Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Check for next array element.

by BaldPenguin (Friar)
on Nov 18, 2005 at 18:47 UTC ( [id://509897]=note: print w/replies, xml ) Need Help??


in reply to Re: Check for next array element.
in thread Check for next array element.

Couldn't that also be written as
$data->{'IS_LAST'} = 0; for ( my $i = 0; $i < @list; $i++ ) { # DO STUFF $data->{'IS_LAST'} = 1 if $i == $#list; }

Don
WHITEPAGES.COM | INC
Everything I've learned in life can be summed up in a small perl script!

Replies are listed 'Best First'.
Re^3: Check for next array element.
by Aristotle (Chancellor) on Nov 18, 2005 at 19:18 UTC

    Too easy to make off-by-one mistakes that way. Use for my $i ( 0 .. $#list ) { ... } instead, unless you have speficic reason to use for(;;). (I have never had such an occasion, but maybe you will.)

    Makeshifts last the longest.

Re^3: Check for next array element.
by friedo (Prior) on Nov 18, 2005 at 18:50 UTC
    Sure, but then in the "DO STUFF" section you have to work with $list[$i] instead of $_. What are we, animals?! :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://509897]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-18 06:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found