List Info

Thread: Re: repeated use of grep




Re: repeated use of grep
country flaguser name
United States
2007-06-11 20:40:12

>>&gt;>> "Glenn" == Glenn Becker < burningc%40sdf.lonestar.org">burningcsdf.lonestar.org&gt; writes:

Glenn>; /:s+(.*tgz$)/;
Glenn> push packages, $1;

This is really dangerous.... don't do this. Don't use $1 unless you've also
checked that the match has succeeded. If you're *absolutely* sure it will
*always* match, at least add "or die" so that your program will abort *when*
you are wrong (not "if&quot; .

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<; merlyn%40stonehenge.com">merlynstonehenge.com> <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!

__._,_.___
.

__,_._,___
Re: repeated use of grep
country flaguser name
United States
2007-06-12 13:12:01


> Glenn> /:s+(.*tgz$)/;
>; Glenn> push packages, $1;
>
> This is really dangerous.... don't do this. Don't use $1 unless
> you've also checked that the match has succeeded. If you're
> *absolutely* sure it will *always* match, at least add "or die" so
> that your program will abort *when* you are wrong (not "if&quot; .

Aww, I shoulda known it was just too easy! I ain't THAT smart! :^T

Thanks again, Randal. Back to the proverbial drawing board ... er, xterm.

G

__._,_.___
.

__,_._,___
Re: repeated use of grep
country flaguser name
United States
2007-06-12 19:02:19


> Glenn> /:s+(.*tgz$)/;
>; Glenn> push packages, $1;
>
> This is really dangerous.... don't do this. Don't use $1 unless
> you've also checked that the match has succeeded.

Would this be a reasonable place to use "eval" -- say, wrap the two
lines above in an "eval" block? like the following

eval { /:s+(.*tgz$)/;
push packages, $1 };
print "No match occurred!n:$" if $;

Is the danger of using $1 that, if the match does not succeed, you are
accessing a "left-over" $1 from another match?

Thanks,

Glenn

__._,_.___
.

__,_._,___
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )