That perldoc has said, a list is a value while an array is a variable.
so [EMAIL PROTECTED] get what you wanted but \(1,2,3) returns each elements' 
reference.

also @array = (1,2,3) will convert a list to an array automatically,
and mysub(@array) will set an array as a list automatically.

and you can shift/pop/unshift/push with an array not a list,if you do
those with a list,you'll get errors:

$ perl -Mstrict -Mwarnings -e 'pop (1,2,3)'
Type of arg 1 to pop must be array (not list) at -e line 1, at end of line
Execution of -e aborted due to compilation errors.

$ perl -Mstrict -Mwarnings -e 'shift (1,2,3)'
Type of arg 1 to shift must be array (not list) at -e line 1, at end of line
Execution of -e aborted due to compilation errors.

$ perl -Mstrict -Mwarnings -e 'unshift (1,2,3),1'
Type of arg 1 to unshift must be array (not constant item) at -e line
1, near "3)"
Execution of -e aborted due to compilation errors.

$ perl -Mstrict -Mwarnings -e 'push (1,2,3),1'
Type of arg 1 to push must be array (not constant item) at -e line 1, near "3)"
Execution of -e aborted due to compilation errors.


On 10/29/07, yitzle <[EMAIL PROTECTED]> wrote:
> Oops. Duly noted.
> Functions/Subs return lists, not arrays.
>
> But then again, grep() takes a list, and not an array :)
>
> Arrays can be set from lists and arrays get converted to lists all the time.
> Is there any practical difference? (Other than the fact that an array
> has a reference which can be passed as a scalar?)
>
>
> Sample code to go along with my previous answer:
>
> my $str = 'abc,123,,bob';
> my @arr = split ',', $str;
> print scalar @arr, " items\n"; # 4
> @arr = grep !/^$/, @arr;
> print scalar @arr, " items\n"; # 3
> @arr = grep !/^$/, split ',', $str;
> print scalar @arr, " items\n"; # 3
>

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


Reply via email to