Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Simple perl one-liner for transforming text files

by pfaut (Priest)
on Mar 05, 2003 at 20:56 UTC ( [id://240706]=note: print w/replies, xml ) Need Help??


in reply to Simple perl one-liner for transforming text files

Not quite one line, but...

You're 'records' are separated by a new blank line so set the input record separator ($/) to a pair of newlines. Then split each record on newlines and take the part after the colon for the fields you want.

#!/usr/bin/perl -w use strict; $/ = "\n\n"; while (<DATA>) { my @wanted = map { (split(/:\s+/))[1] } (split /\n/)[0..1]; print "@wanted\n"; } __DATA__ name: url1.domain1.com date: 2004/2/1 unwanted info: blah blah blah name: url2.domain5.org date: 2004/3/12 unwanted info: blah blah blah
--- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-19 12:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found