[Israel.pm] typeglobs

Gabor Szabo szabgab at gmail.com
Wed Jun 27 03:15:19 PDT 2007

On 6/27/07, Levenglick Dov-RM07994 <dovl at freescale.com> wrote:
> Can you elaborate? Why is opening into a scalar better than opening into
> a file handle?

1) The 2 params version creates a security risk:

my $filename = get_from_external_user();
open FH, $filename or die;  # open for reading

What if the user sends you ">a_critical_file" as the filename?

2) open my $fh,   $fh is scoped to the enclosing block while FH is global

3) You can pass $fh to functions without typeglob magic and without
asking questions on mailing lists :-)


Gabor Szabo
Perl Training in Israel  http://www.pti.co.il/

More information about the Perl mailing list