CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
$line =~ s (Replacing)

 



Thierry
Deleted

Mar 13, 2000, 1:13 PM

Post #1 of 3 (1138 views)
$line =~ s (Replacing) Can't Post

Hello,

My problem is the following one :

Having urls as follows http://www.amazon.de/exec/obidos/ASIN/$givenvariable/

I would need to replace them with http://www.amazon.de/exec/obidos/ASIN/$givenvariable/waatleeft0a

How can I achive this ?
I tried several $line =~ s combinations but i can't seem to get it right ?


darian
Deleted

Mar 14, 2000, 2:12 AM

Post #2 of 3 (1138 views)
Re: $line =~ s (Replacing) [In reply to] Can't Post

If your just looking to add a piece on to the end of the url try this:

$line = "http://www.amazon.de/exec/obidos/ASIN/$givenvariable/";
$line.= "waatleeft0a";

Using the .= will add what is to the right of the = sign to the variable on the left.


japhy
Enthusiast

Mar 15, 2000, 6:43 AM

Post #3 of 3 (1138 views)
Re: $line =~ s (Replacing) [In reply to] Can't Post

Yes, don't use a regex here. If you're curious, though, how to anchor "end of string" in a regular expression you can use:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


$a = "this";
$a =~ s/$/ that/; # "this that"
$a = "this\n";
$a =~ s/$/ that/; # "this that\n"
$a = "this\n";
$a =~ s/\Z/ that/; # "this that\n"
$a = "this\n";
$a =~ s/\z/ that/; # "this\n that"
</pre><HR></BLOCKQUOTE>

$ and \Z and \z are described in 'perlre'.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives