Thomas Bätzler <t.baetz...@bringe.com> writes:

[...]

>
> I hope this answers your question ;-)
>
> Cheers,
> Thomas

Thanks for the effort, but I'm still a bit confused. Just need to
think it over some more maybe.  Is it fair to say that the `magic'
open is far and away the most common working case? And that the 3 arg
open is for unusual circumstances?

Shawn H Corey <shawnhco...@gmail.com> writes:

> Harry Putnam wrote:
>> Is there something beyond style that makes those methods better than
>> what appears to be a simpler format
>
> Yes.  The greatest issue is code injection.  This is especially true
> for the abbreviated form of the two argument open:
>
>   open my $fh, $file or die "could not open $file: $!\n";
>
> What if the user gave this as $file?
>
>   rm -fr ~

Not to be argumentative here... but maybe I can't see as quickly as
some what this would do.

I can't really visualize what would happen there... wouldn't the open
just fail?  Further do we need to prepare for a vastly ridiculous file
name? 

> This should be avoid, especially in server code like CGIs.
>
> Secondarily, the three argument open allows you to skip using binmode.
>
>   open my $fh, '<:encoding(utf8)', $file or die "could not open $file:
> $!\";
>
> Or
>
>   use GD;
>   my $img = GD::Image->new( 1800, 1200 );
>   # draw the picture
>
>   open my $png, '>:raw', 'image.png' or die "could not open image.png:
> $!\n";
>   print $png $img->png() or die "could not print to image.png: $!\n";
>   close $png or die "could not close image.png: $!\n";
>

Sorry, I'd have to do quite a bit of homework before I understand what
that is about.  I'm still at the level where basic simple opens of
reasonably named files is about all I run into.


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to