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

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;

Replies are listed 'Best First'.
Re^5: Constructing a hash - why isn't my regex matching anything
by Anonyrnous Monk (Hermit) on Dec 19, 2010 at 11:36 UTC

    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