On Jul 23, 4:35 am, [EMAIL PROTECTED] (Jeevs) wrote:

> I just wanted to know what does the following line do....
> @{$args{owner}} = qw(hero wierd);
>
> lets assume $args{owner} = 'sachin';
> Then it would mean @{sachin} = qw(hero wierd);
> what would {sachin} stand for does it mean an hash refernce or
> something else. I am lost.

This is known as a symbolic reference, and is a very very bad idea,
for exactly these reasons.  `use strict;` prevents you from doing
messy stuff like this.  You should always use strict.  If you do not:

perl -MData::Dumper -le'
$args{owner} = "sachin";
@{$args{owner}} = qw(hero wierd);
print Dumper(\%args);
print Dumper([EMAIL PROTECTED]);
'

$VAR1 = {
          'owner' => 'sachin'
        };

$VAR1 = [
          'hero',
          'wierd'
        ];

> Can someone explain or atleast point me to some documentation, I tried
> looking into the perldoc but i am sure i missed something.

perldoc perlref
perldoc perlreftut

Basically, when you use a string as though it was a reference, as you
did above, you create a "symbolic reference".  You are modifying the
variable named by that string.  So if $args{owner} contains the string
'sachin', then @{$args{$owner}} is the same thing as the array
variable @sachin.

Some people try to take advantage of this apparent feature by using it
to dynamically choose which variables they want to access.  To learn
the correct way of going about that, please read:
perldoc -q "variable name"

Paul Lalli



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to