Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Different hashes part II

by Anonymous Monk
on Mar 26, 2004 at 16:29 UTC ( [id://340066]=note: print w/replies, xml ) Need Help??


in reply to Different hashes?

Hello Monks I just send a message not long ago (different hashes?), and I tried your suggestions. I thought it was working because I run the script with a small textfile, but it is not!! :(
It is creating a new hash, adding a new record at the time. it's exponential huge
$VAR1 = { 'WaterSports' => [ '8765', [ 'Drysuit', 'r', 'M-L' ] }; $VAR1 = { 'WaterSports'=> [ '8765', [ 'Drysuit', 'r', 'M-L' ] '8365', [ 'Paddle', 't', '45' ] ] };
This is my modify code:
open(INFILE, "products-id.txt")|| die "Cannot open products-id.txt fil +e"; open (OUTPUT,">$output") or die ("Can't open file $output $!"); chomp(my @ProductArray = map { /^\s*$/ ? () : $_ } <INFILE>); close (INFILE); foreach my $line(@ProductArray) { my ($Category, $ID, $Name, $Type, $Size) = split( / /, $line ); push(@{$AllProducts{$Category}}, $ID, [$Name, $Type, $Size]); print OUTPUT Dumper(\%AllProducts); }
I also tried this
push @{$AllProducts{$Category}}, ($ID, [$Name, $Type, $Size]);
Thanks

Replies are listed 'Best First'.
Re: Different hashes part II
by Anonymous Monk on Mar 26, 2004 at 16:50 UTC
    I am trying borisz's solutions, but as well as the others it's taking too much time to execute, so I cancelled it.. but this time the PARTIAL output I am getting is OK, I am not sure it is repeating the whole thing over and over..
    Borisz's script: #!/usr/bin/perl use Data::Dumper; my %products; while (defined( $_ = <DATA> )){ next if $. <= 2 || /^\s*$/; my @d = split ' '; my $cat = shift @d; my $id = shift @d; push @{$products{$cat}}, [ $id, \@d ]; } print Dumper(\%products);
      It is OK, I should not print the dumper(\%product) to the output file, inside the loop mmmmmm sorry about that
Re: Different hashes part II
by graff (Chancellor) on Mar 26, 2004 at 17:21 UTC
    It might have been better to make this a reply or update to your earlier post. Since you seemed to have missed the point of advice that others gave there, I think I'll post a reply there myself, because more information is available there regarding the problem. (In fact, maybe the present thread should be "considered" for removal or relocation.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 15:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found