Hi

pls use,

use strict; use warnings; for better error.

$value3 are not initialized. Anyone know how to fix this?

my($key,$value1,$value2,$value3) = $line =~ /(\w+),(\d+.\d+),(.\d+\s+\ +d+.\d+.)/g;

In regular expression you have only three group and assigning into four variables, so $value3 will be undef.

Update:

Here its the fixed code

use strict; use warnings; my %file1Hash; my $value4; open my $file1, "<","file1.csv" or die $!; open my $file2, "<","file2.csv"or die $!; open my $outfile_1, ">", "combined.rpt.csv" or die $!; while( my $line = <$file1>){ chomp $line; my($key,$value1) = (split /,/, $line); $file1Hash{$key} = $value1; } while(my $line1 = <$file2>){ chomp $line1; my($key1) = (split /,/, $line1); if (exists $file1Hash{$key1}) { print $line1.",".$file1Hash{$key1}."\n"; } else { # print $line1."\n"; } } close $file1; close $file2; close $outfile_1; exit 0;

All is well. I learn by answering your questions...

In reply to Re: Combining Files using Hash by vinoth.ree
in thread Combining Files using Hash by chaney123

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.