Re: Regexp on variable

2001-12-13 Thread Michael R. Wolf

Rus Foster <[EMAIL PROTECTED]> writes:

> my $foo="bar";
> $_ = $foo;
> $foo =~ s/bar/goo/g;
> 
> There has to be a better way hasn't there?

Define "better".  You've actually got two metaphores running side by
side.

Either use a named scalar variable:

  my $foo="bar";
  $foo =~ s/bar/goo/g;

Or use the (scratchpad) default:

  $_ = $foo;
  s/bar/goo/g;


You *could* on-line it, but I don't think that's "better".  This
assigns a string to the scalar $foo (or $_), then immediately performs
a substitute on it.

  ($foo = "bar") =~ s/bar/goo/g;

  ($_ = "bar") =~ s/bar/goo/g;


Better?  I think not (therefore I am not?)
Different, but not better.

-- 
Michael R. Wolf
All mammals learn by playing!
   [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Regexp on variable

2001-12-13 Thread Rus Foster

Hi All,
I've google for this but for the life of me I can't find it. Basic
premise is that I have a variable, want to run a regexp over it and then
put the results back into itself. So far I have

my $foo="bar";
$_ = $foo;
$foo =~ s/bar/goo/g;

There has to be a better way hasn't there?


Rus



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]