Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Filtering Output from two files

by Anonymous Monk
on Feb 06, 2018 at 11:38 UTC ( [id://1208557]=note: print w/replies, xml ) Need Help??


in reply to Re: Filtering Output from two files
in thread Filtering Output from two files

#!/nairvigv/bin/perl use strict; use warnings; use Data::Dumper; my $file1 = 'BBIDs.txt'; my $file2 = 'fixedincomeTransparency.out.px.derived.updates'; #reading file1 into a hash my %hash; my @fields; open (my $fh,'<',$file1) or die $!; while(my $line=<$fh>) { chomp $line; next if $line =~ /^\s*$/; $hash{$line}=1; } #print Dumper(\%hash); close $fh; open (my ($fh2),$file2) or die $!; while (my $row = <$fh2>) { chomp $row; print "$row\n"; next if $row =~ /^\s*$/; my (@fields) = split(/\|/, $row); print "$fields[0]\n "; if (exists $hash{$fields[0]}) { print "$row\n"; } } close $fh2; ~
Hello this works for a program with less lines i.e 10. However when i run it on a big file say about 700k lines nothing happens. Any idea what can be causing this?

Replies are listed 'Best First'.
Re^3: Filtering Output from two files
by LanX (Saint) on Feb 06, 2018 at 11:48 UTC
      Sorry would indentation next time onwards. Basic what's happening is the big files have whitespace before and after each entry So I have to remove those while I store them to a key .
        > So I have to remove those while I store them to a key

        OK ... what is hindering you? :)

        update

        you are already using a regex to match empty lines, time to understand what they do

        perlre#Metacharacters

        ^ Match the beginning of the string Not in [] (or line, if /m is used) ... $ Match the end of the string Not in [], but can ... * Matches the preceding element 0 or more Not in [] times

        update

        and look again into marshall's code ;-)

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Wikisyntax for the Monastery

      open (my ($fh2),$file2) or die $!; while (my $row = <$fh2>) { chomp $row; print "$row\n"; next if $row =~ /^\s*$/; my (@fields) = split(/\|/, $row);
      so i have to add $row =~ s/\s*$// after  next if $row =~ /^\s*$/; and it will work? i cant really check from here since i am at home and would have to wait another 12 hours
        i cant really check from here since i am at home
        1. Install perl at home
        2. Mock up some sample data
        3. Run your code at home against the sample data

        Now you will know whether it works without having to wait.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1208557]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-25 09:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found