Hello monks, thank you for your time. I am wondering about the proper syntax for inputing files at the command line and sending them to separate hashes. perl -walne '$h{$F[0]}.="$F[1]";END{print "$_:\t" . $h{$_} for sort keys%h}' file1.txt.

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.txt

Any 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


In reply to How to supply two input files at command line by ZWcarp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.