in reply to Re^2: Constructing a hash - why isn't my regex matching anything
in thread Constructing a hash - why isn't my regex matching anything

Yes. Use less memory.

Look over your program where you are needlessly wasting memory. Maybe you are reading a complete file into memory instead of processing it line by line. Maybe you are doing something else that wastes memory.

Even still, 125000 lines is not much, so most likely you are doing something that wastes a lot of memory.

  • Comment on Re^3: Constructing a hash - why isn't my regex matching anything

Replies are listed 'Best First'.
Re^4: Constructing a hash - why isn't my regex matching anything
by perl_mystery (Beadle) on Dec 19, 2010 at 10:56 UTC

    I did look at my code(below),I am hardly doing anything other than constructing the hash

    #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash; open my $fh, '<', $ARGV[0] or die "could not open $ARGV[0]'' $!"; while (my $line = <$fh>) { #print "line:$line\n"; my ($key) = $line =~ /;([^;]+)\s-\s/; #print "KEY:$key\n"; my ($value) = $line =~ /\.\\(.*)-\d+\;/; #print "VALUE:$value\n"; if (!($hash{$key})) { $hash{$key}=$value; } } open my $hash, '>', "hash_flf.txt"; print Dumper(\%hash); close $hash;

      How much memory do you have available? The following test case on my system uses 34 MB (according to top) after having filled the hash, and a total of 110 MB after having created the dump string.

      #!/usr/bin/perl -w use strict; use Data::Dumper; my $key_ = '//programfiles/documents/data/lookup/script_auth_pap.h'; my $val_ = 'root\edit\perl\scripts\scripths\sec\inc\script_auth_pap.h' +; my $c = 0; my %hash; for (1..125000) { my $key = "$key_$c"; my $val = "$val_$c"; $c++; $hash{$key} = $val; } <>; # 34 MB my $dump = Dumper \%hash; <>; # 110 MB