Cockneyphil has asked for the wisdom of the Perl Monks concerning the following question:

Upper / Lower case problem

elsif (!(($ARGV[1]) && (-f "$basepath$ARGV[0]/$ARGV[1].dat"))) { &listtoday;

If the above code works with files with a .dat extension How would I get it to work with .DAT as well ('cos it won't at the moment)

Many thanks in advance

Edited by footpad, ~Tue Jul 30 11:10:36 2002 (UTC) : Added <code> and other formatting tags, per Consideration,

Replies are listed 'Best First'.
Re: Upper / Lower case extensions
by Zaxo (Archbishop) on Jul 30, 2002 at 12:10 UTC

    The glob function can do that for you:

    my @datafiles = grep { -f } glob("$basepath$ARGV[0]/$ARGV[1].{dat,DAT}");
    Note that your program logic will change since there can be more than one file for a given pair of arguments.

    After Compline,
    Zaxo

      Good one, Zaxo!

      If odd cases like Dat, dAt, and other such silliness might exist, you could also use:

      my @datafiles = grep { -f } glob("$basepath$ARGV[0]/$ARGV[1].{d,D}{a,A}{t,T}");
      But if you only have to deal with all upper or all lower case, Zaxo's answer is better.
      --
      Mike
        I suggest:
        my @datafiles = glob("$basepath$ARGV[0]/$ARGV[1].[dD][aA][tT]");

        It takes care of the special cases and eliminates the grep.

        Figuring out why it eliminates the grep is an exercise for the reader. :-) Hint: You might need to use man instead of perldoc. . .

        -sauoq
        "My two cents aren't worth a dime.";
        
Re: Upper / Lower case extensions
by NaSe77 (Monk) on Jul 30, 2002 at 12:02 UTC
    just an idea
    elsif (!(($ARGV[1]) && ((-f "$basepath$ARGV[0]/$ARGV[1].dat") || (-f "$basepath$ARGV[0]/$ARGV[1].DAT")))) { &listtoday;
    perhaps ...

    ----
    NaSe
    :x

A reply falls below the community's threshold of quality. You may see it by logging in.