develooper Front page | perl.perl5.porters | Postings from July 2008

Re: Creative and *routine* use of so-called "magic" ARGV (was [perl#2783] Security of ARGV using 2-argument open)

Thread Previous | Thread Next
From:
Mark Mielke
Date:
July 29, 2008 08:12
Subject:
Re: Creative and *routine* use of so-called "magic" ARGV (was [perl#2783] Security of ARGV using 2-argument open)
Message ID:
488F3352.4050800@mark.mielke.cc
David Nicol wrote:
> On Tue, Jul 29, 2008 at 9:32 AM, Abigail <abigail@abigail.be> wrote:
>   
>> It has been documented for a long, long time how to [handle leading/trailing space in 2-arg open]:
>>
>>    my $file = " hello ";
>>    open my $fh, "< ./$file\0";
>>
>>
>> Granted, "\0" is a bit of an oddity, but it is possibly. And you don't
>> need sysopen.
>>     
>
> so would
>     $_ = (m|^/| ? "< $_\0" : "< ./$_\0") for @ARGV;
> work as a football safety device, inserted into the execution process
> at the appropriate time (i.e. after getopts)
>   

It would work on UNIX. :-)

To make it work in more places, I would suggest doing the near opposite:

    $_ = (/^\s/ ? "< ./$_\0" : "< $_\0") for @ARGV;

This is under the assumption that one can USE '/' on most platforms, but 
it may not BE '/' on all platforms. :-)

Cheers,
mark

-- 
Mark Mielke <mark@mielke.cc>


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About