Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Reading a Line into an Array

by iakobski (Pilgrim)
on May 31, 2001 at 11:56 UTC ( [id://84489]=note: print w/replies, xml ) Need Help??


in reply to Reading a Line into an Array

By the way, in Perl you don't often have to find out how many elements there are in an array. If you want the last element use: my $last = $array[ -1 ];

-- iakobski

Replies are listed 'Best First'.
Re: Re: Reading a Line into an Array
by zeidrik (Scribe) on May 31, 2001 at 12:19 UTC
    Iakobski is right. This is smarter :)
    #!/usr/bin/perl -w use strict; open(R,"textfile"); my @F=<R>; close(R); pop @F if $F[-1] eq "\n"; print @F;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-19 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found