in reply to perl statement

Yisha sharma:

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
    Generally if you have a question like that, you look up the appropriate operator, statement or whatever in the docs. Of course, I agree in general, but in this specific case, I can understand that the OP, if she or he does not know much of Perl, would not even know where to look. Also, these backslashes don't make it easy for a beginner.

      But roboticus does go on to constructively address the specific case: " In this case, you could ..." OTOH, davido's response below is much more detailed and, IMHO, preferable. In any event, ++ to both from me.

      And yes, those backslashes are rather eye- and brain-bezoggling; severe LTS.