FAQ
Hi All,

I am using following code

#!/usr/local/bin/perl

# Main program

use warnings;
use strict;
use File::Find;

my $file = 'c:\\backup.pl';
open (FH, $file);
my ($line);
my $word = pop;
while ($line = <FH>)
{
if ($line =~/$word/)
{
print "match found";
}
else
{
print "match not found";
}
}
close FH;

Following is the error

readline() on closed filehandle FH at C:\irfan\search.pl line 13.

can anybody plz help

Regards
Irfan Sayed

Search Discussions

  • Irfan J Sayed at Jun 2, 2006 at 9:36 am
    Hi All,

    I am using following code

    #!/usr/local/bin/perl

    # Main program

    use warnings;
    use strict;
    use File::Find;

    my $file = 'c:\\backup.pl';
    open (FH, $file);
    my ($line);
    my $word = pop;
    while ($line = <FH>)
    {
    if ($line =~/$word/)
    {
    print "match found";
    }
    else
    {
    print "match not found";
    }
    }
    close FH;

    Following is the error

    readline() on closed filehandle FH at C:\irfan\search.pl line 13.

    can anybody plz help

    Regards
    Irfan Sayed
  • Anthony Ettinger at Jun 2, 2006 at 10:31 am
    my $word = pop; #what is this for?

    open(FH, "$file") or die "$!";
    while (my $line = <FH>)
    {
    if ($line =~ m/foo/)
    {
    print "matched!";
    next;
    }
    print "unmatched :(";
    }
    close(FH);
    On 6/2/06, Irfan J Sayed wrote:
    Hi All,

    I am using following code

    #!/usr/local/bin/perl

    # Main program

    use warnings;
    use strict;
    use File::Find;

    my $file = 'c:\\backup.pl';
    open (FH, $file);
    my ($line);
    my $word = pop;
    while ($line = <FH>)
    {
    if ($line =~/$word/)
    {
    print "match found";
    }
    else
    {
    print "match not found";
    }
    }
    close FH;

    Following is the error

    readline() on closed filehandle FH at C:\irfan\search.pl line 13.

    can anybody plz help

    Regards
    Irfan Sayed


    --
    Anthony Ettinger
    Signature: http://chovy.dyndns.org/hcard.html
  • Dr.Ruud at Jun 2, 2006 at 10:29 am

    Irfan J Sayed schreef:

    I am using following code

    #!/usr/local/bin/perl

    # Main program

    use warnings;
    use strict;
    use File::Find;

    my $file = 'c:\\backup.pl';
    open (FH, $file);
    my ($line);
    my $word = pop;
    while ($line = <FH>)
    {
    if ($line =~/$word/)
    {
    print "match found";
    }
    else
    {
    print "match not found";
    }
    }
    close FH;

    Following is the error

    readline() on closed filehandle FH at C:\irfan\search.pl line 13.

    can anybody plz help
    1. see my previous reply:
    news:20060601111230.10084.qmail@lists.develooper.com

    2. fix the indentation of your script, it's a mess now

    3. guard your opens and closes (see 1.)

    4. use quotemeta for user input: /\Q$word\E/
    (see `perldoc -f quotemeta`)

    --
    Affijn, Ruud

    "Gewoon is een tijger."
  • D. Bolliger at Jun 2, 2006 at 11:39 am

    Irfan J Sayed am Freitag, 2. Juni 2006 09:23:
    Hi All, Hi
    I am using following code

    #!/usr/local/bin/perl

    # Main program

    use warnings;
    use strict;
    use File::Find;
    # File::Find is never used
    my $file = 'c:\\backup.pl';
    open (FH, $file);
    # Always check results of system calls:

    open (FH, $file) or die "error opening '$file' $!";

    # ...and adjust the filename. See the error below which gives you a hint.
    my ($line);
    # not necessary, see below
    my $word = pop;
    # takes the last cmdline argument; if only one is passed,
    # shift is more common
    # you also want to check the usage:

    my $word=shift or die "please give a word to search\n";
    while ($line = <FH>)
    {
    if ($line =~/$word/)
    {
    print "match found";
    }
    else
    {
    print "match not found";
    }
    }
    # in short:

    print 'match ', (/\Q$word\E/ ? '' : 'not'), " found for '$word'\n" for <FH>;

    # note the \Q\E (where \E is not really necessary since at the end of
    # the regex) that assures that all chars are interpreted literally,
    # perldoc -f quotemeta
    close FH;
    Always check system call results
    Following is the error

    readline() on closed filehandle FH at C:\irfan\search.pl line 13.

    can anybody plz help

    Regards
    Irfan Sayed
  • Irfan J Sayed at Jun 2, 2006 at 11:51 am
    Hi All,

    I modified the code as per suggession but still error

    #!/usr/local/bin/perl

    # Main program

    use warnings;
    use strict;
    use File::Find;

    my $file = "c:\\irfan\\cqcmd.txt";
    open (FH, $file) | die "file can't open $! \n";
    my ($line);

    while ($line = <FH>)
    {
    if ($line =~m/foo/)
    {
    print "match found";
    next;
    }
    else
    {
    print "match not found";
    }
    }
    close (FH);

    error is

    Useless use of bitwise or (|) in void context at C:\irfan\search.pl line
    10.
    file can't open Bad file descriptor

    Regards
    Irfan Sayed
  • Irfan J Sayed at Jun 2, 2006 at 11:59 am
    great it's working fine

    thanks

    Regards
    Irfan Sayed





    <balan.ranganathan@wipro.com>
    06/02/2006 05:24 PM

    To
    Irfan J Sayed/India/IBM@IBMIN
    cc

    Subject
    RE: searching word in script







    Use '||' instead of '|'.

    -----Original Message-----
    From: Irfan J Sayed

    Sent: Friday, June 02, 2006 5:20 PM
    To: beginners@perl.org
    Subject: RE: searching word in script

    Hi All,

    I modified the code as per suggession but still error

    #!/usr/local/bin/perl

    # Main program


    use warnings;
    use strict;
    use File::Find;

    my $file = "c:\\irfan\\cqcmd.txt";
    open (FH, $file) | die "file can't open $! \n";
    my ($line);

    while ($line = <FH>)
    {
    if ($line =~m/foo/)
    {
    print "match found";
    next;
    }
    else
    {
    print "match not found";
    }
    }
    close (FH);

    error is


    Useless use of bitwise or (|) in void context at C:\irfan\search.pl line

    10.
    file can't open Bad file descriptor


    Regards
    Irfan Sayed





    The information contained in this electronic message and any attachments
    to this message are intended for the exclusive use of the addressee(s) and
    may contain proprietary, confidential or privileged information. If you
    are not the intended recipient, you should not disseminate, distribute or
    copy this e-mail. Please notify the sender immediately and destroy all
    copies of this message and any attachments.


    WARNING: Computer viruses can be transmitted via email. The recipient
    should check this email and any attachments for the presence of viruses.
    The company accepts no liability for any damage caused by any virus
    transmitted by this email.


    www.wipro.com
  • Dr.Ruud at Jun 2, 2006 at 3:01 pm

    Irfan J Sayed schreef:

    great it's working fine
    No, it is still a mess.

    --
    Affijn, Ruud

    "Gewoon is een tijger."
  • Harold Castro at Jun 5, 2006 at 2:45 am
    Hi,

    I'm currently running perl-5.8.7, my modules are
    located in site_perl/5.8.7 however, after upgrading to
    5.8.8, all of programs using perl modules, suddenly
    breaks because it cannot find those modules into its
    new supposed to be @INC (site_perl/5.8.8.. what can I
    do with this?

    Thanks.


    __________________________________________________
    Do You Yahoo!?
    Tired of spam? Yahoo! Mail has the best spam protection around
    http://mail.yahoo.com
  • Tom Phoenix at Jun 6, 2006 at 1:40 pm

    On 6/4/06, Harold Castro wrote:

    I'm currently running perl-5.8.7, my modules are
    located in site_perl/5.8.7 however, after upgrading to
    5.8.8, all of programs using perl modules, suddenly
    breaks because it cannot find those modules into its
    new supposed to be @INC (site_perl/5.8.8.. what can I
    do with this?
    I recommend you re-install the modules. Although there may be a
    simpler solution, this method ensures that the modules are compiled
    for the correct configuration of the new perl binary.

    Hope this helps!

    --Tom Phoenix
    Stonehenge Perl Training

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedJun 2, '06 at 7:24a
activeJun 6, '06 at 1:40p
posts10
users6
websiteperl.org

People

Translate

site design / logo © 2021 Grokbase