t-rex has asked for the wisdom of the Perl Monks concerning the following question:

I am using 2 packages ( which i have written) initially i was using them as different scripts ( one script calling another and it was working fine ) but now i can't even see the print output.

here is one main.pl script
1 #!/usr/bin/perl 2 print "hello"; 3 use strict; 4 use warnings; 5 use YAML_Lib; 6 use YAML::XS; 7 use Run_Lib; 8 9 print "hello 1"; 10 my $input_file; 11 if(scalar(@ARGV) < 1) 12 { 13 print("USAGE:: $0 <Input file>\n"); 14 exit(0); 15 } 16 17 print STDOUT "Welcome to our little program\n"; 18 19 $input_file = $ARGV[0]; 20 print "Input File = $input_file\n"; 21 # parse the yaml file 22 $YAML_Lib::yaml_input = YAML::XS::LoadFile("$input_file"); 23 &YAML_Lib::parse_yaml($YAML_Lib::yaml_input); 24 25 # call client functions + 26 &Run_Lib::socket_check();

here is the package Run_Lib

1 #!/usr/bin/perl 2 package Run_Lib; 3 use strict; 4 use warnings; 5 use Exporter 'import'; + 6 use Net::OpenSSH; 7 #use Fcntl; 8 #use Client_Lib; 9 10 #function declarations 11 sub socket_check(); 12 sub open_file($$); 13 sub read_file_str($$); 14 sub write_file_str($$); 15 sub server_setup(); 16 17 #global variable declarations 18 my $client_connect_flag = 0; 19 my $pwd = $ENV{'PWD'}; 20 my $filename = "$pwd/LOG.txt"; 21 22 #check for if the socket is established by calling the client (hos +t) script 23 #socket_check(); 24 25 sub socket_check() 26 { 27 # open the log file ( flush for the first time ) 28 print "helloooooooo!!"; 29 my $log_fh = open_file( $pwd, $filename ); 31 #write the log about calling client script 32 my $string = "INFO :: Calling the Client script \n"; 33 write_file_str( $log_fh, $string ); 34 35 # call the client functions to connect to the socket 36 #my $cmd = "$pwd/utpsm_lts_client.pl"; 37 #my $rc = system($cmd) 38 #or die "cant run client.pl $! \n"; 39 40 # my $socket_client = &Client_Lib::client_socket_create(); 41 # &Client_Lib::client_main($socket_client); 42 43 # check the log file if the client connected or not 44 my $client_str = "FAIL_CLIENT_CONNECT"; 45 read_file_str( $log_fh, $client_str); 46 47 # check if client connected or not 48 if ($client_connect_flag) 49 { 50 # setup the server on target 51 server_setup(); 52 } 53 54 } 55 56 sub open_file ($$) 57 { 58 my ( $pwd, $filename ) = @_; 59 my $FH; 60 open ( $FH ,"+>$filename" ) or 61 die "can't open/create $filename $!"; 62 return $FH; 63 } 64 65 66 sub read_file_str ($$) 67 { 68 my ($log_fh, $find_str) = @_; 69 my @lines = <$log_fh>; 70 #check for the output of log file if the client started or not 71 for (@lines) 72 { 73 if ($_ =~ /$find_str/ ) 74 { 75 $client_connect_flag = 0; 76 } 77 } 78 close $log_fh; 79 } 80 81 sub write_file_str ($$) 82 { 83 my ( $log_fh, $string_to_write ) = @_; 84 print $log_fh "$string_to_write"; 85 close $log_fh; 86 }

now i am confused as to what is the problem. anyone has some clues to it

Replies are listed 'Best First'.
Re: Loading package error : script works in weird way
by t-rex (Scribe) on Jun 28, 2016 at 06:53 UTC

    hey monks, i got the problem there was an exit in my Run_Lib.pm which when i commented is now giving me proper results. sorry for the inconvenience , pls don't down vote, this si a learning every time i make package we shouldn't write an exit

      Glad to hear you have found and fixed your bug.

      For future reference it would be much kinder to everyone if you could refrain from prepending each line in your source with a number. I believe that there are user settings in PerlMonks at each user's discretion which can add these as a viewing aid for those users which prefer them but if you do it in the posted code there's no simple method to then switch them off. Much worse, anyone who tries to download your code to test it and help you debug it would first have to edit out all the line numbers. Help us to help you and just omit them next time. Thanks.

      If one inserts an exit into their program for testing purposes, one might consider placing a print statement in front of it.

      print 'Exiting the package', "\n"; exit;

      If one forgets to delete the exit, then one will see the message when one runs the program again months later.