develooper Front page | perl.beginners | Postings from May 2008

Re: Comparing files with regular expressions

Thread Previous | Thread Next
From:
Chas. Owens
Date:
May 2, 2008 16:56
Subject:
Re: Comparing files with regular expressions
On Fri, May 2, 2008 at 10:44 AM, rubinsta <rubinsztajn@gmail.com> wrote:
snip
> Any thoughts as to why
>  some of the matches are getting missed?
snip

Not off hand.  I will extract your code and do some tests.  Can you
send me your data or is it sensitive?

snip
>  Just out of beginner curiosity, why did you suggest I use the 3
>  argument filehandle instead of:
>  open(EX, "exclude1.txt") or die $!
snip

Because the three argument version of open is safer.  It doesn't
matter in the code you wrote because you used a literal string, but if
you say

open FH, $file or die "could not open $file: $!";

expecting FH to be a read filehandle and $file contains the filename
">important", you will wind up with a write filehandle.  Specifying
the type of filehandle you want separately from the file is an
important safety feature.  Using the old version of open is a bad
habit you should not develop.  You should know it exists (like many of
the other bad habits left over from earlier versions of the Language)
in case you run into code that uses it, but you shouldn't use it
yourself.  I would also strongly recommend using lexical filehandles
instead of the old bareword style for similar reasons.

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

Thread Previous | Thread Next


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About