in reply to Re: Perl Code Runs Extremely Slow
in thread Perl Code Runs Extremely Slow

A few minor problems with your code. Here's my idea of a better version (update: starting from the second verse).

open IHF, "<", "File1" or die "Could not open File1: $!"; while( <IHF> ) { chomp; my ($k, $v) = split; $fets{$k} = $v if defined ($k) and defined ($v); } close IHF; open JHF, "<", "File2" or die "Could not open File2: $!"; while(<JHF>) { chomp; my ($key, $val) = split; print "$key $fets{$key} $val\n" if exists $fets{$key}; } close JHF;

• another intruder with the mooring in the heart of the Perl

Replies are listed 'Best First'.
Re^3: Perl Code Runs Extremely Slow
by Mandrake (Chaplain) on Jun 14, 2006 at 08:15 UTC
    I see you chomp the lines. I missed it probably because the orginal post does not seem to do it.
    Many thanks for the correction.
      Yes but you don't have to chomp the lines because split removes all whitespace, including any terminating newlines.

        This particular usage of split removes all whitespace, not split in general. If you split on something more specific such as a space or a tab then the newline will still be found in the last element of the list.

        use Data::Dumper; while (<DATA>) { my @foo = split; my @bar = split / /, $_; print Dumper \@foo, \@bar; } __DATA__ hello world foo bar baz

        jeffa

        L-LL-L--L-LL-L--L-LL-L--
        -R--R-RR-R--R-RR-R--R-RR
        B--B--B--B--B--B--B--B--
        H---H---H---H---H---H---
        (the triplet paradiddle with high-hat)