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

Hallo

I'm in need of some help. I can't really narrow the Problem down. I have some really Basic Perl Program which should help me to get Protokoll my testing of Oracle SQL Scripts a Little swifter. in most Cases it runs ver well for my Needs. But from time to time without any reasoning it rejects some files. here is the Errormessege i recieve.

.fad fuer command test ist /edvtest/cdk/kuda_537/TP/TP_chk_mjm.sql :Keine Datei und kein Verzeichnis at /edvtest/cdk/shellscripts//my_uti +ls.pm line 440_chk_mjm.sql ', 1) called at /edvtest/cdk/shellscripts/Testframework_v2/MANAGE_ORAC +LE.pm line 413 ') called at /edvtest/cdk/shellscripts/Testframework_v2/TEST_SQL.pm li +ne 201/TP/TP_chk_mjm.sql ') called at /edvtest/cdk/shellscripts/Testframework_v2/TEST_SQL.pm li +ne 65jm.sql ') called at /edvtest/cdk/shellscripts/Testframework_v2/TEST_SQL.pm li +ne 29est/cdk/kuda_537/TP/TP_chk_mjm.sql ', '\u20ac') called at ./consol_output.pl line 135', 'DBI::db=HASH(0x4 +089f718)', 'test\u20ac/edvtest/cdk/kuda_537/TP/TP_chk_mjm.sql the packages i use are as following <code> #!/usr/bin/perl package TEST_SQL; use strict; use warnings; use lib $ENV{'HOME'} . "/shellscripts/"; use lib $ENV{'HOME'} . "/modules"; use DBI; use DBD::Oracle; use Getopt::Long; use Crypt::OpenSSL::RSA; use Carp; use POSIX; use utf8; use MANAGE_ORACLE; use my_utils; ... sub handle_ctctl_line { my ($pname,$dbh,$orders,$seperator) = @_; my @return; my @orderlist = split($seperator,$orders); my $do_what = shift @orderlist; if ("test" eq "$do_what") { my ($sqlpath,@params) = @orderlist; @return = ctctl_test($pname,$dbh,$sqlpath,@params); } elsif ("proc" eq "$do_what") { my ($package,$procedure,@params) = @orderlist; @return = MANAGE_ORACLE->start_procedure($dbh,$package,$procedure, +@params); } elsif ("pause" eq "$do_what") { push @return, undef; push @return, "pause"; } elsif ("text" eq "$do_what") { @return = ctctl_text($pname,@orderlist); } elsif ("line" eq "$do_what") { @return = ctctl_line($pname,@orderlist); } elsif ("start" eq "$do_what") { #param 1 immer prog_name, param2 immer extension, param3 Shell_par +ameter @return = ctctl_start($pname,$dbh,@orderlist); } elsif ("plsql" eq "$do_what") { @return = ctctl_plsql($pname,$dbh,@orderlist); } elsif ("sqlplus" eq "$do_what") { #nicht vergessen $dbh ist in diesem context kein db-handle sonder +ein dbcon; @return = ctctl_sqlplus($pname,$dbh,@orderlist); } else { push @return, undef; push @return, "empty"; } return @return; } ... sub ctctl_test { my ($pname,$dbh,$sqlpath,@params) = @_; my $output = pre_result($pname,$sqlpath,@params); my @return = MANAGE_ORACLE->call_sql_stmt($dbh,$sqlpath,undef,@param +s); my ($is_ok,$e_code,$e_msg,$o_csv,$o_reccs,$o_cols) = @return; if ($is_ok && $o_reccs >= 0) { $output = $output . rewe_utils->union_array(rewe_utils->format_csv +_txt($o_csv,$o_reccs,$o_cols)); $output .= process_rownumber($o_reccs); $return[3] = $output; } return @return; } ... sub pre_result { my ($pname,$stmtpath,@params) = @_; my $return = "Abfragezeitpunkt: " . (strftime "%d.%m.%Y %H:%M:%S", l +ocaltime) . "\n" . "Script: $stmtpath\n"; my $sqlstmt = MANAGE_ORACLE->get_statement($stmtpath,@params); $return .= "Statement:\n" . $sqlstmt . "\n\n"; return $return; } ---------------------------------------------------------------------- +------------------- #!/usr/bin/perl package MANAGE_ORACLE; use strict; use warnings; use DBI; use DBD::Oracle; use Carp; use utf8; use lib "/edvtest/cdk/shellscripts/"; use my_utils; sub get_statement { my ($pname,$sqlpath,@params) = @_; my $sqlstmt = my_utils->read_file($sqlpath,1); if (scalar(@params) > 0) { my $counter = 1; foreach my $param (@params) { $sqlstmt =~ s/(:$counter)/$param/g; $counter++; } } return $sqlstmt; } ---------------------------------------------------------------------- +------------------ #!/usr/bin/perl package rewe_utils; use strict; use warnings; use Carp; use utf8; my $linesize = 75; my $moddir = $ENV{'HOME'} . "/modules"; print $moddir; #use lib $moddir; use Crypt::OpenSSL::RSA; use Convert::PEM; use MIME::Base64; use File::Basename; use XML::Simple; use ORADB; use POSIX; sub read_file { my ($pname,$path,$encoding) = @_; my $return = undef; local $/ = undef; if ($encoding) { open (my $fh, "<:encoding(UTF-8)", $path) or confess "Uebergebener + Pfad nicht korrekt: /n" . $0 . ': open' . $path .':' . $!; { local $/; $return = <$fh>; } close $fh; $return = convert_problems($pname,$return); } else { open (my $fh, '<', $path) or confess "Uebergebener Pfad nicht korr +ekt: /n" . $0 . ': open' . $path .':' . $!; { local $/; $return = <$fh>; } close $fh; } chomp $return; return $return; }
--------------------------------------------------------------------------------

