Plankton has asked for the wisdom of the Perl Monks concerning the following question:

Oh wise Monks,

We have been putting off porting this code for way too long. I have Perl 5.6.1 code that I am trying to run under Perl 5.10.1 and I get this message ...

$* is no longer supported
... when executing this bit of code:
for ($ro_string) { s/^\s*//; s/$*\s//; }
Does any monk know what $* should be replaced with in this old code?

Thanks

Replies are listed 'Best First'.
Re: $* is no longer supported
by ikegami (Patriarch) on Nov 03, 2009 at 21:39 UTC
    Your code has never worked. It was likely suppose to be
    for ($ro_string) { s/^\s*//; s/\s*$//; }

      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.

        You should be printing $ro_string. Due to the aliasing done by for, modifying $_ in the loop also modifies $ro_string.

      print; # nothing!

      print $ro_string; # something! :)

      (update: Derrrrrr, meant to respond to JadeNB of course.)

        Derrrrrr, meant to respond to JadeNB of course.
        Well, it's no problem; I responded to ikegami. :-)
Re: $* is no longer supported
by BioLion (Curate) on Nov 03, 2009 at 21:38 UTC