Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: Counting in loop help!

by Rudolf (Monk)
on Jul 26, 2012 at 20:26 UTC ( #983930=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Counting in loop help!
in thread Counting in loop help!

is it possible you can remove the invalid names before going through the list? for example create a new array with the valid names.. find the number of them and then test the id against the array element in your subroutine:

my @raw_names = ...; my @valid_names = (); my $total_valid_names = -1; foreach my $raw_name(@raw_names){ next unless $raw_name; push(@valid_names,$raw_name); $total_names++; } for(my $i=0;$i<length(@valid_names);$i++){ check_name($valid_names[$i],$i); } sub check_names{ my($name,$id) = @_; if($id == $total_valid_names){ say "$name is the last name! ($idth)"; } }


Comment on Re^3: Counting in loop help!
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (12)
As of 2014-12-21 08:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (104 votes), past polls