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

Forgive me if I'm not much help. I'm pretty tired and I have work to do so I can't spend long on it...

I didn't think about the fact that the records would have different number of lines in them. Am I ok to assume that the first part of the records will all be the same and just have an optional number of sub-recrods (Options)? If so, then are you wanting to save the Option records? If not, then just remove the last like I said and you should be ok (since the while(<FILE>) will slurp up all the Option records as well as the "End Product" and ";" lines; ie: the if block won't match). If you did want to save the Option records, you'll have to put a sub-while loop in just before the push to read in all the Option records. It should have similar logic to the outter while loop.

That said, I'm not sure this is the best way to go about this. I don't really like reads inside the if block because you're not doing any EOF checking on them and you're usurping control from the while. I think you might be better off going with Trimbach's suggestion or, perhaps even better (depending on how you implement it), DeaconBlues' method, both of which use $/, though DeaconBlues' use of it actually make more use of it. (Okay, that last bit didn't make much sense but, like I said, I'm sleepy.)

Anyway, sorry I couldn't help more. Hope you get it. Gotta work. =(

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(7): how to hash this
by malaga (Pilgrim) on Apr 01, 2001 at 09:28 UTC
    i'll have to start fresh tomorrow i think. the way i'm doin it seems ok, but maybe there's a better way. i'll look at them all again. right now i'm stuck because i need to print a file that is named with ref->{'prodtext'}, and i can't seem to open the file within the current block (because it only hits the first instant and stops) and i can't make it work in a sub routine because i'm using a hash and not an array and i don't know if there's a way to pass ref->{'prodtext'} to the subroutine.

    <code> foreach my $ref (@products) { if ($ref->{prodname} =~ ($value)){ print $ref->{prodcode}; print "
    "; print $ref->{prodname}; print "
    "; print $ref->{prodprice}; print "
    "; print $ref->{prodtext}; print "
    "; print "
    "; #here is where i need to open the file named in $ref->{prodtext}, and just print out the contents. i tried to put it in a subroutine, but don't know how to pass the hash element to it. </code.