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

Re: Test for the last element in a foreach

by CountZero (Bishop)
on Aug 02, 2007 at 20:30 UTC ( [id://630391]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my @array = (1 .. 10);
    my $counter;
    foreach my $element (@array) {
        print "Last element follows now!\n"    if ++$counter == scalar(@ar
    +ray);
        print "$element\n";
    }
    
  2. or download this
    1
    2
    3
    ...
    9
    Last element follows now!
    10
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2025-03-27 01:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (69 votes). Check out past polls.

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.