in reply to Re: $* is no longer supported
in thread $* is no longer supported

Have I got my rules for scoping wrong, or is that code useless?

my $ro_string = " I'm surrounded by spaces! "; for ($ro_string) { # alias $_ to $ro_string for this scope s/^\s*//; # strip leading spaces from $_ s/\s*$//; # strip trailing spaces from $_ } # lose $_ when the scope ends print; # nothing!
At least, that's what I'm getting on Perl 5.8.9.

UPDATE: True but irrelevant, as pointed out by Your Mother and ikegami.

Replies are listed 'Best First'.
Re^3: $* is no longer supported
by ikegami (Patriarch) on Nov 04, 2009 at 06:12 UTC
    You should be printing $ro_string. Due to the aliasing done by for, modifying $_ in the loop also modifies $ro_string.
      Oops. I was seduced by the name $ro_string into thinking that it was read-only. Thanks!