John Ackley wrote:
> Inherited code (from Verisign): @[EMAIL PROTECTED] = split /\t/,$rec;
> which worked but really puzzled me.
What is happening is a hash slice assignment similar to:
@datafield{ 'a', 'b', 'c' } = ( 'd', 'e', 'f' );
Where the first element in @send is used as the key for the first value from
split() and the second element in @send is used as the key for the second
value from split(), etc.
> I assumed that it meant [EMAIL PROTECTED] = split /\t/,$rec;
> which worked also as I verified by testing both versions.
[EMAIL PROTECTED] = split /\t/,$rec;
Is short for:
[EMAIL PROTECTED] = @_ = split /\t/,$rec;
Where @_ is assigned the values from split() and since [EMAIL PROTECTED] is a
scalar both @_ and @send are evaluated in scalar context which means that the
number of elements in @send is used as the key and the number of elements in
@_ is used as the value.
> However [EMAIL PROTECTED] = split /\t/,$rec;
> gives the warning quote: Use of implicit split to @_ is deprecated at . . .
>
> Could some please explain the error messages
> and the syntax of these lines of code?
>
> I understand the right side produces a list from a string.
Yes.
> I do not understand the first @ on the left side.
> Does it produce a list of $datafield{one}, $datafield{two}, . . . ?
> assuming @send = ( one, two, . . .);
Yes. @[EMAIL PROTECTED] is short for ( $datafield{$send[0]},
$datafield{$send[1]}, $datafield{$send[2]}, $datafield{$send[3]}, ...,
$datafield{$send[$#send]} )
> Can someone point out documentation that explains
> this use of @? I learned that @ flags an array.
perldoc -q 'What is the difference between \$array\[1] and @array\[1]'
And see the "Slices" section in perldata and perllol:
perldoc perldata
perldoc perllol
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>