Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: how to print first 5 lines of a file

by CharlesClarkson (Curate)
on Nov 01, 2001 at 03:42 UTC ( #122455=note: print w/ replies, xml ) Need Help??

in reply to how to print first 5 lines of a file

for (1 .. 5) { print scalar <>; last if eof; }

Or, if you're certain there are at least five lines:

print scalar <> for 1 .. 5;

Calling the diamond operator <> in scalar context will return 1 line, assuming $/ is set to "\n". (Note - 'while' calls in scalar context while 'foreach' and 'for' call in list context.)

Charles K. Clarkson

Comment on Re: how to print first 5 lines of a file
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (16)
As of 2015-08-03 13:37 GMT
Find Nodes?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...

    Results (37 votes), past polls