readline() on closed fielhandle?

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default readline() on closed fielhandle?

    Hello,

    Cannot see what is wrong with following - I get following error
    message "readline() on closed fielhandle at line ++" - help please!

    Cheers

    Geoff

    use warnings;
    use strict;

    use File::Find;

    open (OUT, ">>out");

    my $dir = 'c:/atemp1/test';

    find ( sub {

    open (IN, "$_");

    ++ while (defined(my $line=<IN>)) {

    if ($line =~ /Mailto:(.*?)"/i) {
    print OUT ("$1");
    }

    }

    }, $dir);

    close (OUT);
    close (IN);
    Geoff Cox Guest

  2. Similar Questions and Discussions

    1. How to glue Net::Server and readline ?
      Hi, I'm trying to glue together an console application with readline extension (=I can edit the line befor I enter it). How can I make it work with...
    2. Readline API doc?
      I'm looking for the info on how to define/modify/basically interact with readline keymaps from Ruby. Anyone have any pointers? -Mark
    3. readline.dll missing in 1.8 final?
      Chris Morris wrote: .... Hi, WATANABE, Hirofumi maintains a very nice collection of Ruby relevant Windows ports (including readline and...
    4. readline.dll problem
      I am using U.Nakamura's mswin32 Ruby 1.8.0. When I installed it and tried to use irb, I got an error "readline.dll not found". (Irb works fine...
    5. irb --readline
      Hi, In message "irb --readline" on 03/07/25, Wybo Dekker <wybo@servalys.nl> writes: |When I try to have readline support with: | |irb...
  3. #2

    Default Re: readline() on closed fielhandle?

    In article <uab6mvob4hsaigjvqjrhutudhjs4kjh4rk@4ax.com>,
    Geoff Cox <geoff.cox@blueyonder.co.uk> wrote:
    > Cannot see what is wrong with following - I get following error
    > message "readline() on closed fielhandle at line ++" - help please!
    >
    > []
    >
    > open (IN, "$_");
    You don't even know if the open succeeded. **Always** check to be sure
    open succeeds:

    open IN, $_ or die "can't open $_: $!\n";

    (Oh, and you don't need the quotes around $_.)
    > print OUT ("$1");
    Don't need the quotes around $1, either.
    --
    Kevin Michael Vail | Dogbert: That's circular reasoning.
    [email]kevin@vaildc.net[/email] | Dilbert: I prefer to think of it as no loose ends.
    [url]http://www.vaildc.net/kevin/[/url]
    Kevin Michael Vail Guest

  4. #3

    Default Re: readline() on closed fielhandle?

    In article <uab6mvob4hsaigjvqjrhutudhjs4kjh4rk@4ax.com>,
    Geoff Cox <geoff.cox@blueyonder.co.uk> wrote:
    > Hello,
    >
    > Cannot see what is wrong with following - I get following error
    > message "readline() on closed fielhandle at line ++" - help please!
    >
    > Cheers
    >
    > Geoff
    >
    > use warnings;
    > use strict;
    >
    > use File::Find;
    >
    > open (OUT, ">>out");
    >
    > my $dir = 'c:/atemp1/test';
    >
    > find ( sub {
    >
    > open (IN, "$_");
    open (IN, "$_") or return;
    >
    > ++ while (defined(my $line=<IN>)) {
    >
    [snip]

    hth-

    --
    Michael Budash
    Michael Budash Guest

  5. #4

    Default Re: readline() on closed fielhandle?

    On Sat, 13 Sep 2003 11:07:59 -0400, Kevin Michael Vail
    <kevin@vaildc.net> wrote:
    >In article <uab6mvob4hsaigjvqjrhutudhjs4kjh4rk@4ax.com>,
    > Geoff Cox <geoff.cox@blueyonder.co.uk> wrote:
    >
    >> Cannot see what is wrong with following - I get following error
    >> message "readline() on closed fielhandle at line ++" - help please!
    >>
    >> []
    >>
    >> open (IN, "$_");
    >
    >You don't even know if the open succeeded. **Always** check to be sure
    >open succeeds:
    >
    >open IN, $_ or die "can't open $_: $!\n";
    Kevin,

    This has got me confused ! If I use the check for opening the file I
    get error message "failed in open(): Permission denied at line 8" and
    nothing goes into the file called out ...

    If I use line 7 instead, I get error message "readline() on closed
    filehandle IN at line 9" - but the email addresses are put into the
    file
    called out ..?? What am I missing here?

    Geoff


    1 use warnings;
    2 use strict;
    3 use File::Find;
    4 open (OUT, ">>out");
    5 my $dir = 'c:/atemp1/test';
    6 find ( sub {
    7 open (IN, "$_");
    8 # open(IN, $_) or die "Failed in open(): $!";
    9 while (defined(my $line=<IN>)) {
    10 if ($line =~ /Mailto:(.*?)"/i) {
    11 print OUT ("$1 \n");
    12 }
    13 }
    14 }, $dir);
    15 close (OUT);
    16 close (IN);

    >
    >(Oh, and you don't need the quotes around $_.)
    >
    >> print OUT ("$1");
    >
    >Don't need the quotes around $1, either.
    Geoff Cox Guest

  6. #5

    Default Re: readline() on closed fielhandle?

    Geoff Cox wrote:
    > On Sat, 13 Sep 2003 11:07:59 -0400, Kevin Michael Vail
    > <kevin@vaildc.net> wrote:
    >
    >
    >>In article <uab6mvob4hsaigjvqjrhutudhjs4kjh4rk@4ax.com>,
    >>Geoff Cox <geoff.cox@blueyonder.co.uk> wrote:
    >>
    >>
    >>>Cannot see what is wrong with following - I get following error
    >>>message "readline() on closed fielhandle at line ++" - help please!
    >>>
    >>>[]
    >>>
    >>>open (IN, "$_");
    >>>
    >>You don't even know if the open succeeded. **Always** check to be sure
    >>open succeeds:
    >>
    >>open IN, $_ or die "can't open $_: $!\n";
    >>
    >
    > Kevin,
    >
    > This has got me confused ! If I use the check for opening the file I
    > get error message "failed in open(): Permission denied at line 8" and
    > nothing goes into the file called out ...
    >
    > If I use line 7 instead, I get error message "readline() on closed
    > filehandle IN at line 9" - but the email addresses are put into the
    > file
    > called out ..?? What am I missing here?

    As the sub code reference argument to File::Find's find function, note
    that your sub (and your open statement) is being executed many times,
    once for each file (but your close statement isn't -- but that doesn't
    matter, since open() will first close the filehandle if it is still
    open). Apparently somewhere down that list of files you have a file
    with permissions set so the user you are running this under cannot read
    that file. At that point your open fails with your permission denied
    error, and you choose to either die or ignore that fact, depending upon
    whether you put the "or die" in. When you told it to die on error, it
    did. Maybe you want to just "or return" on error and ignore that file.
    You will probably note that only some of your email addresses are put
    into the file called out, and that it either skips those files or
    terminates when it gets to the first file with the bad permissions
    anyway. I'm not sure if the readline() error is a warning or a fatal
    error -- I'd guess it is merely a warning, and that consequently your
    code is essentially skipping your bad-permission file(s) when you omit
    the "or die" on the open.

    >
    > Geoff
    >
    >
    > 1 use warnings;
    > 2 use strict;
    > 3 use File::Find;
    > 4 open (OUT, ">>out");
    > 5 my $dir = 'c:/atemp1/test';
    > 6 find ( sub {
    > 7 open (IN, "$_");
    > 8 # open(IN, $_) or die "Failed in open(): $!";
    > 9 while (defined(my $line=<IN>)) {
    > 10 if ($line =~ /Mailto:(.*?)"/i) {
    > 11 print OUT ("$1 \n");
    > 12 }
    > 13 }
    > 14 }, $dir);
    > 15 close (OUT);
    > 16 close (IN);
    ....

    --
    Bob Walton

    Bob Walton Guest

  7. #6

    Default Re: readline() on closed fielhandle?

    On Sat, 13 Sep 2003 19:29:13 GMT, Bob Walton
    <bwalton@rochester.rr.com> wrote:
    >Geoff Cox wrote:
    >
    >> On Sat, 13 Sep 2003 11:07:59 -0400, Kevin Michael Vail
    >> <kevin@vaildc.net> wrote:
    >>
    >>
    >>>In article <uab6mvob4hsaigjvqjrhutudhjs4kjh4rk@4ax.com>,
    >>>Geoff Cox <geoff.cox@blueyonder.co.uk> wrote:
    >>>
    >>>
    >>>>Cannot see what is wrong with following - I get following error
    >>>>message "readline() on closed fielhandle at line ++" - help please!
    >>>>
    >>>>[]
    >>>>
    >>>>open (IN, "$_");
    >>>>
    >>>You don't even know if the open succeeded. **Always** check to be sure
    >>>open succeeds:
    >>>
    >>>open IN, $_ or die "can't open $_: $!\n";
    >>>
    >>
    >> Kevin,
    >>
    >> This has got me confused ! If I use the check for opening the file I
    >> get error message "failed in open(): Permission denied at line 8" and
    >> nothing goes into the file called out ...
    >>
    >> If I use line 7 instead, I get error message "readline() on closed
    >> filehandle IN at line 9" - but the email addresses are put into the
    >> file
    >> called out ..?? What am I missing here?
    >
    >
    >As the sub code reference argument to File::Find's find function, note
    >that your sub (and your open statement) is being executed many times,
    >once for each file (but your close statement isn't -- but that doesn't
    >matter, since open() will first close the filehandle if it is still
    >open). Apparently somewhere down that list of files you have a file
    >with permissions set so the user you are running this under cannot read
    >that file. At that point your open fails with your permission denied
    Bob,

    this is odd as I am using Windows 98(SE) and have checked that all
    files have only the A atribute .. ?
    >error, and you choose to either die or ignore that fact, depending upon
    >whether you put the "or die" in. When you told it to die on error, it
    >did. Maybe you want to just "or return" on error and ignore that file.
    with "or return" the code runs without error message and the email
    addresses are extracted ..

    Cheers

    Geoff
    > You will probably note that only some of your email addresses are put
    >into the file called out, and that it either skips those files or
    >terminates when it gets to the first file with the bad permissions
    >anyway. I'm not sure if the readline() error is a warning or a fatal
    >error -- I'd guess it is merely a warning, and that consequently your
    >code is essentially skipping your bad-permission file(s) when you omit
    >the "or die" on the open.
    >
    >
    >>
    >> Geoff
    >>
    >>
    >> 1 use warnings;
    >> 2 use strict;
    >> 3 use File::Find;
    >> 4 open (OUT, ">>out");
    >> 5 my $dir = 'c:/atemp1/test';
    >> 6 find ( sub {
    >> 7 open (IN, "$_");
    >> 8 # open(IN, $_) or die "Failed in open(): $!";
    >> 9 while (defined(my $line=<IN>)) {
    >> 10 if ($line =~ /Mailto:(.*?)"/i) {
    >> 11 print OUT ("$1 \n");
    >> 12 }
    >> 13 }
    >> 14 }, $dir);
    >> 15 close (OUT);
    >> 16 close (IN);
    >...
    Geoff Cox Guest

  8. #7

    Default Re: readline() on closed fielhandle?

    Geoff Cox <geoff.cox@blueyonder.co.uk> wrote:
    > 1 use warnings;
    > 2 use strict;
    > 3 use File::Find;
    > 4 open (OUT, ">>out");
    > 5 my $dir = 'c:/atemp1/test';
    > 6 find ( sub {
    > 7 open (IN, "$_");
    > 8 # open(IN, $_) or die "Failed in open(): $!";
    > 9 while (defined(my $line=<IN>)) {
    > 10 if ($line =~ /Mailto:(.*?)"/i) {
    > 11 print OUT ("$1 \n");
    > 12 }
    > 13 }
    > 14 }, $dir);
    > 15 close (OUT);
    > 16 close (IN);

    Please spend the time to format your code sensibly.

    Many people will just move on to help someone else who has
    done what they can to make it easier to give an answer.


    --
    Tad McClellan SGML consulting
    [email]tadmc@augustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

  9. #8

    Default Re: readline() on closed fielhandle?

    Geoff Cox <geoff.cox@blueyonder.co.uk> wrote:
    : Bob Walton <bwalton@rochester.rr.com> wrote:
    : >Geoff Cox wrote:
    : >> Kevin Michael Vail <kevin@vaildc.net> wrote:

    : >>>open IN, $_ or die "can't open $_: $!\n";

    : >> This has got me confused ! If I use the check for opening the file I
    : >> get error message "failed in open(): Permission denied at line 8" and
    : >> nothing goes into the file called out ...

    : >Apparently somewhere down that list of files you have a file
    : >with permissions set so the user you are running this under cannot read
    : >that file.

    : this is odd as I am using Windows 98(SE) and have checked that all
    : files have only the A atribute .. ?

    Win98 will also say "Permission denied" when your program tries to open
    a directory as if it is a file.

    Jay Tilton Guest

  10. #9

    Default Re: readline() on closed fielhandle?

    On Sat, 13 Sep 2003 20:51:28 GMT, [email]tiltonj@erols.com[/email] (Jay Tilton)
    wrote:
    >Geoff Cox <geoff.cox@blueyonder.co.uk> wrote:
    >: Bob Walton <bwalton@rochester.rr.com> wrote:
    >: >Geoff Cox wrote:
    >: >> Kevin Michael Vail <kevin@vaildc.net> wrote:
    >
    >: >>>open IN, $_ or die "can't open $_: $!\n";
    >
    >: >> This has got me confused ! If I use the check for opening the file I
    >: >> get error message "failed in open(): Permission denied at line 8" and
    >: >> nothing goes into the file called out ...
    >
    >: >Apparently somewhere down that list of files you have a file
    >: >with permissions set so the user you are running this under cannot read
    >: >that file.
    >
    >: this is odd as I am using Windows 98(SE) and have checked that all
    >: files have only the A atribute .. ?
    >
    >Win98 will also say "Permission denied" when your program tries to open
    >a directory as if it is a file.
    Jay,

    the email addresses are in files which are in a folder with no
    sub-folders so it cannot be this, can it?

    Geoff

    Geoff Cox Guest

  11. #10

    Default Re: readline() on closed fielhandle?

    On Sat, 13 Sep 2003 15:24:31 -0500, [email]tadmc@augustmail.com[/email] (Tad
    McClellan) wrote:
    >Geoff Cox <geoff.cox@blueyonder.co.uk> wrote:
    >
    >> 1 use warnings;
    >> 2 use strict;
    >> 3 use File::Find;
    >> 4 open (OUT, ">>out");
    >> 5 my $dir = 'c:/atemp1/test';
    >> 6 find ( sub {
    >> 7 open (IN, "$_");
    >> 8 # open(IN, $_) or die "Failed in open(): $!";
    >> 9 while (defined(my $line=<IN>)) {
    >> 10 if ($line =~ /Mailto:(.*?)"/i) {
    >> 11 print OUT ("$1 \n");
    >> 12 }
    >> 13 }
    >> 14 }, $dir);
    >> 15 close (OUT);
    >> 16 close (IN);
    >
    >
    >Please spend the time to format your code sensibly.
    >
    >Many people will just move on to help someone else who has
    >done what they can to make it easier to give an answer.
    Tad,

    sorry about that - would you recommend any program which automates the
    formatting?

    Cheers

    Geoff

    Geoff Cox Guest

  12. #11

    Default Re: readline() on closed fielhandle?

    Geoff Cox <geoff.cox@blueyonder.co.uk> wrote:
    > would you recommend any program which automates the
    > formatting?

    vi or emacs


    --
    Tad McClellan SGML consulting
    [email]tadmc@augustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

  13. #12

    Default Re: readline() on closed fielhandle?

    Geoff Cox <geoff.cox@blueyonder.co.uk> wrote:

    : On Sat, 13 Sep 2003 20:51:28 GMT, [email]tiltonj@erols.com[/email] (Jay Tilton)
    : wrote:

    : >Win98 will also say "Permission denied" when your program tries to open
    : >a directory as if it is a file.
    :
    : the email addresses are in files which are in a folder with no
    : sub-folders so it cannot be this, can it?

    Instead of asking me, ask your program to give you that information.

    find ( sub {
    if( -d $_ ) {
    warn "'$_' is a subdirectory.\n";
    return;
    }
    # rest of subroutine goes here
    }, $dir);

    Jay Tilton Guest

  14. #13

    Default Re: readline() on closed fielhandle?

    On Sat, 13 Sep 2003 17:04:05 -0500, [email]tadmc@augustmail.com[/email] (Tad
    McClellan) wrote:
    >Geoff Cox <geoff.cox@blueyonder.co.uk> wrote:
    >
    >> would you recommend any program which automates the
    >> formatting?
    >
    >
    >vi or emacs
    thanks

    Geoff
    Geoff Cox Guest

  15. #14

    Default Re: readline() on closed fielhandle?

    On Sat, 13 Sep 2003 22:42:36 GMT, [email]tiltonj@erols.com[/email] (Jay Tilton)
    wrote:
    >Geoff Cox <geoff.cox@blueyonder.co.uk> wrote:
    >
    >: On Sat, 13 Sep 2003 20:51:28 GMT, [email]tiltonj@erols.com[/email] (Jay Tilton)
    >: wrote:
    >
    >: >Win98 will also say "Permission denied" when your program tries to open
    >: >a directory as if it is a file.
    >:
    >: the email addresses are in files which are in a folder with no
    >: sub-folders so it cannot be this, can it?
    >
    >Instead of asking me, ask your program to give you that information.
    >
    > find ( sub {
    > if( -d $_ ) {
    > warn "'$_' is a subdirectory.\n";
    > return;
    > }
    > # rest of subroutine goes here
    > }, $dir);
    ok !

    Geoff
    Geoff Cox Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139