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

can you use glob with variables...i.e.: @test = glob ("$var*");

Replies are listed 'Best First'.
Re: glob & variables
by Rich36 (Chaplain) on Jan 09, 2002 at 21:17 UTC
    Yes.
    I just tried perl -e '$var = ".lst"; print <*$var>;' and it worked fine.
    Rich36
    There's more than one way to screw it up...

Re: glob & variables
by fuzzysteve (Beadle) on Jan 09, 2002 at 21:21 UTC
    yes.


    I checked. 7 lines of code (so strict isn't needed. its a habit ok?)
    #/usr/bin/perl -w use strict; my $var="/usr/local/apache/logs/"; my @file=glob("$var*"); foreach (@file){ print "$_\n"; }
    it prints out a list of files in the given directory.
Re: glob & variables
by gav^ (Curate) on Jan 09, 2002 at 23:31 UTC
    I was just wondering why you didn't think of trying? I often just run perl from the command line and try out a couple of lines of code to see what happens:
    C:\>perl $, = ','; $var = 'a'; @test = glob("$var*"); print @test;
    It's a nice way to check things before putting it in a bigger script.