the start Programm uses the followig

#!/usr/bin/perl use strict; use warnings; use lib $ENV{'HOME'} . "/shellscripts/"; use lib $ENV{'HOME'} . "/modules"; use lib $ENV{'HOME'} . "/shellscripts/Testframework_v2"; use Getopt::Long; use Crypt::OpenSSL::RSA; use Carp; use POSIX; use utf8; use TEST_SQL; use MANAGE_ORACLE; use my_utils;

Critics and help would be great as i am fairly new to the whole Perl theme and i sadly have no real Input on Things i do

thanks in advance Christian

Replies are listed 'Best First'.
Re: Problem with file encoding
by Corion (Patriarch) on Mar 28, 2019 at 09:24 UTC
    .fad fuer command test ist /edvtest/cdk/kuda_537/TP/TP_chk_mjm.sql :Keine Datei und kein Verzeichnis at /edvtest/cdk/shellscripts//my_uti +ls.pm line 440_chk_mjm.sql ...

    The first step would be to look at (or show us) line 440 in my_utils.pm. From the mangled line :Keine Datei und kein Verzeichnis at /edvtest/cdk/shellscripts//my_utils.pm line 440_chk_mjm.sql, I assume that there is whitespace (for example, a carriage return) at the end of the filename that ends in 440_chk_mjm.sql. Most likely, whatever routine is reading the filenames of the SQL files from a file is not cleaning up whitespace at the end of each line.

    If there is no whitespace at the end there, please show us how you are reading that filename and where it comes from. Data::Dumper has the $Useqq variable to also output whitespace, so inspecting the string would also help:

    use Data::Dumper; $Data::Dumper::Useqq = 1; warn Dumper $filename;

    Otherwise, output more of the filenames and values into your logfile.

Re: Problem with file encoding
by haj (Vicar) on Mar 28, 2019 at 09:33 UTC

    Hello Christian,

    The first thing to do would be to check the file name your program is trying to open. It seems that a few bytes are missing from your error output?

    If it is the file test\u20ac/edvtest/cdk/kuda_537/TP/TP_chk_mjm.sql, then note that there's an UTF-8-encoded Euro sign (\u20ac) in the path name. I guess that most file systems nowadays handle those paths, but if "from time to time" only happens with files containing non-ASCII charaters, then you might have something to investigate on.

      Especially on Windows, the APIs expect a Wide string instead of UTF-8, while Unixish systems do not care about the encoding and expect a matching byte string. Using the Wide Windows APIs and finding the appropriate encoding on Unixish systems is possible, but for that, we'll have to wait for further information as to what actually goes wrong and what OS the OP is using.

Re: Problem with file encoding
by Just_ME (Novice) on Mar 28, 2019 at 10:35 UTC

    thx for all your time

    your suggestions lead me the right way!

    The Problem was that recently my Notepad++ crashed and the settngs for linefeed were resetted. The Input for my program is a plain textfield which consists of Steps which the program should do with stored paths to SQL statments. I work on a unix System and after the Crash of my Notepad++ the Default Settings were Windows lf so perl was confused and right so

    thanks Christian