develooper Front page | perl.beginners | Postings from February 2002

Dereferencing a referenced hash.

Thread Next
From:
Tor Hildrum
Date:
February 28, 2002 04:46
Subject:
Dereferencing a referenced hash.
Message ID:
B8A3E512.5752%torhildr@mac.com
Is this a bug or a feature?
Or is it just me? :)

!/usr/bin/perl -w
use strict;
use warnings;

my $variable = "variable";
my @array = qw(this is an array);
my %hash = qw(1 this 2 is 3 a 4 hash); ## correct syntax

my $rvariable = \$variable;
my $rhash = \%hash;  ## correct syntax
my $rarray = \@array;


print "\$variable from reference: $$rvariable\n";
print "\@array from reference: @$rarray[0] @$rarray[1] @$rarray[2]
@$rarray[3]\n";
print "\%hash from reference: %$rhash{1} %$rhash{2} %$rhash{3}
%$rhash{4}\n"; ## correct syntax

[localhost:~/Perl/Advanced Perl] tor% ./1.pl
Global symbol "%rhash" requires explicit package name at ./1.pl line 16.
Global symbol "%rhash" requires explicit package name at ./1.pl line 16.
Global symbol "%rhash" requires explicit package name at ./1.pl line 16.
Global symbol "%rhash" requires explicit package name at ./1.pl line 16.
Execution of ./1.pl aborted due to compilation errors.

I simply can't see that anything is wrong with my syntax.

If I remove -w, use warnings; and use strict;

[localhost:~/Perl/Advanced Perl] tor% ./1.pl
$variable from reference: variable
@array from reference: this is an array
%hash from reference: % % % %

Anyone know why this is happening?

-- 
T.


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About