ZWcarp has asked for the wisdom of the Perl Monks concerning the following question:
Now lets say I want to read in a second file as a second hash in the same execution... what is the syntax to tell perl that file1 and file2 should go to separate hashes?
perl -walne '$h{$F[0]}.="$F[1]" Now here is where I want to read in file2.txt into %h2 ;END{$_=......... ' file1.txt file2.txtAny ideas on how to do this? Thanks a ton!!
UPDATE
how about something simpler... file one is a list, and I want to print out every line in file 2 that matches the current element in the list. In a script you would do this by making a nested foreach loop or you could do it by making a hash and then checking the hash.. How would one do this at command line (specifically dealing with 2 files ) ? Something like this where the file 2 lines only are piped in to the matching part:
perl -F: -walne'$h{$F[0]}.="$F[1] "; END{#Line from file2 here#=~/$h{$_}/&&print"$h{$_}"for keys%h}' file1.txt file2.txt
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to supply to input files at command line
by jwkrahn (Abbot) on Apr 17, 2012 at 19:54 UTC | |
|
Re: How to supply to input files at command line
by brx (Pilgrim) on Apr 17, 2012 at 17:53 UTC |