Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Sort of like a file handle, but not

by bikeNomad (Priest)
on Aug 21, 2001 at 22:41 UTC ( #106679=note: print w/replies, xml ) Need Help??

in reply to Sort of like a file handle, but not

You're calling glob, which expands file name arguments. Since they're unquoted, each of the "file names" is returned to you separately. Your code is equivalent to:
my $x; while (defined($x = CORE::GLOBAL::glob('hello there how are you', 0))) + { print "$x\n"; }
Had you had wildcards in there, they would have been expanded as well.

Replies are listed 'Best First'.
Re (tilly) 2: Sort of like a file handle, but not
by tilly (Archbishop) on Aug 21, 2001 at 22:48 UTC
    Leading to shell fun and games like the following, which (at least on 5.005) works on Linux but not on Windows...
    print map "$_\n", glob("{A,B}{a,b}");
    Ah well, I guess non-portability is what I get for being clever. :-(
      Actually globbing is one of the most unportable things on unix. The way perl solves this is by calling /bin/csh with your glob and passes you the result. This is also why globbing CANT work while working under Taint mode...

      T I M T O W T D I
        As of 5.6 perl began implementing this with bsd_glob. See perldoc -f glob and perldoc File::Glob for more...

        P.S. I've been using it on Windows without any problems.

        Thanks, Ira,

        "~/.signature not found"
        ~Signature from my lead's e-mail

      I beg to differ (about Windows). Run this at a command prompt:

      C:\> perl -e "print map( \"$_\n\", glob(\"{A,B}{a,b}\"))"

      For this particular example, I get identical results on Windows to that on UNIX. Note that Windows' braindead command line quote handling, or lack thereof, requires escaping the double quotes in the perl code and surrounding the entire thing with double quotes

      Under Windows, each executable must do its own command-line globbing, Perl, like any Windows executable must then expand wildcards on its command line, which it seems to do by calling the standard Microsoft __setargv routine, which is far less powerful than even csh in terms of globbing.

      On the other hand, the internal glob() routine is implemented specially for Windows, to behave like a UNIX shell. At least it is in ActiveState's Perl.


      Just call me the Anti-Gates ...
        Before begging too much, run:
        perl -v
        As I stated, I find that the output differs between Perl 5.005_03 on Windows and Linux. On Windows I get nothing. On Linux I get 4 lines.

        Now the odds are that you have a recent Perl. That means either a heavily patched 5.005 or (more likely) you have 5.6. In that case see the other notes in this thread about the glob implementation changing.

        In short, before saying someone's statement (made on a direct test) is wrong, it is good to have tied out all relevant factors. And in this case you can see that while it may not differ for you, it does for me. And it does for me on the version that I stated up front had differences.

        Incidentally I already knew about the braindead command line handling on Windows. If you want to prove that the executable handles it, it is probably easiest to just write a trivial VB application that echoes the command line. And the best way around the way that perl.exe handles it is to pick a different quote delimiter:

        perl -e "print map qq($_\n), glob('{A,B}{a,b}');"

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://106679]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2021-04-18 02:30 GMT
Find Nodes?
    Voting Booth?

    No recent polls found