more useful options | |
PerlMonks |
Re: Someone please verify this.by GrandFather (Saint) |
on Jul 10, 2007 at 04:35 UTC ( [id://625761]=note: print w/replies, xml ) | Need Help?? |
There are a bunch of errors and dodgy practices there. The first thing that you need to do is add strictures:
Then you need to declare all the variables you use by prefixing them with my. For example:
You should always use the three parameter version of open to improve code readability and reduce possible errors of various sorts:
The while loop is reading one line at a time so you don't need a for loop (see perlsyn - foreach) to iterate over anything - $efile is not an array. In your regex you use a character set ([!,\#,\",\$,\%,&]), but it isn't what you possibly expect. The characters included in the set are !,#"$%& which includes comma, that may surprise you. Note that none of the quoted characters in the set need to be quoted. The complete code rewritten and modified to take itself (on my system) as the input looks like:
prints:
Note that I added the __DATA__ (see perldata - Special Literals) section so I could include something for the regex to match. DWIM is Perl's answer to Gödel
In Section
Seekers of Perl Wisdom
|
|