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

No he does not. Looks like someone read just the node subject and not the text :-)

If he was trying to declare (well actually USE) variables with ad hoc names, you'd be right, but he just needs to access the regexp matches. I think in this case the easiest solution is to turn the strict refs off in the block. Or rewrite the code so that he gets the matches as a list. Which is not always possible without huge changes to the code.

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

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

Replies are listed 'Best First'.
Re: Re: Re: how to dynamically declare a varialble?
by Anonymous Monk on May 23, 2004 at 06:58 UTC
    use strict; my %hash = ( 1 => \$1, 2 => \$2 ); my $hash = 1; "aa bb cc" =~ /(aa)/ and print ${ $hash{$hash} },$/; __END__ aa
Re: Re: Re: how to dynamically declare a varialble?
by dragonchild (Archbishop) on May 24, 2004 at 13:05 UTC
    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

      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