I'm using the $' operator to append to a string that I find from using a search.
Thats a variable actually.
For example given the string copyright 2003-2004, I want to append an additional year onto the end.
Use the concatenation (thats how comp sci people say "append to the end of a string" :-) operator the dot . so you might say
use strict;
use warnings;
my $string="copyright 2003-2004";
my $year=2005;
$string=$string.",".$year;
But we normally wouldnt say that last line just like that, we would use a shortcut
$string.=", $year";
which does the same thing but is less chars to type ( $x .= $y is the same as $x= $x . $y) and we dont need to actually do concatenation here explicitly but out of lazyness we write it to use interpolation and then perl sort it out for us.
I used s/copyright*/$& $' ,2005/g
No-no-no-no. Thats a bit like using a flame thrower to light a candle. First off the special match variables $` $& and $' are bad to use in general (you can usually rewrite your regex to go without them), but to use them just to do concatenation wouldn't be done except in the wildest obfu/golf mutant code :-) Furthermore that regex says "match 'copyrigh' followed by 0 or more t's and then replace it with itself and everything to its right followed by ',2005'". So effectively we are inserting a copy of everything to after the word 'copyright' with itself follwed by ", 2005". '*' doesnt match any characters like it does on a command line. '*' itself is a qualifier that means "match the thing infront of me 0 or more times." We use the special character . (funny how that keeps coming up eh?) to represent any character (ahem, normally it means "every character but a newline"). So '.*' matches "zero or more of any characters but a newline". Which means that you could say s/(copyright.*)/$1, 2005/; and it would do what you want. But its unlikely anybody would do that. They would be much more likely to do s/(copyright 2003-2004)/copyright 2003-2005/; especially if the relevent string was embedded in a larger one.
I really would recommend some doc time however. Its clear that you need a refresher in the basics.
Good luck.
---
demerphq
<Elian> And I do take a kind of perverse pleasure in having an OO assembly language...
|