Re: File test operator (race conditions)

2011-11-27 Thread Jim Gibson
At 5:21 AM +0100 11/28/11, timothy adigun wrote: > > From: Owen > > There is no race condition. > > And that code demo is correct Actually, there is in a multitasking environment. Please, check subtitle "File Locking" in perldoc perlopentut. masayoshi wrote: Before calling prin

Re: File test operator (race conditions)

2011-11-27 Thread timothy adigun
> > > From: Owen > > > > There is no race condition. > > > > And that code demo is correct > Actually, there is in a multitasking environment. Please, check subtitle "File Locking" in perldoc perlopentut. masayoshi wrote: > Before calling print method, the file might be deleted by another p

Re: File test operator (race conditions)

2011-11-27 Thread masayoshi
- Original Message - > From: Owen > > There is no race condition. > > And that code demo is correct > Before calling print method, the file might be deleted by another process So I reckoned when "File exists" appeared, the file might be deleted. >_>   --- masayoshi & Ayumi Kinoshita

Re: File test operator (race conditions)

2011-11-27 Thread Owen
> Hi,I am masayoshi. > I read the following article. > > http://perltraining.com.au/tips/2005-11-24.html > > > A lot of website use the following script to explain file test > operators, > But I reckon I should not write it for race conditions. > Is this right? > Thanks in advance. > > > #!/usr/bi

Re: File test failed!

2011-09-16 Thread Magnus Woldrich
On 2011-09-16 17:53, y...@eisoo.com wrote: I want to test if a file exists or it is a link or not You test for a regular file with -f. You test for existance with -e. You test for symbolic links with -l. See perldoc -f -x for more information. -- │ Magnus Woldrich │ m...@japh.se │ http:/

Re: File test failed!

2011-09-16 Thread Shlomi Fish
Hi YYQ, On Fri, 16 Sep 2011 17:53:25 +0800 "y...@eisoo.com" wrote: > Hi, All: > > I want to test if a file exists or it is a link or not, the code is: > #!/usr/bin/perl -w > > use strict; > use File::Basename; > use File::stat; > use Fcntl ':mode'; > > my $elfobj = $ARGV[0]; > > sub str

Re: file test

2006-01-24 Thread Adriano Rodrigues Ferreira
The operator -e (like the other -X operators) takes a filename or file handle, and not a glob or file name pattern with wildcards. As others pointed, you use the builtin glob to do the expansion (either explicitly or via <>). Then you might say: for (glob 'file*') { print "true\n" if -e $_;

Re: file test

2006-01-24 Thread Adriano Rodrigues Ferreira
The operator -e (like the other -X operators) takes a filename or file handle, and not a glob or file name pattern with wildcards. As others pointed, you use the builtin glob to do the expansion (either explicitly or via <>). Then you might say: for (glob 'file*') { print "true\n" if -e $_;

Re: file test

2006-01-24 Thread Bob Showalter
hien wrote: dear all, i am trying to check if there are any files named file* (e.g. file_001.txt file1.doc) in my directory. if( -e "file*" ) { print("true\n"); } # this doesn't work else { print("false\n"); } if( -e "m/^file/" ) { print("true\n"); } # this doesn't work either else { print(

Re: file test

2006-01-24 Thread Gerard Robin
On Mon, Jan 23, 2006 at 09:47:40PM +0100, hien wrote: > i am trying to check if there are any files named file* (e.g. > file_001.txt file1.doc) in my directory. #!/usr/bin/perl use warnings; use strict; my $i = 0; while () { if (-e $_) { print "$_ exists\n"; $i++; } } print "there are $i f

Re: file test

2006-01-23 Thread Chris Devers
On Mon, 23 Jan 2006, hien wrote: > i am trying to check if there are any files named file* (e.g. > file_001.txt file1.doc) in my directory. perldoc -f glob -- Chris Devers DO NOT LEAVE IT IS NOT REAL -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTEC

Re: File Test Question

2005-11-30 Thread jm
according to Programming Perl (p. 98)... -w = file is writable by effective uid/gid -s = file has nonzero size (returns size) -w only tells if the file's permissions allow it to be written to, has nothing to do with whether or not it already has data. save the return value of -s and check that v

RE: File Test Question

2005-11-30 Thread Timothy Johnson
I don't think the -x tests mean what you think they mean. >From "perldoc -f -x": -r File is readable by effective uid/gid. -w File is writable by effective uid/gid. -x File is executable by effective uid/gid. -o File is owned by effective uid. -R File is

Re: File Test Question

2005-11-30 Thread Wiggins d'Anconia
Dave Adams wrote: > *My Code:* > > my $logfile = "logfile_with_content"; > if (-w $logfile) { > print ("True - file exists but empty"); > } > if (-s $logfile) { > print ("True - file exist and has content"); > } > > *My Output:* > > True - file exists but empty True - file exist and has

Re: file test doesn't seem to be working

2002-02-05 Thread John Mooney
>>> "Brett W. McCoy" <[EMAIL PROTECTED]> 2/5/2002 10:35:48 AM >>> > >That's just more a matter of style -- I get the willies when subroutines >modify global values invisibly. Great advice. thanks -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: file test doesn't seem to be working

2002-02-05 Thread Brett W. McCoy
On Tue, 5 Feb 2002, John Mooney wrote: > Actually, it is not an incorrect way I believe, so much as he is using > slightly incorrect syntax. From the Nutshell ... I really meant 'incorrect' in its usage, not the syntax -- he was using it in a void context. > ... I think the key is that he was

Re: file test doesn't seem to be working

2002-02-05 Thread John Mooney
>>> "Brett W. McCoy" <[EMAIL PROTECTED]> 2/4/2002 9:28:42 PM >>> >>On Mon, 4 Feb 2002, david wright wrote: >> >> i can't use the ternary operator like this? (damn waste if not) thanks. >> >> foreach $dup (@array){ >> (-d $dup) ? print "yes: $dup \n": print "no: $dup \n"; >> ) > >Yes, that i

Re: file test doesn't seem to be working

2002-02-04 Thread Jeff 'japhy' Pinyan
On Feb 4, Brett W. McCoy said: >On Mon, 4 Feb 2002, david wright wrote: > >> i can't use the ternary operator like this? (damn waste if not) thanks. >> >> foreach $dup (@array){ >> (-d $dup) ? print "yes: $dup \n": print "no: $dup \n"; >> ) > >Yes, that is an incorrect way to use the ?: op

Re: file test doesn't seem to be working

2002-02-04 Thread Brett W. McCoy
On Mon, 4 Feb 2002, david wright wrote: > i can't use the ternary operator like this? (damn waste if not) thanks. > > foreach $dup (@array){ > (-d $dup) ? print "yes: $dup \n": print "no: $dup \n"; > ) Yes, that is an incorrect way to use the ?: operator -- the operataor is handed an expr

Re: file test doesn't seem to be working

2002-02-04 Thread John W. Krahn
David Wright wrote: > > i am sending @array a directory (i.e. example /usr/dw5) which contains a > lot of files and folders (directories). > (i have already checked the value of @array and $dup and they are as > desired.) What i want to accomplish is: print yes, "$dup (file name)" if > it's a dir

Re: file test doesn't seem to be working

2002-02-04 Thread david wright
On Monday, February 4, 2002, at 07:26 PM, Jeff 'japhy' Pinyan wrote: > On Feb 4, david wright said: > >> i am sending @array a directory (i.e. example /usr/dw5) which >> contains a >> lot of files and folders (directories). > > Be warned that readdir() returns NAMES, not PATHS. > > opendir DI

Re: file test doesn't seem to be working

2002-02-04 Thread Jeff 'japhy' Pinyan
On Feb 4, david wright said: >i am sending @array a directory (i.e. example /usr/dw5) which contains a >lot of files and folders (directories). Be warned that readdir() returns NAMES, not PATHS. opendir DIR, "/some/dir"; @files = readdir DIR; closedir DIR; @files will contain (".", ".."

Re: file test doesn't seem to be working

2002-02-04 Thread david wright
On Monday, February 4, 2002, at 06:57 PM, Timothy Johnson wrote: > > Did you chdir to the directory? Otherwise your script might be > checking the > wrong directory. > > opendir(DIR,"/mydir"); > @array = readdir(DIR); > chdir "/mydir"; > foreach $dup (@array){ > (-d $dup) ? print "yes: $d

RE: file test doesn't seem to be working

2002-02-04 Thread Timothy Johnson
Did you chdir to the directory? Otherwise your script might be checking the wrong directory. opendir(DIR,"/mydir"); @array = readdir(DIR); chdir "/mydir"; foreach $dup (@array){ (-d $dup) ? print "yes: $dup \n": print "no: $dup \n"; } -Original Message- From: david wright [mailt

Re: file test

2001-11-30 Thread Luke Bakken
Actually `dir /B` won't produce anything since dir isn't a real coomand - it's a shell builtin. This may help: c:\>perl -e"for (<*>) { print $_, qq(\n) if(! -x $_ && -B $_ ) }" Luke On Thu, 29 Nov 2001, Carl Rogers wrote: > At 08:09 PM 11/29/2001 +, [EMAIL PROTECTED] wrote: > >How can I d

Re: file test

2001-11-29 Thread Brett W. McCoy
On Thu, 29 Nov 2001, Carl Rogers wrote: > At 08:09 PM 11/29/2001 +, [EMAIL PROTECTED] wrote: > >How can I do more then one file test for file? > > > >I'm trying to test a list of files to see if they're a binary file, that > >isn't executable. > > If I understand correctly, you want to check

Re: file test

2001-11-29 Thread Carl Rogers
At 08:09 PM 11/29/2001 +, [EMAIL PROTECTED] wrote: >How can I do more then one file test for file? > >I'm trying to test a list of files to see if they're a binary file, that >isn't executable. If I understand correctly, you want to check all files in a certain directory to see if they AREN

Re: file test fails 2nd time thru

2001-10-30 Thread Andrea Holstein
Hanson wrote: > > I have a fairly large perl script which optionally runs > through a few subroutines doing similar things to different > files. Sorry I can't be more detailed. > My problem is this: within these subroutines are file tests: > > (-e $File) or die > > type of stuff. > > The first