On Aug 19, 2008, at 1:43 PM, Paul Lalli wrote:

On Aug 19, 11:16 am, [EMAIL PROTECTED] (Perry Smith) wrote:
My friend is trying to do this:

#!/bin/perl

$a = 1;
$b = 2;
$c = 3;

@l = ( \$a, \$b, \$c );

# This is the line we need help with
# Is there a way to tell Perl that @l[0] is a reference
# and we want to assign what it refers to the number 4.
# i.e. ${$l[0]} = 4;
# but for the whole list in @l
( \( @l ) ) = ( 4, 5, 6 );

print "$a should be 4\n";

It sounds to me like you're looking for the exact opposite of the \
( ... ) behavior.  That is, you want some operation that will take a
list of references and return the corresponding list of referents.

To my knowledge, no such operator exists.  Sorry.

You can dereference a single reference to an array.  But you can't
dereference a list of references to scalars.

Best you could do would probably be something involving a postfix for,
like:
my @new_vals = (4, 5, 6);
my $i = 0;
${$_} = $new_vals[$i++] for @l;


Yes, my first guess was:

( [EMAIL PROTECTED] ) = ( 4, 5, 6)

Some languages have a "splat" unary operator that explodes the list into its elements but I guess Perl does not.

Thank you for your time and effort,
Perry
Ease Software, Inc. ( http://www.easesoftware.com )

Low cost SATA Disk Systems for IBMs p5, pSeries, and RS/6000 AIX systems


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


Reply via email to