"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.


In reply to (bbfu) Re(5): how to hash this by bbfu
in thread how to hash this by malaga

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.