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:\
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
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
[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
[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
"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
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
"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
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
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
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:
>
> [.
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
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
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
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
"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
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
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
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
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
[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
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/
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.
[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
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
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
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
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
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
(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:
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
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
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
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
>
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
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
36 matches
Mail list logo