in reply to Re: Using * character to open all Files in the directory
in thread Using * character to open all Files in the directory

The c:\> in Prayag's post gives us a good indication that they're doing this in a Windows (or DOS) environment, which (by default) doesn't expand asterisks, etc. (aka "shell globbing").

Instead, you need to all such expansion yourself, with something like...

my @files; push @files, glob foreach @ARGV;

... which breaks as soon as you want to open a file containing an asterisk or other expansion character.

Anyhoo, for further discussion, see the recent portable globbing behavior for command-line tool.

    --k.


Replies are listed 'Best First'.
Re: Re: Re: Using * character to open all Files in the directory
by BrowserUk (Patriarch) on Jul 06, 2002 at 00:05 UTC

    FWIW, I haven't found a way of creating a filename with an embedded wildcard char yet.

    This may be possible under *nix, but I wonder what would stop the shell from trying to expand it everytime someone tried to use it? Showing my ignorance of *nix stuff again.

      Yes Windows forbids the use of numerous characters including several non while cards such as : and '. In UN*X you escape the wild character to protect it, same idea as in Perl.

      --
      perl -pew "s/\b;([mnst])/'$1/g"

        Actually, I already know what chars windows does/doesn't allow in filenames. Your assumption is slightly wrong though, vis.

        C:\test>echo .>' C:\test>dir Volume in drive C has no label. Volume Serial Number is 8C87-E163 Directory of C:\test 02/08/20 02:55a <DIR> . 02/08/20 02:55a <DIR> .. 02/08/20 02:55a 3 ' <<<<<! 02/08/13 03:12p 210 178232.pl

        In an earlier thread the following:

        ... @ARGV = map glob, @ARGV; ...

        was advised against because "someone might pass in an escaped (eg.what\*ever) filename containing glob chars", and that might cause the above snippet to "break" on *nix environments. I thought then and I am asking now:

        1) Why would anyone wish to embed "*" in a filename? Other than shear perversity.

        2) How would this break?

        Surely, globbing filespec of "what\*ever" is going to match the file named "what*ever"? Granted it might also match "whatifever" etc. but (see Q.1).

        I guess I accept that OS's in general (*nix included) have to reserve some chars in filenames and other system entities (try creating a file "feet/sec" on *nix?).

Re: Re: Re: Using * character to open all Files in the directory
by vek (Prior) on Jul 06, 2002 at 02:31 UTC
    Kanji++ You're right of course, I must admit that in my haste I did not notice the C:\>.

    Cheers.

    -- vek --