in reply to perl statement
Generally if you have a question like that, you look up the appropriate operator, statement or whatever in the docs. In this case, you could read perldoc perlop to find the documentation for the s/// operator (it's in the "quote-like operator" section), or you could just experiment with it a little and find out, like:
$ cat tu.pl while (<DATA>) { #$tmp = s/\*/\$lvl=/g; # LTS! $tmp = s{\*}{\$lvl=}g; # ?better? print "$_ : $tmp\n"; } __DATA__ now is *the* time! just how many asterisks? ***** $ perl tu.pl now is $lvl=the$lvl= time! : 2 just how many asterisks? $lvl=$lvl=$lvl=$lvl=$lvl= : 5 :
Update: I agree that I coulda done better with this node, davido's is much better. I sometimes forget how daunting the perl docs can be when starting. (Even now, I sometimes have a little time figuring out which perldoc to read for some topics.) I also changed the code to use an alternate form of the s/// operator to avoid Leaning Toothpick Syndrome (LTS).
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: perl statement
by Laurent_R (Canon) on Nov 20, 2014 at 07:14 UTC | |
by AnomalousMonk (Archbishop) on Nov 20, 2014 at 14:11 UTC |