Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello dear Monks,

I would highly appriciate some help here.

my Programm prints the lines as expected from   print if  /ORA-/ || /Fehler/ || /ORACLE-Fehler/;

in the below Code, but then always ends with :
Couldn't read from remote file: End of file at ./pruefeRmanDUP.pl line 96.

Here me line of codes which fails;

[...] $fh1 = $sftp->open("$file") or die $sftp->error; while (<$fh1>) { print if /ORA-/ || /Fehler/ || /ORACLE-Fehler/; # my $last = $_; # print $last; } [...]
Any Idea what I am doing wrong here? Thanks a lot Diana

Replies are listed 'Best First'.
Re: while (<FH>) always ends with "Couldnt read from remote file: End of file at"
by salva (Canon) on Jul 06, 2017 at 14:15 UTC
    There was a bug I have just fixed on Net::SFTP::Foreign affecting readline when using autodie mode.

    Try running your script again after installing the new version 1.88_01 from CPAN.

Re: while (<FH>) always ends with "Couldnt read from remote file: End of file at"
by haukex (Archbishop) on Jul 06, 2017 at 10:52 UTC

    You haven't shown the appropriate code to reproduce the issue, and the following works fine for me:

    use warnings; use strict; use Data::Dumper; use Net::SFTP::Foreign; $Data::Dumper::Useqq=1; die "Usage: $0 SSH_HOST\n" unless @ARGV==1; my $sftp = Net::SFTP::Foreign->new($ARGV[0]); $sftp->die_on_error("Unable to establish SFTP connection"); my $fh1 = $sftp->open("/etc/passwd") or die $sftp->error; while (<$fh1>) { print Dumper($_) if /root/ || /wheel/ || /www/; }

    To get better help, register an account so that you can edit nodes if necessary (instead of posting several disjoint anonymous nodes) and show a Short, Self-Contained, Correct Example that reproduces the issue - for example you don't show how you create the $sftp object (I have to guess that it's an Net::SFTP::Foreign), and you don't tell us which line is 96. See also How do I post a question effectively?

Re: while (<FH>) always ends with "Couldnt read from remote file: End of file at"
by Anonymous Monk on Jul 06, 2017 at 10:27 UTC
    I Am using :
    use common::sense; # Supposed to be mostly the same, with much lower memory usage, as: # use utf8; # use strict qw(vars subs); # use feature qw(say state switch); # use feature qw(unicode_strings unicode_eval current_sub fc evalby +tes); # no feature qw(array_base); # no warnings; # use warnings qw(FATAL closed threads internal debugging pack # portable prototype inplace io pipe unpack malloc # glob digit printf layer reserved taint closure # semicolon); # no warnings qw(exec newline unopened); use Net::SFTP::Foreign; use Getopt::Std; use Config::General; use Fcntl qw(O_RDONLY :mode); use boolean ':all'; use Data::Dumper;
      use common::sense; Ick!

      While it does many good things, I avoid this module for a couple of reasons:

      1. no strict 'refs'; is an uncommon sensibility. Use it only in those few blocks where it has value.
      2. use utf8; is entirely reasonable in a web app; but, in a command line environment, it completely ignores your terminal's settings and decodes your command line as utf8, no matter how inappropriate.
      TJD

        I agree on no strict 'refs';, but am not sure what "use utf8; ... decodes your command line as utf8" is supposed to mean (also considering this isn't a oneliner). Are you maybe thinking of use open qw/:std :utf8/; or perl -C instead? (see utf8 vs. open vs. -C)

Re: while (<FH>) always ends with "Couldnt read from remote file: End of file at"
by Anonymous Monk on Jul 06, 2017 at 10:25 UTC
    forgot to tell that this while is sourounded by if else as follow:
    [... some stuff here ] if ( $var eq "*" ) { $file = "name*"; # is some real file with an Asterix to search only + on them in the real code my $ls = $sftp->ls (wanted => qr/$file}/ ) or die "unable to retri +eve directory: ".$sftp->error; print "$_->{longname}\n" for (@$ls); } else { $file = "realname.ext"; # existing file say $file; # reading - default method - from the remote file $fh1 = $sftp->open("$file") or die $sftp->error; while (<$fh1>) { print if /ORA-/ || /Fehler/ || /ORACLE-Fehler/; # my $last = $_; # print $last; } exit 0;