> -----Original Message-----
> From: Pedro Antonio Reche [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, December 17, 2002 7:22 PM
> To: [EMAIL PROTECTED]
> Subject: help parsing file
> 
> 
> ... I am not
> please with it, as it generates an empty element in the hash from the
> header of the file

John Krahn's code corrects a problem with your code. You write:

   $_ =~ /product=\"(.+)\"/;
   $gname = $1;

But what if the regex failed to match? Rather than $1 having an undef value,
it would have whatever value it previously held. This could be a major
problem. Never use the $1,$2,$3 variables without checking that the regex
matched. John's construct,

   my ($gname) = /product="([^"]+)"/;

solves this problem. If the regex fails to match, $gname will be guaranteed
to be undef.

As far as the empty element you're getting at the start, you can do a couple
of things:

1) do a read before entering your loop to skip over the
   "header" data:

      <>;               # skip header
      while(<>) {
          ...

2) the data you're interested in seems to start with
   "complement" following "CDS", while the header data
   doesn't. So you could skip data that doesn't have
   "complement":

      while(<>) {
         next unless /\s*complement/;   # skip header
         ...

HTH

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to