Hi,

If I get the concept of globbing properly, I have been able to prevent it in Unix by 
quoting my parameter list.  I'm not sure how this works for spaces, but it helps a lot 
with CGI stuff.  When I do this, I use an test for STDIN, and if its not preloaded, 
take @ARGV from the command-line as a simulated query string, without the quotes, the 
system splits on & and rerally mucks up the process.

Joseph

Jenda Krynicky wrote:

> From: "Rob Dixon" <[EMAIL PROTECTED]>
> > "Jenda Krynicky" <[EMAIL PROTECTED]> wrote in message
> > 3E1349E5.27703.3CB576EE@localhost">news:3E1349E5.27703.3CB576EE@localhost...
> > > From: "Rob Dixon" <[EMAIL PROTECTED]>
> > > > But glob 'absent_file.txt' returns ('absent_file.txt') so I think
> > > > this does what's required. As perldoc says, glob EXPR returns the
> > > > value of EXPR with filename expansions such as the standard Unix
> > > > shell /bin/csh would do.
> > >
> > > I see ... it only returns nothing if the parameter contained a * or
> > > ?
> > >
> > > I remember having some discussions regarding this and we agreed that
> > > even this should survive the cmdline globbing.
> >
> > Sounds like a little overactive ego on the part of the shell in that
> > case. You're saying that the script in
> >
> >     script.pl *.ext file.ext
> >
> > would see an @ARGV of
> >
> >    ('*.ext', 'file.ext')
> >
> > if there were no files with this extension, but
> >
> >     ('file.ext', 'file1.ext', 'file2.ext', 'file.ext')
> >
> > if all of these (three) files existed?
> >
> > Then how do you pass '*.ext' as ('*.ext') if there are such files?
>
> If we are talking about unix shells
>
>         script.pl '*.ext' file.ext
>
> And actually that's what will work with G.pm as well.
>
> And yes you are right, that's exactly what is the shell supposed to
> be doing.
>
> > I
> > suppose you can pick up the entire command line (I think?) and process
> > that, but I'm very glad most languages don't do clever 'useful' things
> > with your parameter list before called code gets to see them.
>
> The whole problem is that the process gets the commandline if you use
> Windows and a list of parameters if you use Unix.
>
> Normaly the C runtime under Windows parses the commandline and fills
> the argv array. Which is exactly what happens if you run a Perl
> script under windows. The system passes the cmdline and the runtime
> breaks it apart. And breaks it. And your program is supposed to do
> the globbing, even though the runtime already stripped some well
> needed info.
>
> The G.pm basicaly overcomes the broken @ARGV and parses the cmdline
> and globs the parameters at the same time. Close to the Unix way.
>
> If you do not want that you either do not use G.pm and glob just the
> stuff you want or
>         use G qw(NOGLOB StripPerlFromCommandLine GetCommandLine);
>
>         $rawcmdline = GetCommandLine();
>         $cmdlineparams = StripPerlFromCommandLine($rawcmdline);
>
> and parse the raw commandline.
> (Actually it's not totally raw. The IO redirections and pipes are
> already processed by the shell and NOT passed to the process.)
>
> > > So that you could print
> > >
> > > Cannot open file *.txt
> > > or
> > > No files match the *.txt mask
> > >
> > >
> > > If you happen to have several masks with different meanings it might
> > > be good to be able to say which one did not return anything. And it
> > > may not of course :-) I was told this is the behaviour of the Unix
> > > shells ...
> > >
> >
> > Fine, but rather than have the shell performing obscure gymnastics
> > beneath me I'd rather code it explicitly:
> >
> >     for (@ARGV) { print "No files match the $_ mask\n" unless glob };
> >     my @input_files = map glob, @ARGV;
>
> Problem is that under Unix the shell IS performing the gymnastics.
>
> You can quote some params to ensure they are not globbed, but the
> default is globbing.
>
> > > > > From: "Rob Dixon" <[EMAIL PROTECTED]>
> > > > > >     my @input_files = map glob, @ARGV;
> > >
> > > There's one more bad thing about this code. Suppose the script was
> > > called like this
> > >
> > > script.pl "hello world.doc"
> > >
> > > then the @ARGV = ( 'hello world')
> > > but the line above will set @input_files to
> > > ( 'hello', 'world.doc' )
> >
> > Not at all. @ARGV would equal ( "hello world.doc" ) and the statement
> > would set @input_files = ( "hello world.doc" ).
>
> What's your version of Perl?
>
> In file zkGlob.pl I have this:
>         #!perl
>         print "\@ARGV = ( '" . join( "', '", @ARGV) . "')\n\n";
>         @input_files = map {glob $_} @ARGV;
>         print "\@input_files = ( '" . join( "', '", @input_files) .
> "')\n\n";
>
> call it as:
>         c:\temp\zkGlob.pl "hello world.doc" *.txt
>
> and get:
>         @ARGV = ( 'hello world.doc', '*.txt')
>
>         @input_files = ( 'hello', 'world.doc', 'te-fetch.txt')
>
> Jenda
> ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
> When it comes to wine, women and song, wizards are allowed
> to get drunk and croon as much as they like.
>         -- Terry Pratchett in Sourcery
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to