in reply to Re: running same bit of code twice
in thread running same bit of code twice

Hi pfaut,

I'm interested in the phrasing of the open command:

open FH,"<",$datafile or die "Could not read virtual file";
I habitually use:
open FH, "$datafile" or die "Can't open $datafile: $!";
although I'm aware of the  < being an 'open for read only' tag I would use it as follows:
open FH, "< $datafile" or die "Can't open $datafile: $!";
I wondered if you would talk me through your use of it and why you might consider it necessary to use   < at all.

Thanks for your help

Replies are listed 'Best First'.
Re: Re: Re: running same bit of code twice
by belg4mit (Prior) on May 04, 2003 at 18:43 UTC
    3-arg open is considered more secure than 2-arg open, as perl won't be looking to change it's behavior based upon any special characters (such as < > |) (update: in the filename). Since 3-arg open has no default (you can't leave the second arg undefined), you must explicitly indicate "open for read-only". Finally, some people simply like to be explicit. Why would you write
    foreach my $apple (qw(McIntosh Empire Gala)){ $apple }
    When this would do just fine
    foreach (qw(McIntosh Empire Gala)){ $_ }

    --
    I'm not belgian but I play one on TV.