in reply to which data structure and how?

Use an array of hashes, for example.

my @array; my %hash = ( name => "Me", address => "Right here" ); push @array, \%hash; # etc etc etc print $array[2]->{ 'name' }; # prints name from the 3rd hash in the a +rray.

Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Replies are listed 'Best First'.
Re: Re: which data structure and how?
by malaga (Pilgrim) on Mar 31, 2001 at 05:36 UTC
    I couldn't make this work with my data. Where am I going wrong? Nothing prints out.
    $value = "GPY"; $lfilename = "products.pdg"; open(FILE, "$lfilename") or &dienice; while(<FILE>) { @row = split(/\;/); if ($row eq $value){ %data; @data{@fields} = @row; push @records, \%data; } } close (FILE); foreach my $ref ( @records ) { print $ref->{Begin}; }
      You are not using -w or strict. In particular, there is nothing in $row, because it's only used once. $row[0] would be a more likely choice.

      Let Perl help you debug.

      Update: Additionally, @fields is not defined, as far as I can see. Even if your if loop executed, you'd be throwing away the data you just read in. This is *exactly* the time to use strict and -w! If the error messages confuse you, use diagnostics as well. Perl will tell you when you throw away your data and that is most of your problem here. The other part is not setting $/ to "\n;\n".

        I tried that before, still nothing. I took it out just to see if I would get something back. I'm not using strict or -w only because i'm testing. i will once i get something usable. i'm not online with it. My ->ref{} can be any word at the beginning of a line in my file, and it should give me that same line back, right? is there a better way to do this? when i read in the file, i need the records in between the ";"s or between each "Beginning" and "End" to be separate records.