CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
list question

 



stu7
Deleted

Jan 4, 2001, 11:57 AM

Post #1 of 2 (215 views)
list question Can't Post

 ok... there is this guy on our channel... and he is always doing trout... but he said there was a way to do a list
or something... like this $a = () = something the " ( ) " is supposed to be a list... but how can it do
anything with nothing inside the parenthesis ? Thats is my question !
anyway, isnt " $ " a list ? I am confused about this.



japhy
Enthusiast

Jan 5, 2001, 7:36 AM

Post #2 of 2 (200 views)
Re: list question [In reply to] Can't Post

A list assignment in scalar context returns the number of values attempted to be assigned.


Code
$num = ($a,$b,$c) = (10);  # $num = 1 
$num = ($a,$b,$c) = (10,11); # $num = 2
$num = ($a,$b,$c) = (10,11,12); # $num = 3
$num = ($a,$b,$c) = (10,11,12,13); # $num = 4

Therefore, remove the variables from the assignment, and you're left with:


Code
$num = () = some_function();

This calls some_function() in list context, and then determines the number of values the function returned.

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives