Object references in dynamic Perl regular expressions

So, I had a variable in a LO Dictionary I wanted to use in a regular expression:

$d->{name} = 'hello';

if ($x =~ m/$d->name/) {
  [...]
}

But that wasn't working. Only way I could get it to work was a local:

my $r = $d->{name};
if ($x =~ m/$r/) {
  [...]
}

Then everything worked fine. Wonder if its a weird behavior in Dictionary or if I had a regular object:

if ($x =~ m/$o->{name}/) {
  [...]
}

would that have worked?


Follow on Twitter


LinkedIn
Facebook
Notchup, Member 74311




Copyright (C) 2008, Mike McCreavy
[ x ] Console
Timestamp Message
hey
[ x ] Socket Console
Timestamp Message
hey