You forgot a semicolon on the line
my $second
oh, and on the line
my $line = $_
too.

That would solve your immediate syntax problem. But it doesn't solve the semantic problem: that it doesn't do what you want. For example, there is no connection between your value for $second and your hash key. That connection is in the value for $first. It'd work somewhat better if you incorporated your final loop body (but without the loop) into the one reading the second file. And you're making the classic newbie error of not backwhacking the "|" for split — and it's easier to use a regex for split, otherwise you'd even have to double the backslash.

while(<>) { my $line = $_; my($first, $second) = split(/\|/, $line); # or: "\\|" my @list = ($hash{$first}, $second); $joined = "@list"; # joins with space by default (see $" ) $hash{$first} = $joined; }

In reply to Re^3: combining 2 files with a comon field by bart
in thread combining 2 files with a comon field by jjohhn

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.