Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: regex issue

by johngg (Canon)
on Nov 11, 2010 at 11:51 UTC ( [id://870834]=note: print w/replies, xml ) Need Help??


in reply to Re^2: regex issue
in thread regex issue

...or more legibly

I think you might be obscuring the wood with a lot of trees there! Perhaps use of the -n switch would be applicable here, either in a script or as a one-liner.

$ cat rubbish Line1 Line2 Line3 Line4 Line5 Line6 Line7 Line8 Line9 Line10 Line11 Line12 $ perl -ne 'print if 2 .. 7;' rubbish Line2 Line3 Line4 Line5 Line6 Line7 $

The array slice method is, as you say, only suitable for small files whereas using -n when combined with last is more efficient when interested only in lines at the beginning of large files. The following examples were acting on a 2,000,000+ line log file.

# time perl -ne 'print if 5 .. 10' maillog Nov 11 04:19:28 ... Nov 11 04:19:28 ... Nov 11 04:19:28 ... Nov 11 04:19:28 ... Nov 11 04:19:28 ... real 0m1.206s user 0m0.773s sys 0m0.432s # time perl -ne 'print if 5 .. 10; last if $. > 10' maillog Nov 11 04:19:28 ... Nov 11 04:19:28 ... Nov 11 04:19:28 ... Nov 11 04:19:28 ... Nov 11 04:19:28 ... real 0m0.013s user 0m0.006s sys 0m0.008s #

I hope this is of interest.

Cheers,

JohnGG

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-19 08:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found