[Wellington-pm] Side effects

Grant McLean grant at mclean.net.nz
Fri Mar 31 02:26:54 PST 2006


On Fri, 2006-03-31 at 19:45 +1200, Cliff Pratt wrote:
> Hi Perlmongers!
> 
> I don't know if this qualifies as a tip or a question!
> 
> my $v = "123456789ABC" ;
> my $v1 = "7" ;
> 
> print "|" . eval { $v =~ s/$v1// ; return $v } . "|\n" ;
> 
> Now, orginally, I had the following:
> 
> print "|" . $v =~ s/$v1// . "|\n" ;
> 
> which prints "1", since "$v =~ s/$v1//" returns '1'.
> 
> I wanted to print the side-effect ($v with "7" removed).
> 
> After trying various things I got the line of code I printed at the
> beginning. Is this the best way of doing it?

Here's a way that might be clearer:

  $v =~ s/$v1//;
  print "|$v|\n";

:-)
Grant



More information about the Wellington-pm mailing list