in reply to Curly braces variable
This is a "symbolic reference", but happens to use a syntax that still passes strict.
Do you understand what happens here?
no strict qw(refs); my $variable = 'host_mail'; my ${ $variable } = '80.80.80.80';
How about this:
no strict qw(refs subs); my $variable = host_mail; my ${ $variable } = '80.80.80.80';
So it's not much of a stretch to get to this:
my ${ host_mail } = '80.80.80.80';
It's a little unusual to do. Usually strict disallows symbolic references, but in this case it allows it, because it's rarely harmful to do it. It's arguably poor style though, as it can result in confusion. (It confused you.)
The one place you do see it quite often though is in string interpolation:
my $scandal_topic = 'email'; say "We will call this scandal '${scandal_topic}gate'!"; # says "We will call this scandal 'emailgate'!";
That's because without the curlies we get:
my $scandal_topic = 'email'; say "We will call this scandal '$scandal_topicgate'!"; # dies "Global symbol "$scandal_topicgate" requires explicit package n +ame
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Curly braces variable
by chromatic (Archbishop) on Apr 30, 2012 at 18:27 UTC | |
by tobyink (Canon) on Apr 30, 2012 at 21:16 UTC | |
by chromatic (Archbishop) on Apr 30, 2012 at 22:06 UTC |