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@/
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.