Thanks for the tip.
The gist is that it's grabbing the first field in a comma delimited text
file and making that the key. If the match fails, then something horribly
wrong has gone on with the input file and there will be much bigger fish to
fry.

How would I go about making that code "safe", though? 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Friday, June 08, 2001 10:47 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: Printing a hash - weird behavior


>>>>> "jbarry" == jbarry  <[EMAIL PROTECTED]> writes:

jbarry>         /(.*?),/; #pattern matching. Grabs everything up to the
first comma.
jbarry> (The material number)
jbarry>         $key = $1;

All other comments included, the one thing that hasn't been pointed
out is that this is dangerous.

NEVER use $1 unless it's in the context of a conditional based on the
pattern match.  If the match fails (perhaps unexpectedly), you'll
be getting the *previous* $1, and that will certainly not be what
you had expected.

jbarry>         /.*?,(.*)/;
jbarry>         #print 'First:'. $1."\n";       # sanity check 1

Ditto here.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!

Reply via email to