Solved

adding stuff in string.....

Posted on 2000-04-15
7
202 Views
Last Modified: 2010-08-05
hi all

i have this string :
<li><a href="/anydir/anylink.html">any text for the link</a>

and i want to get this:
<li><a href="http://www.myserver.com/anydir/anylink.html">any text for the link</a>

do someone have any idea..???

tanks
popy
0
Comment
Question by:popy
7 Comments
 
LVL 3

Expert Comment

by:monas
ID: 2719017
$x = '<li><a href="/anydir/anylink.html">any text for the link</a>';

$x =~ s#(<a href=")(.*)#$1.'http://www.myserver.com/'.$2/ei;

print $x;
0
 
LVL 3

Expert Comment

by:monas
ID: 2719031
oops

$x = '<li><a href="/anydir/anylink.html">any text for the link</a>';

$x =~ s#(<a href=")(.*)#$1.'http://www.myserver.com/'.$2#ei;

print $x;
0
 

Author Comment

by:popy
ID: 2719051
Adjusted points from 100 to 150
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:popy
ID: 2719052
ok, thanks, but now subquestion, this line appear somewhere in the text, i reading text file, then i need to verifing if the line having this tag...
any sugestion...?

popy
0
 
LVL 84

Expert Comment

by:ozo
ID: 2719061
There's really no need for the (.*) .$2 and /e
0
 

Accepted Solution

by:
nmoldav earned 150 total points
ID: 2719067
If you're reading a file, then it should work as follows:

while (<FILE>) {
      if (m!<A\s+HREF="([^"]+"!i) {
            my $link = $1;
            s!HREF="$link"!HREF="http://www.myserver.com/$link"!i;
      }
}

# The if checks whether the pattern is present in the current line and the replace operator adds the server name to the link.
0
 
LVL 3

Expert Comment

by:monas
ID: 2719068
while($x = <FILE>){
  $num = ($x =~ s#(<a href=")#$1.'http://www.myserver.com/'#gei);
  # number of occurences is in $num;
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
perl to mysql 5 130
Bash one liner, start and end time calculation 13 103
get the last nth lines from a an array if nth element is xxx 2 68
quoting a comma separated list 20 82
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now