Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: [GOLF] Perl csv diff

by truedfx (Monk)
on Nov 03, 2005 at 13:25 UTC ( [id://505320]=note: print w/replies, xml ) Need Help??


in reply to [GOLF] Perl csv diff

Here's a quick one in 84 (updated from 86 because I had a pointless !! before eof) (unless I miscounted) -- relying on $^F defaulting to 2:
#--------1---------2---------3---------4---------5---------6---------7 +---------8-------- #234567890123456789012345678901234567890123456789012345678901234567890 +123456789012345678 perl -anF, -le'$h{$F[0]}|=$^F;$^F-=eof}{"@_"=~/[12]$/&&print"$&:$`"whi +le(@_=each%h)' t1.csv t2.csv 1:8 1:6 2:1 2:3 2:5
As always with hashes, I can't promise anything about the order of the output, but that seems to be okay. :)

Update:
79, by using 2-@ARGV instead of $^F
78, by using the implicit print from -p
77, by splitting manually instead of with -a
#--------1---------2---------3---------4---------5---------6---------7 +------- #234567890123456789012345678901234567890123456789012345678901234567890 +1234567 perl -pe'@h{/([^,]*)/}|=2-@ARGV}while(@_=each%h){$_="@_"=~/[12]$/&&"$& +:$`$/"'

Replies are listed 'Best First'.
Re^2: [GOLF] Perl csv diff
by BrowserUk (Patriarch) on Nov 03, 2005 at 13:50 UTC

    That's neat! I had to run away to perlvar to work out what $^F was. Uniquely for a while now, I had absolutely no idea.

    That is a genuinely perverse piece of lateral thinking. ++.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-03-29 15:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found