Ask a Question related to PERL Beginners, Design and Development.
-
Re: Still need unlink help!! God help me. - Revisited
<20030808202717051099.GyazMail.neuroball@usa.net >
<YW50aWdvbmU=.45ab06a65368617cf57750f9f6311818@106 0402929.cotse.net>
<20030808223332494596.GyazMail.neuroball@usa.net >
<YW50aWdvbmU=.b5f5cdebb1363e9b5422d22aeff7ce2e@106 0449982.cotse.net>
<BAY1-DAV43JqxyBidAz000261ff@hotmail.com>
X-Priority: 3
Importance: Normal
X-MSMail-Priority: Normal
Cc: <dunc339cowley@hotmail.com>
Reply-To: [email]perlwannabe@antigone.cotse.net[/email]
X-Mailer: [url]www.cotse.net[/url]
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Approved: [email]news@nntp.perl.org[/email]
From: [email]perlwannabe@antigone.cotse.net[/email] (Perlwannabe)
Lines: 20
Xref: intern1.nntp.aus1.giganews.com perl.beginners:123
Yes, it does. But it does not work when reading from a variable.> This works - i've tried it...
>
> print 'Deleted ' , unlink (<*997*>) , ' files.\n';
>
> good luck
> Duncan
my $temp = '*997*';
print 'Deleted ' , unlink (<$temp>) , ' files.\n';
This very simple variation of your example does not work.
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.
Guest
-
Unlink and variables
Hello, I created a form to upload files. The formfield contents are stored as records in an Ascii file "data.dat"; for reasons I am not using a... -
Still need unlink help!! God help me.
Still having problem with unlink. My original problem began with deleting files from a list. I seem to have fixed the problem reading the list but... -
Help with Unlink please
> Steve Grazzini wrote at Wed, 06 Aug 2003 23:38:00 -0400: Neither of these worked. I am beginning to think that there is something wrong with... -
problem using unlink()
Hi, I have a problem using unlink(); on a system using FreeBSD and Apache... where my local system using Windows and Apache experiences no... -
unlink() in a loop???
I have a script that allows users to upload pics and enter personal info into Database (not pictures i only store filename in db). The form passes... -
David #2
Re: Still need unlink help!! God help me. - Revisited
"Perlwannabe" <perlwannabe@antigone.cotse.net> wrote in message
news:YW50aWdvbmU=.bca259c206ff92e930679e970dbc8699 @1060478346.cotse.net...the reason why YOUR version won't work is because when Perl sees '<$temp>',>> > 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.
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 "\@files1: $_\n";
}
for(@files2){
print "\@files2: $_\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.
if you were really "all ears out", you should have tell us where all of your>
> 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.
>
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
David Guest



Reply With Quote

