Perl wildcard un-expansion

Perl wildcard un-expansion

am 19.11.2007 10:36:46 von alexxx.magni

I am usually very happy to access any args I gave to my prog as:
> myprog.pl *.pgm
using @ARGV

In this particular occasion instead, I find that I would like to
access the literal argument written by the user, i.e.
> myprog.pl img0*.pgm
to be able to access "img0*.pgm", not its expansion

is it possible?

thanks!

Alessandro Magni

Re: Perl wildcard un-expansion

am 19.11.2007 10:41:51 von jurgenex

alexxx.magni@gmail.com wrote:
> I am usually very happy to access any args I gave to my prog as:
>> myprog.pl *.pgm
> using @ARGV
>
> In this particular occasion instead, I find that I would like to
> access the literal argument written by the user, i.e.
>> myprog.pl img0*.pgm
> to be able to access "img0*.pgm", not its expansion
>
> is it possible?

That expansion is performed by the shell and there is nothing perl can do
about it because when it recieves the arguments the shell expansion has
happened already.

If you want to include a literal * in a command line argument then you need
to use the proper shell escape character or whatever means your shell
provides to prevent the shell from expanding that *.

jue

Re: Perl wildcard un-expansion

am 19.11.2007 10:43:31 von Peter Makholm

"alexxx.magni@gmail.com" writes:

> In this particular occasion instead, I find that I would like to
> access the literal argument written by the user, i.e.
>> myprog.pl img0*.pgm
> to be able to access "img0*.pgm", not its expansion

Not as such. The expansion happens in the shell and perl has no way of
knowing if the arguments is a result of an expansion or not.

But you can call you program like:

$ myprog.pl 'img0*.pgm'

and then perl will se the argument untouched. (This isn't really a perl
question but a question about the environment you're using perl in. So
teh correct answer may differ acording to platform.)

//Makholm

Re: Perl wildcard un-expansion

am 19.11.2007 11:33:05 von sheinrich

On Nov 19, 10:36 am, "alexxx.ma...@gmail.com"
wrote:
> to be able to access "img0*.pgm", not its expansion

On a side note to the former answers, some shells put the commandline
into the environment.
Take a look at the content of %ENV. Maybe you're lucky.

Cheers,
Steffen

Re: Perl wildcard un-expansion

am 19.11.2007 23:14:24 von Michele Dondi

On Mon, 19 Nov 2007 09:41:51 GMT, "Jürgen Exner"
wrote:

>> In this particular occasion instead, I find that I would like to
>> access the literal argument written by the user, i.e.
>>> myprog.pl img0*.pgm
>> to be able to access "img0*.pgm", not its expansion
>>
>> is it possible?
>
>That expansion is performed by the shell and there is nothing perl can do
>about it because when it recieves the arguments the shell expansion has
>happened already.

In shells that *do* perform wildcard expansion, like most *NIX one
actually do. Indeed, under cmd.exe one has to take care of that
manually, e.g. by means of

BEGIN {@ARGV= map glob, @ARGV}


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^ ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

Re: Perl wildcard un-expansion

am 21.11.2007 10:44:19 von alexxx.magni

On 19 Nov, 11:33, sheinr...@my-deja.com wrote:
> On Nov 19, 10:36 am, "alexxx.ma...@gmail.com"
> wrote:
>
> > to be able to access "img0*.pgm", not its expansion
>
> On a side note to the former answers, some shells put the commandline
> into the environment.
> Take a look at the content of %ENV. Maybe you're lucky.
>
> Cheers,
> Steffen


not on BASH, it seems...

Alessandro