Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Keep only X number of entries of a file using a delimeter

by hdb (Monsignor)
on Oct 13, 2015 at 13:39 UTC ( [id://1144700]=note: print w/replies, xml ) Need Help??


in reply to Keep only X number of entries of a file using a delimeter

Use a counter! Set $/ to "#" to read the desired chunks.

use strict; use warnings; my $keep = 3; local $/="#"; while(<DATA>){ last unless $keep--; print; } __DATA__ 1 # 2 # 3 # 4 # 5

Replies are listed 'Best First'.
Re^2: Keep only X number of entries of a file using a delimeter
by SimonPratt (Friar) on Oct 15, 2015 at 15:48 UTC

    You could also test $., like so: last if $. > 3;

Re^2: Keep only X number of entries of a file using a delimeter
by Anonymous Monk on Oct 13, 2015 at 13:52 UTC
    Thanks a bunch!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-24 08:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found