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.)
In reply to Re: how to print first 5 lines of a file
by CharlesClarkson
in thread how to print first 5 lines of a file
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |