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



Thierry
Deleted

Mar 13, 2000, 1:13 PM


Views: 2958
$line =~ s (Replacing)

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


Views: 2958
Re: $line =~ s (Replacing)

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


Views: 2958
Re: $line =~ s (Replacing)

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'.