Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Perl and Pipes. Share your story.

by fizbin (Chaplain)
on Apr 16, 2006 at 00:12 UTC ( #543602=note: print w/replies, xml ) Need Help??


in reply to Perl and Pipes. Share your story.

I'm constantly using perl one-liners in pipes when investigating things; as such, the usage doesn't usually get written down and I can only come up with a few examples in my bash_history file:

svn log -vv -r 21224 | perl -nle 'm|Eclipse/(.*)| and print$1'> /tmp/f +ilesChanged.txt
A simple checklist of stuff to look at generated by a certain subversion commit.

Then there's this longer example that requires some setup. See, we have in our source code a bunch of DTD files that are replicated into several different directories. Yeah, we should keep them in one central location, and we're moing there, but right now we don't. Anyway, occasionally a DTD file changes, and the changes are copied to its various versions, but every once in a while we miss something. That's where this usage of perl in the midst of pipes comes in.

find * -name '*.dtd' | xargs md5sum > /tmp/dtdmd5s.txt perl -ple 's{([^*]*) [*](.*/)([^/]*)$}{$2$3 $3 $1}' /tmp/dtdmd5s.txt | + \ sort -k2 | uniq -c -f 1 | \ perl -nle '@a=split;if($a eq $a[2]){print $b;print}$b=$_;$a=$a[2]'
The output that produces is nothing when all the copies of a given dtd file are in sync. When they aren't, I get something like this: (names tweaked to protect... um ... someone)
1 clients/megacorp/cmeta/smeta.dtd smeta.dtd 81e2470da0cc593e114 +6556d0fe0ebed 41 base/classes/com/mycomp/dtd/smeta.dtd smeta.dtd e287f8786ecf79 +06f3019d3cc9accff7
This tells me that there are 42 copies of this dtd in our source, and 41 of them agree with the dtd stored under "base", but the one for megacorp is different. I then look manually at the two versions. I keep the md5sums in a temp file because sometimes it isn't just 1 spot that has the rogue dtd, but 2 or 3, and I can just grep through the temp. file to find the locations of the rogue dtd.
--
@/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2022-08-17 17:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?