Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > issue with closedir

Reply
Thread Tools

issue with closedir

 
 
solaristar
Guest
Posts: n/a
 
      01-23-2010
i had this working with close(DIR); but im trying to do some best
practices code here and apparently closedir is more what i should be
using

here's the relevant code snippet


opendir(my $dh, $basedir) || die "can't open $basedir: $!\n";
my $suff_re = qr/\.[mcu]w\./;
my @servers = grep { !/^\./ && m/$suff_re/ } readdir($dh);
...
...
closedir($dh);


the error

closedir() attempted on invalid dirhandle $dh at ./foo20 line 48.
closedir() attempted on invalid dirhandle $dh at ./foo20 line 48.

line 48 is closedir($dh);

thoughts?

 
Reply With Quote
 
 
 
 
Uri Guttman
Guest
Posts: n/a
 
      01-23-2010
>>>>> "s" == solaristar <(E-Mail Removed)> writes:

s> i had this working with close(DIR); but im trying to do some best
s> practices code here and apparently closedir is more what i should be
s> using

s> here's the relevant code snippet


s> opendir(my $dh, $basedir) || die "can't open $basedir: $!\n";
s> my $suff_re = qr/\.[mcu]w\./;
s> my @servers = grep { !/^\./ && m/$suff_re/ } readdir($dh);
s> ...
s> ...
s> closedir($dh);


s> the error

s> closedir() attempted on invalid dirhandle $dh at ./foo20 line 48.
s> closedir() attempted on invalid dirhandle $dh at ./foo20 line 48.

s> line 48 is closedir($dh);

without seeing more code, it is hard to tell. the only clue is that you
are getting multiple errors. did $dh get modified somehow before this?
was it closed already before this? perldiag shows this error means you
are closing an already closed dirhandle.

uri

--
Uri Guttman ------ http://www.velocityreviews.com/forums/(E-Mail Removed) -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
 
Reply With Quote
 
 
 
 
solaristar
Guest
Posts: n/a
 
      01-23-2010
On Jan 23, 4:27*am, "Uri Guttman" <(E-Mail Removed)> wrote:
> >>>>> "s" == solaristar *<(E-Mail Removed)> writes:

>
> * s> i had this working with close(DIR); but im trying to do some best
> * s> practices code here and apparently closedir is more what i should be
> * s> using
>
> * s> here's the relevant code snippet
>
> * s> * * opendir(my $dh, $basedir) || die "can't open $basedir: $!\n";
> * s> * * my $suff_re = qr/\.[mcu]w\./;
> * s> * * my @servers = grep { !/^\./ && m/$suff_re/ } readdir($dh);
> * s> * * ...
> * s> * * ...
> * s> * * closedir($dh);
>
> * s> the error
>
> * s> closedir() attempted on invalid dirhandle $dh at ./foo20 line 48.
> * s> closedir() attempted on invalid dirhandle $dh at ./foo20 line 48.
>
> * s> line 48 is closedir($dh);
>
> without seeing more code, it is hard to tell. the only clue is that you
> are getting multiple errors. did $dh get modified somehow before this?
> was it closed already before this? perldiag shows this error means you
> are closing an already closed dirhandle.
>
> uri
>
> --
> Uri Guttman *------ *(E-Mail Removed) *-------- *http://www.sysarch.com--
> ----- *Perl Code Review , Architecture, Development, Training, Support ------
> --------- *Gourmet Hot Cocoa Mix *---- *http://bestfriendscocoa.com---------



Uri, thanks for the reply, i ended up realizing what i did wrong,
thats what i get for programming at 4:30am (without sleep)

the syntax was right i just had the closedir inside a loop which was
messing things up, i moved it up to be below the line above on my
snippet and works good


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it a hardware issue or a config issue or something else Scooty Cisco 0 06-14-2008 04:02 PM
Data Storage Issue (Basic Issue) Srini Java 11 06-01-2008 01:17 AM
Service Pack 2: login issue's and power management issue's ?!? Skybuck Flying Windows 64bit 0 04-07-2007 03:12 PM
inspiron 8200 video issue and hd issue the pez lover Computer Support 1 02-05-2007 02:44 AM
Major ActiveX Domain issue. NOT LOCAL PC ISSUE joe.valentine@gmail.com Computer Support 8 02-06-2006 09:03 PM



Advertisments