Solved

adding stuff in string.....

Posted on 2000-04-15
7
192 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Remove Malware code from PHP file 6 54
PERL export multiple query results to a JSON file 1 153
Perl Sort Question 4 118
crawling gofundme 4 103
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

18 Experts available now in Live!

Get 1:1 Help Now