in reply to Re: Re: Re: Re: how to hash this
in thread how to hash this
"i thought this: ... was putting each line of the file into the hash"
It is. The problem is that you need to declare $ref before the print line. You're also declaring $hash and never using it and you're declaring %hash and $line twice.
Plus, @products is being populated for you (or, rather, it would be if you weren't lasting right before it all the time) but you're never using it. I say, ditch $ref and use @products.
open (FILE, $lfilename) or &dienice; # my $hash; # Never used. ??? # my $line; # Declared my inside the while(). ??? # my %hash; # Declared my inside the while(). ??? my @products; while ( <FILE> ) { if ( /^Begin Product (.*)/i ) { my %hash; $hash{ 'name' } = $1; $hash{ 'description' } = <FILE>; $hash{ 'numberline1' } = <FILE>; $hash{ 'numberline2' } = <FILE>; my $track = <FILE>; $hash{ 'tracking' } = ( $track =~ /(Yes|No)/i ); $hash{ 'images' } = <FILE>; $hash{ 'producttext' } = <FILE>; my $line = <FILE>; # Why are you doing this, anyway? # last if ( $line =~ /End Product/ ); push @products, \%hash; }} # @products contains all of your hashes. # Lookup the one you want in it. print "<B>$products[0]{name}</B>"; # Where was $ref supposed to've come from? # print "<B>", my $ref->{name}, "</B>";
Well, I hope that helps some. You should definately read perlref.
bbfu
Seasons don't fear The Reaper.
Nor do the wind, the sun, and the rain.
We can be like they are.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (bbfu) Re(5): how to hash this
by malaga (Pilgrim) on Apr 01, 2001 at 08:59 UTC | |
by bbfu (Curate) on Apr 01, 2001 at 09:16 UTC | |
by malaga (Pilgrim) on Apr 01, 2001 at 09:28 UTC |