>>>>> "Dan" == Dan Muey <[EMAIL PROTECTED]> writes:
Dan> for(`ls /files/`) {
Dan> if(`cat $_ |grep $string`) { push(@matchedfiles,$_); }
Dan> }
Hmm. Where to begin?
- Dangerous use of ls.
- Useless use of cat.
- Dangerous use of backticks.
- Shelling out when every one of those steps is done as well
or better by Perl.
- Insecure use of child shells
In short, code that should be used as a "BEFORE" model in a "BEFORE"
and "AFTER" talk on any of the subjects of best practices, security,
optimizing for speed, maintainability, dealing with filenames with
whitespace, etc etc.
Dan> Then you are only greping one file at a time instead of a list of
Dan> too many. Of course what would be better is to use the readdir()
Dan> functions to list the files and open() and grep() combo to grep
Dan> the contents. But the same principle applies.
More than just better. More correct. Safer. Faster. Easier to
maintain. Less likely to break when tried on real-world stuff.
I say this not because I am criticizing you Dan, but because I want to
make sure that NOBODY ELSE ON THIS BEGINNER LIST COPIES THAT CODE for
their own purposes. It's really just so far off the mark to be badly
dangerous.
--
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!
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]