"Perlwannabe" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > This works - i've tried it... > > > > print 'Deleted ' , unlink (<*997*>) , ' files.\n'; > > > > good luck > > Duncan > > Yes, it does. But it does not work when reading from a variable. > > my $temp = '*997*'; > print 'Deleted ' , unlink (<$temp>) , ' files.\n'; > > This very simple variation of your example does not work.
the reason why YOUR version won't work is because when Perl sees '<$temp>', it's trying to read from the file handle '*997*'. it's NOT doing glob for you. example: my $s = '*.pl'; my @c = ('*.pl'); #-- #-- even though the following 2 lines seems identical and should work to give you #-- all file names ending with *.pl in the current directory, only the second version really works #-- my @files1 = <$s>; #-- this does not work because Perl is trying to read from the '*.pl' file handle! my @files2 = <$c[0]>; #-- this does work. see reason below for(@files1){ print "[EMAIL PROTECTED]: $_\n"; } for(@files2){ print "[EMAIL PROTECTED]: $_\n"; #-- only this get print out. } to make the long story short: Perl consider $s to be a simple scalar (and yes that's the official term) and whenever a simple scalar is put inside '<>', Perl assumes it's a file handle that you are trying to read from. otherwise, you can't even: open(my $file,'some.txt') || die; while(<$file>){ #-- doing glob or reading from $file? #-- code } close($file); it's reading from $file (the file handle) because $file is a considered to be a simple scalar. now if you were to change your script to look like: my $temp = '*997*'; print 'Deleted ' , unlink (<@{[$temp]}>) , ' files.\n'; it will work because that tells Perl the stuff inside '<>' is not a file handle so it should be handed to the glob function. > > The problem is that I have to read from a file and put the value from the > file into a variable. Although your "hard coded" example does work, it > doesn't work for a value read in from an external file and into a > variable. Any other ideas? I am all ears and out of ideas. > if you were really "all ears out", you should have tell us where all of your files live and how (and where) you execute your script. i still think your problem is largely related to Perl not able to find the files because you are running the script from a different directory. david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]