Date: 11 Sep 2001 02:46:22 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: references, slices, voodoo
Message-Id: <slrn9pqukb.2fv.damian@puma.qimr.edu.au>

Shmuel (Seymour J.) Metz chose Mon, 10 Sep 2001 21:35:55 -0400 to say this:
>In <qo67ptkej2sqqfkm9imteu4hohmrca3gfk@4ax.com>, on 09/03/2001
>   at 03:12 PM, Bart Lateur <bart.lateur@skynet.be> said:
>
>>As for the array slice:
>
>>	@ary[2, 4] = @ary[4, 2];
>
>>is functionally equivalent to
>
>>	($ary[2], $ary[4]) = ($ary[4], $ary[2]);
>
>That doesn't explain the @ and $ back-to-back in
>    @$array[$i,$j] = @$array[$j,$i] unless  $i == $j; # ???
>
>$array($i,$j) is a slice of @array, but what is @$array?
>

No, @array[$i,$j] is a slice -- see the perldata manpage. 

@$array is another kind of beast -- equivalent to @{$array}, where the @{}
implies that $array is a reference to an array. Not very helpful unless $array
is in fact a reference to an array. In this case @$array[$i,$j] is equivalent
to:

	@{$array}[$i, $j]

which is equivalent to:

	( $array->[$i], $array->[$j] )

or

	( ${$array}[$i], ${$array}[$j] )

or

	( $$array[$i], $$array[$j] )

See perlref, perlreftut and perldsc.

Cheers,
Damian
-- 
@:=grep!(m!$/|#!..$|),split//,<DATA>;@;=0..$#:;while($:=@;){$;=rand
$:--,@;[$;,$:]=@;[$:,$;]while$:;push@|,shift@;if$;[0]==@|;select$,,
$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/}  __END__
Just another Perl Hacker, #                      damian@qimr.edu.au


