issue with closedir

Discussion in 'Perl Misc' started by solaristar, Jan 23, 2010.

  1. solaristar

    solaristar Guest

    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?
     
    solaristar, Jan 23, 2010
    #1
    1. Advertising

  2. solaristar

    Uri Guttman Guest

    >>>>> "s" == solaristar <> 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.sysarch.com --
    ----- Perl Code Review , Architecture, Development, Training, Support ------
    --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
     
    Uri Guttman, Jan 23, 2010
    #2
    1. Advertising

  3. solaristar

    solaristar Guest

    On Jan 23, 4:27 am, "Uri Guttman" <> wrote:
    > >>>>> "s" == solaristar  <> 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.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

    :)
     
    solaristar, Jan 23, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JohnFol
    Replies:
    0
    Views:
    1,352
    JohnFol
    Aug 6, 2003
  2. Satinderpal Singh

    AppDomain Issue...

    Satinderpal Singh, Oct 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    712
    Dan Ignatov
    Oct 27, 2003
  3. Catherine Jones

    rich text box issue

    Catherine Jones, Dec 11, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    742
    Robert Jacobson
    Dec 11, 2003
  4. AJ

    Datatype issue

    AJ, Jan 12, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    503
    Mattias Sjögren
    Jan 12, 2004
  5. Srini
    Replies:
    11
    Views:
    994
    Arne Vajhøj
    Jun 1, 2008
Loading...

Share This Page