|Pathologically Eclectic Rubbish Lister|
Re: Counting instances of wordsby strat (Canon)
|on May 28, 2007 at 11:38 UTC||Need Help??|
Perl is a very flexible and powerful language, even powerful enough to shoot away your own foot, and perl won't complain. But there exists a perl-builtin pragma with name use warnings; which tries to warn you if you write code that might be problematic and to warn you from some errors that may be difficult to be found. If you dont understand what such a warning means, also use diagonstics; which will try to explain why this might be dangerous.
Another very big help is use strict; which may save you from a lot of other - difficult to find - errors. Why you should use strict is a very good node to start with, and Use strict and warnings and 101 reasons to use strict and Why We Use Strict and Use strict warnings and diagnostics.
So it's a good idea to start every program with the following lines:
Here some stuff for security:
You don't control if the filenames given are really filenames, and not commands that will be executed. Try the following code which will try to open notepad under windows:
You can easily avoid this if you use the open with three parameters:
And if you want to open an existing file for reading, it might also be a good idea to check if it is really existing before opening it: