RE: readdir() question

2009-05-28 Thread Ajay Kumar
Sent: Monday, May 25, 2009 4:30 AM To: beginners@perl.org Subject: Re: readdir() question On Mon May 25 2009 @ 4:34, sanket vaidya wrote: > Hi all, > > > > Kindly look at the code below: > > > > use warnings; > > use strict; > > opendir(DIR, "D:\

Re: readdir() question

2009-05-25 Thread Telemachus
On Mon May 25 2009 @ 4:34, sanket vaidya wrote: > Hi all, > > > > Kindly look at the code below: > > > > use warnings; > > use strict; > > opendir(DIR, "D:\\test") || die "can't opendir: $!"; > > my @dots = readdir(DIR); > > print map{"$_.\n"}...@dots; > > > > .. > > ... > > Tes

Re: readdir formulated badly? gives wrong count

2007-12-03 Thread reader
Rob Dixon <[EMAIL PROTECTED]> writes: > [EMAIL PROTECTED] wrote: >> "Jeff Pang" <[EMAIL PROTECTED]> writes: >> >>> On Dec 3, 2007 10:12 AM, <[EMAIL PROTECTED]> wrote: >>> #!/usr/local/bin/perl -w use strict; use warnings; my @ar = (); for(@ar){ pr

Re: readdir formulated badly? gives wrong count

2007-12-03 Thread Matthew Whipple
[EMAIL PROTECTED] wrote: > "Jeff Pang" <[EMAIL PROTECTED]> writes: > > >> On Dec 3, 2007 12:51 PM, <[EMAIL PROTECTED]> wrote: >> >>> "Jeff Pang" <[EMAIL PROTECTED]> writes: >>> mhh? It won't print a newline, it even won't print anything. b/c @ar is empty, for(...) doesn't

Re: readdir formulated badly? gives wrong count

2007-12-03 Thread Rob Dixon
[EMAIL PROTECTED] wrote: "Jeff Pang" <[EMAIL PROTECTED]> writes: On Dec 3, 2007 10:12 AM, <[EMAIL PROTECTED]> wrote: #!/usr/local/bin/perl -w use strict; use warnings; my @ar = (); for(@ar){ print "$_\n"; } But running that script just does nothing but gleefully print a ne

Re: readdir formulated badly? gives wrong count

2007-12-02 Thread reader
"Jeff Pang" <[EMAIL PROTECTED]> writes: > On Dec 3, 2007 12:51 PM, <[EMAIL PROTECTED]> wrote: >> "Jeff Pang" <[EMAIL PROTECTED]> writes: >> > mhh? It won't print a newline, it even won't print anything. >> > b/c @ar is empty, for(...) doesn't go into it, 'print' won't be happened. >> >> Yeah you

Re: readdir formulated badly? gives wrong count

2007-12-02 Thread Jeff Pang
On Dec 3, 2007 12:51 PM, <[EMAIL PROTECTED]> wrote: > "Jeff Pang" <[EMAIL PROTECTED]> writes: > > mhh? It won't print a newline, it even won't print anything. > > b/c @ar is empty, for(...) doesn't go into it, 'print' won't be happened. > > Yeah your right... (what was I thinking...) but my point

Re: readdir formulated badly? gives wrong count

2007-12-02 Thread reader
"Jeff Pang" <[EMAIL PROTECTED]> writes: > On Dec 3, 2007 10:12 AM, <[EMAIL PROTECTED]> wrote: > >> >> #!/usr/local/bin/perl -w >> use strict; >> use warnings; >> my @ar = (); >> >> for(@ar){ >> print "$_\n"; >> } >> >> But running that script just does nothing but gleefully print

Re: readdir formulated badly? gives wrong count

2007-12-02 Thread Jeff Pang
On Dec 3, 2007 10:12 AM, <[EMAIL PROTECTED]> wrote: > > #!/usr/local/bin/perl -w > use strict; > use warnings; > my @ar = (); > > for(@ar){ > print "$_\n"; > } > > But running that script just does nothing but gleefully print a > newline. mhh? It won't print a newline, it even

Re: readdir formulated badly? gives wrong count

2007-12-02 Thread reader
Harry wrote: >> @DirContent = grep { /^[0-9]/ } readdir(DIR); >> if ($DirContent[0]){ J. Krahn replied: > Again, you are doing boolean tests on the contents of array elements > when you should really be testing the array itself. What if > $DirContent[0] contained the file name "0"? > > if ( @D

Re: readdir formulated badly? gives wrong count

2007-12-02 Thread kens
Been away from the computer for a while, and I see that some of your questions have been addressed, but I will add a few comments. On Dec 1, 10:44 am, [EMAIL PROTECTED] wrote: > Thanks for taking time to respong and go clear thru the script bit by > bit. > > kens <[EMAIL PROTECTED]> writes: > > [.

Re: readdir formulated badly? gives wrong count

2007-12-02 Thread Matthew Whipple
Rob Dixon wrote: > Matthew Whipple wrote: >> >> The for loop won't execute if it has nothing through which to >> iterate. On my system the for won't execute with an empty list, but >> will once >> when the array is undefined. Changing the above to 'if >> (defined(@DirContent)) {' would be a bit cl

Re: readdir formulated badly? gives wrong count

2007-12-02 Thread Matthew Whipple
Rob Dixon wrote: > Matthew Whipple wrote: >> >> The for loop won't execute if it has nothing through which to >> iterate. On my system the for won't execute with an empty list, but >> will once >> when the array is undefined. Changing the above to 'if >> (defined(@DirContent)) {' would be a bit cl

Re: readdir formulated badly? gives wrong count

2007-12-01 Thread reader
John W.Krahn <[EMAIL PROTECTED]> writes: > On Friday 30 November 2007 22:47, [EMAIL PROTECTED] wrote: > > Sorry for taking so long to reply but I was mulling it over while > eating cold pizza and watching NCAAF. You don't specify the exact file > names so I will assume that they match the patte

Re: readdir formulated badly? gives wrong count

2007-12-01 Thread John W . Krahn
On Friday 30 November 2007 22:47, [EMAIL PROTECTED] wrote: Sorry for taking so long to reply but I was mulling it over while eating cold pizza and watching NCAAF. You don't specify the exact file names so I will assume that they match the pattern /\A\d+\z/ which is what you use when you copy t

Re: readdir formulated badly? gives wrong count

2007-12-01 Thread reader
"Tom Phoenix" <[EMAIL PROTECTED]> writes: > On 12/1/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> John W.Krahn <[EMAIL PROTECTED]> writes: >> > perldoc -f rewinddir >> >> Is that faster or anything than using a second opendir? > > Is it faster? What did you find out when you benchmarked both

Re: readdir formulated badly? gives wrong count

2007-12-01 Thread Rob Dixon
Matthew Whipple wrote: The for loop won't execute if it has nothing through which to iterate. On my system the for won't execute with an empty list, but will once when the array is undefined. Changing the above to 'if (defined(@DirContent)) {' would be a bit clearer. Now what would you mean

Re: readdir formulated badly? gives wrong count

2007-12-01 Thread Tom Phoenix
On 12/1/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > John W.Krahn <[EMAIL PROTECTED]> writes: > > perldoc -f rewinddir > > Is that faster or anything than using a second opendir? Is it faster? What did you find out when you benchmarked both ways of coding it? In any case, when you're readin

Re: readdir formulated badly? gives wrong count

2007-12-01 Thread John W . Krahn
On Saturday 01 December 2007 17:25, Matthew Whipple wrote: > > [EMAIL PROTECTED] wrote: > > > > kens <[EMAIL PROTECTED]> writes: > > > >> This test add nothing. The for loop will fail if there is no > >> content > >> > >>> if ($DirContent[0]){ > > > > Checking to make sure there are in fact numbere

Re: readdir formulated badly? gives wrong count

2007-12-01 Thread John W . Krahn
On Saturday 01 December 2007 16:20, [EMAIL PROTECTED] wrote: > > John W.Krahn <[EMAIL PROTECTED]> writes: > > > > perldoc -f rewinddir > > Is that faster or anything than using a second opendir? I don't know, you'd have to use Benchmark to test it. (In my defense you only asked if it was possibl

Re: readdir formulated badly? gives wrong count

2007-12-01 Thread Matthew Whipple
[EMAIL PROTECTED] wrote: > Thanks for taking time to respong and go clear thru the script bit by > bit. > > kens <[EMAIL PROTECTED]> writes: > > [...] > > >> # The following lines are your friend >> use strict; >> use warnings; >> > > I've seen that before but didn't understand why. > > T

Re: readdir formulated badly? gives wrong count

2007-12-01 Thread reader
John W.Krahn <[EMAIL PROTECTED]> writes: > perldoc -f rewinddir Is that faster or anything than using a second opendir? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: readdir formulated badly? gives wrong count

2007-12-01 Thread John W . Krahn
On Saturday 01 December 2007 08:30, [EMAIL PROTECTED] wrote: > [EMAIL PROTECTED] writes: > >> The main problem, I believe, is that you are using a stale > >> directory handle. closedir (in main) and opendir here. > > > > Ha... and that was the problem... turns out it doesn't need to be > > moved.

Re: readdir formulated badly? gives wrong count

2007-12-01 Thread reader
[EMAIL PROTECTED] writes: >> The main problem, I believe, is that you are using a stale directory >> handle. closedir (in main) and opendir here. > > Ha... and that was the problem... turns out it doesn't need to be > moved. Once the typeo is corrected to closedir(DIR); it works, with > no reopen

Re: readdir formulated badly? gives wrong count

2007-12-01 Thread reader
Thanks for taking time to respong and go clear thru the script bit by bit. kens <[EMAIL PROTECTED]> writes: [...] > # The following lines are your friend > use strict; > use warnings; I've seen that before but didn't understand why. The `warnings' part is clear enough but doesn't the -w flag

Re: readdir formulated badly? gives wrong count

2007-12-01 Thread kens
On Dec 1, 1:47 am, [EMAIL PROTECTED] wrote: > Sorry to plop so much shabby code up here but I think I've stared at > this a little too long and am now incapable of catching my error. > > This started out as just a helper script to help solve this problem: > > Needing to cp files with number names f

Re: readdir question

2005-09-30 Thread Jay Savage
On 9/30/05, Gergely Buday <[EMAIL PROTECTED]> wrote: > Hi, > > this is a working code snippet: > > opendir (DIR, $dir) || die "Open failed: $!\n"; > > $\ = "\n"; > while ($_ = readdir(DIR)) { print; }; > > But when I try to use > > while (readdir(DIR)) ... > > my script writes only empty lines. It

RE: readdir question

2005-09-30 Thread Thomas Bätzler
Hi, Gergely Buday <[EMAIL PROTECTED]> wrote: > this is a working code snippet: > > opendir (DIR, $dir) || die "Open failed: $!\n"; > > $\ = "\n"; > while ($_ = readdir(DIR)) { print; }; > > But when I try to use > > while (readdir(DIR)) ... > > my script writes only empty lines. It seems that

Re: readdir unlink any symlinks

2003-07-07 Thread Harry Putnam
Steve Grazzini <[EMAIL PROTECTED]> writes: > Ah, okay. But you'll need to make that into a real loop. > > use File::Spec::Functions; > ... > > foreach (readdir(DIR)) { > my $target = catfile($mnsd, $_); > if (-l $target) { >unlink $target or warn "unli

RE: readdir unlink any symlinks

2003-07-07 Thread Tim Johnson
(BIt doesn't look like you are setting the $_ variable anywhere. Maybe if you (Bput this line in after the opendir and before the first bracket: (B (Bforeach(readdir(DIR)) (B (Band closed the bracket (B (B-Original Message- (BFrom: Harry Putnam [mailto:[EMAIL PROTECTED] (BSent:

Re: readdir unlink any symlinks

2003-07-07 Thread Steve Grazzini
On Mon, Jul 07, 2003 at 12:59:27PM -0700, Harry Putnam wrote: > I'm pretty sure there is a nifty thrifty way to do this rather than > tying myself in knots like this: > > I want to unlink and symlinks that might be in a specific directory. > A snipped from hack-a-thonic script: > > my $mnsd = "/t

RE: Readdir

2002-12-24 Thread Paul Kraus
disregard I had a sneaky last statement messing me up. > -Original Message- > From: Paul Kraus [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, December 24, 2002 9:11 AM > To: 'Perl' > Subject: Readdir > > > Correct me if I am wrong but this should return a directory listing? > > use consta

Re: Readdir to array

2002-12-13 Thread Mystik Gotan
I'd be using: #!/usr/bin/perl -w $dir = "/backup"; opendir BACKUPDIR, $dir or die "Cannot open $dir!"; foreach (readdir BACKUPDIR){ unless ($_ eq "." or $_ eq ".."){ #print "$_"; push (@dirs,$_); } foreach (@dirs) { print "$_\n"; } } -- Bob Erinkveld (Webmaster Insa

RE: Readdir to array

2002-12-13 Thread Paul Kraus
doht! Thanks! > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] > Sent: Friday, December 13, 2002 10:13 AM > To: Paul Kraus; Perl > Subject: RE: Readdir to array > > > You are foreah'ing in your foreach. So it is printing the >

RE: Readdir to array

2002-12-13 Thread wiggins
You are foreah'ing in your foreach. So it is printing the contents of the array foreach of the files in the directory... http://danconia.org On Fri, 13 Dec 2002 09:56:19 -0500, "Paul Kraus" <[EMAIL PROTECTED]> wrote: > for some reason the outpu

Re: readdir

2001-07-27 Thread Maxim Berlin
Hello COLLINEAU, Friday, July 27, 2001, COLLINEAU Franck FTRD/DMI/TAM <[EMAIL PROTECTED]> wrote: CFFDT> I have a problem with my code: CFFDT> #!/usr/bin/perl -w CFFDT> opendir (LMI,"lmi") || die "impossible d'ouvrir lmi: $!"; CFFDT> $chaine="BEGIN PAPIER"; CFFDT> while($fichier=readdir LMI) C