in reply to Re: writing portable file processing scripts that use wildcards in filenames
in thread writing portable file processing scripts that use wildcards in filenames

There's no harm in calling glob() on a filename with no wildcards.
Indeed, there isn't.
Just glob all but the last argument.
No, that would be wrong. Just because globbing on a filename without wildcars is ok doesn't mean that the result of a glob gives you a fixed point.

Suppose for instance you have a utility that removes those files that are given as argument (like rm does). Let's call it remove. But, unlike rm, it globs its arguments - even when working in an environment that globs. Suppose you have a directory that contains the following files:

thesis_worked_on_for_the_past_four_years naked_perl_chicks.tar.gz parrot_1.0.0.tar.gz [a-z]*
And you want to remove that pesky file named [a-z]*. You call your program like this:
remove *a-z*
If you had called rm, the first three files would still be there, with the pesky file removed. However, remove, globbing its arguments, will remove the first three files, leaving the pesky file where it is.
Perl --((8:>*

Replies are listed 'Best First'.
Re^3: writing portable file processing scripts that use placeholders in filenames
by halley (Prior) on Dec 02, 2005 at 13:42 UTC
    But that's not the syntax of the command the original poster was recalling. rm would glob ALL arguments. cp would glob all but the last argument, since the last argument is defined as the destination.

    Perl's glob() expands bracket classes in some versions, usually in the same environments where the shells do too. If you don't want the shell to expand bracket classes, you escape them at the shell level: rm '[a-b]foo', or rm \[a-b\]foo. If you have to pass a bracket class to a program which globs for you, even after the shell would normally escape it, you may need to escape it twice. If this is a really common concern, then the "portable" way would be more elaborate. But then again, command line arguments are never going to be 100% "portable."

    If your filesystem has allowed a ? or * in your filename, you'll need to use some more serious tools, because that's generally a filesystem bug.

    --
    [ e d @ h a l l e y . c c ]