in reply to how to hash this
Here's how I would approach this, not necessarily knowing everything about the file format:
But again, your file format is very awkward, and without more details, there's not much more we can do with it. However, what we've given you should give you a good start of how to set up a data structure to use with this file.my @products; while ( <FILE> ) { if ( /^Begin Product (.*)/i ) { # We have a product starting line my %hash; $hash{ 'name' } = $1; # get the product name. # I'm guessing on the next 6 lines as to their functions. $hash{ 'description' } = <FILE>; $hash{ 'numberline1' } = <FILE>; $hash{ 'numberline2' } = <FILE>; my $track = <FILE>; $hash{ 'tracking' } = ( $track =~ /(Yes|No)/i ); $hash{ 'images' } = <FILE>; $hash{ 'producttext' } = <FILE>; # Now you have some weirdness to your stuff. Some of # your items have an XML-like structure, some don't. # I'll assuming that if the lines starts with Begin, # it indicates the start of a list of items. Of course, # End Product will end all this. my $line = <FILE>; last if ( $line ~= /End Product/ ); if ( $line ~= /^\s*Begin Option (.*)$/ ) { my $name = $1; my @option_list; while ( <FILE> ) { last if ( /End Option/ ); push @option_list, $_; } $hash{ $name } = \@option_list; } else { # if there is no option, then stick what's in front of the : as +the hash name, the rest as it's value my ( $name, $value ) = ( $line ~= /^\s*(.*?):(.*)$/ ); $hash{ $name } = $value; } push @products, \%hash; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: how to hash this
by malaga (Pilgrim) on Mar 31, 2001 at 23:08 UTC | |
|
Re: Re: how to hash this
by malaga (Pilgrim) on Apr 01, 2001 at 00:36 UTC | |
by chromatic (Archbishop) on Apr 01, 2001 at 02:01 UTC | |
by malaga (Pilgrim) on Apr 01, 2001 at 02:14 UTC | |
by bbfu (Curate) on Apr 01, 2001 at 07:14 UTC | |
by malaga (Pilgrim) on Apr 01, 2001 at 08:59 UTC | |
|