Bob Showalter wrote: > > > -----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. Dear Bob, thanks a lot for your help and for the explanation to Krah's code. Now I see that John Krahn's code was much better than mine. Best, Pedro > > 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]
-- ******************************************************************* PEDRO A. RECHE , pHD TL: 617 632 3824 Dana-Farber Cancer Institute, FX: 617 632 4569 Harvard Medical School, EM: [EMAIL PROTECTED] 44 Binney Street, D1510A, EM: [EMAIL PROTECTED] Boston, MA 02115 URL: http://www.reche.org ******************************************************************* -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]