in reply to Re: Re: how to dynamically declare a varialble?
in thread how to dynamically declare a varialble?

Ahhh. I missed the phrase "matched memory variable". I will reply again.

Your solution is poor - much better is to assign the matches to an array.

------
We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

I shouldn't have to say this, but any code, unless otherwise stated, is untested

  • Comment on Re: Re: Re: how to dynamically declare a varialble?

Replies are listed 'Best First'.
Re: Re: Re: Re: how to dynamically declare a varialble?
by Jenda (Abbot) on May 24, 2004 at 16:21 UTC

    Well it depends on what do you do. If you have code like this:

    if (/regexp/) { no strict 'refs'; my $i = 1; while (defined ${$i}) { ... } }
    then it's definitely better (and fairly easy) to change the code and assign the matches into an array. If you have something like:
    $text =~ s{regexp}{ no strict 'refs'; my $i = 1; while (defined ${$i}) { ... } ... }ge;
    it ain't that trivial.

    Jenda
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

    Edit by castaway: Closed small tag in signature

      Show me an example of the second and I'll show you how to rewrite it. The second sounds like someone trying to be too clever.

      ------
      We are the carpenters and bricklayers of the Information Age.

      Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

      I shouldn't have to say this, but any code, unless otherwise stated, is untested