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:
Reading data in list context

 



zaphod
New User

Apr 18, 2002, 8:42 PM

Post #1 of 4 (515 views)
Reading data in list context Can't Post

Is there a way to "throw away" the third value in this assignment where the question marks are without assigning it first to a scalar? There are four values read in each time.

$_=<>;

($a,$b,??,$c) = split;



Thanks in Advance.


mhx
Enthusiast / Moderator

Apr 18, 2002, 9:57 PM

Post #2 of 4 (511 views)
Re: [zaphod] Reading data in list context [In reply to] Can't Post

Yes, just use undef:


Code
($a, $b, undef, $c) = split;


-- mhx

At last with an effort he spoke, and wondered to hear his own words, as if some other will was using his small voice. "I will take the Ring," he said, "though I do not know the way."

-- Frodo



zaphod
New User

Apr 18, 2002, 10:21 PM

Post #3 of 4 (508 views)
Re: [mhx] Reading data in list context [In reply to] Can't Post

Simple truths are a relief from grand speculations.

-Vauvenargues


rGeoffrey
User / Moderator

Apr 26, 2002, 9:35 PM

Post #4 of 4 (491 views)
Re: [zaphod] Reading data in list context [In reply to] Can't Post

Another option is to use a splice...


Code
($a,$b,$c) = (split)[0,1,3];


With a splice you only get exactly the bits of an array you want.

 
 


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

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