Hi Paul,
I think you're looking for:
sub suby {
$temp=$_[0];
print "$_[0]\n";
print "$$temp[0]\n";
}
I'm not sure why. It seems like it should be print "$$_[0]\n";, but I believe the
results I got from the interpreter. Output:
ARRAY(0x1ab28e0)
paul
ARRAY(0x1ab28e0)
paul
Joseph
Paul Kr
On Mon, Jan 06, 2003 at 04:29:41PM -0500, Paul Kraus wrote:
> I don't understand why the output of the two print statements inside the
> subroutine is different. The one only prints the new line.
Hmm, I get "Use of uninitialized value in concatenation (.) or string at
qw" for both.
> #!/usr/bin/
-Original Message-
From: Paul Kraus [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 06, 2003 3:30 PM
To: Perl
Subject: passing array ref to subroutine
Because the second one is printing the '0' item fo an array called 'temp' you need to
do
$$temp[0] the same as yo
is the same as:
${$temp}[0]
P.S. The same works for hashes. $temp->{key} accesses an element of the
hash referenced by $temp
-Original Message-
From: Paul Kraus [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 06, 2003 1:30 PM
To: Perl
Subject: passing array ref to subroutine
I don
I don't understand why the output of the two print statements inside the
subroutine is different. The one only prints the new line.
#!/usr/bin/perl -w
@array=qw/paul david kraus/;
$arrayref=\@array;
print "$arrayref\n";
print "$$arrayref[0]\n";
&suby($arrayref);
sub suby {
$temp=$_[0];
p