PERL: Calling a sub routine from another module - help!!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting PERL: Calling a sub routine from another module - help!!!
# 1  
Old 09-26-2014
PERL: Calling a sub routine from another module - help!!!

Hi,

I am an occasional PERL user. I am trying to call a sub routine (passing parameters) in perl module from a driver .pl file. I have been "tinkering" for a while now and have confused myself.

Could someone please look at the code below and spot where I am going wrong.

testPerl.pl

Code:
#!/usr/local/bin/perl -w
use strict;
use call;
    my $to_directory = "F:\\Received";   # The target directory
    my $snode        = "cd.nt.arc.trl";   # The Secondary node
    my $directory    = "\/data\/enva\/MS\/msarchive";   # cd log dirs
    my $from_directory = "R:\\"; # The directory where lis files are kept
    my $report_dir   = "\/data\/enva\/MS\/msarchive\/archive_report";   # Report Directory
    my $subsystem    = "M";   # e.g. M for Message Server
my $date = "ADATE";
my $filename = "dir$date.lis";
$call->get_sentfilecount($to_directory, $snode, $directory, $from_directory, $report_dir, $subsystem);
call::get_sentfilecount($to_directory, $snode, $directory, $from_directory, $report_dir, $subsystem);

call.pm

Code:
#!/usr/local/bin/perl -w
use strict;
package call;

sub get_sentfilecount
{
    use POSIX qw(strftime);
    my $to_directory = shift;   # The target directory
    my $snode        = shift;   # The Secondary node
    my $directory    = shift;   # cd log dirs
    my $from_directory = shift; # The directory where lis files are kept
    my $report_dir   = shift;   # Report Directory
    my $subsystem    = shift;   # e.g. M for Message Server
    my $line         = undef;
    my $lastline     = undef;
    my $CD_OUT       = undef;
    my $CD_IN        = undef;
    
    my $date = strftime "%d%m%Y", localtime;
    my $filename = "dir$date.lis";
    my $trans_file = $from_directory.$subsystem."\\". $filename;
    print "$trans_file";
    # connect direct stuff goes here
    if (!open(CDFILE, ">$directory/mstont2.cd"))
    {
        $ArchiveServer::errstr = "can't open mstont2.cd for writing: $!";
        return 0;
    }
    # Form the Connect:Direct copy command and write it into the file mstont2.cd
    #
    # The transfer should be made in binary mode with no translation
    # The transfer mode should be described in both the from and to part of the copy
    # statement
    #
    my $get_liscount = qq(
                       mstont2 process snode=$snode
                       step01
                         run task snode (PGM=WinNT)
                         sysopts="cmd(dir $to_directory\\*.TXT  > $from_directory\\dir$date.lis) desktop(no)"
                       step02
                       copy from (file =$trans_file
                                      snode
                                      sysopts="datatype(binary) xlate(no)"
                                     )
                                to   (file = $report_dir
                                      pnode
                                      sysopts=":datatype=binary:xlate=no:"
                                      disp = rpl
                                     )
                       pend;
                      );
    print CDFILE $get_liscount;
    close(CDFILE);
    my $errcd = 0;
    # Open Connect:Direct CLI and submit job in file mstont2.cd
    eval
    {
        $errcd = open2($CD_OUT, $CD_IN, 'direct 2>/dev/null');
    };
    if ($@)
    {
       $ArchiveServer::errstr = "Cannot Create command for file transfer due to: $!";
       return 0;
    }
    print $CD_IN "submit file=$directory/mstont2.cd;\n";
    print $CD_IN "quit;\n";
    close($CD_IN);
    my $OKflag = 0;
    while ($line = <$CD_OUT>)
    {
        chomp($line);
        if ($line =~ "Process Submitted")
        {
           $OKflag = 1;
        }
        $lastline = $line;
    }
    if (0 == $OKflag )
    {
       $ArchiveServer::errstr = "Cannot create submit process command for file transfer due to : $lastline";
       return 0;
    }
    close($CD_OUT);
    if ($@)
    {
       $ArchiveServer::errstr = "Cannot Create command for file transfer due to: $!";
       return 0;
    }
    print $CD_IN "submit file=$directory/mstont2.cd;\n";
    print $CD_IN "quit;\n";
    close($CD_IN);
    my2 $OKflag = 0;
    while ($line = <$CD_OUT>)
    {
        chomp($line);
        if ($line =~ "Process Submitted")
        {
           $OKflag = 1;
        }
        $lastline = $line;
    }
    if (0 == $OKflag )
    {
       $ArchiveServer::errstr = "Cannot create submit process command for file transfer due to : $lastline";
       return 0;
    }
    close($CD_OUT);
    return 1;
}
1;

When I run it, I get the following error:

$ perl -w testPerl.pl
Global symbol "$call" requires explicit package name at testPerl.pl line 15.
Execution of testPerl.pl aborted due to compilation errors.

Thanks

Chris

---------- Post updated at 04:48 PM ---------- Previous update was at 04:23 PM ----------

OK got it (the PERL) to work:

Code:
#!/usr/local/bin/perl -w
use strict;
use call;
    my $to_directory = "F:\\Received";   # The target directory
    my $snode        = "cd.nt.arc.trl";   # The Secondary node
    my $directory    = "\/data\/enva\/MS\/msarchive";   # cd log dirs
    my $from_directory = "R:\\"; # The directory where lis files are kept
    my $report_dir   = "\/data\/enva\/MS\/msarchive\/archive_report";   # Report Directory
    my $subsystem    = "M";   # e.g. M for Message Server
my $date = "ADATE";
my $filename = "dir$date.lis";
##$call->get_sentfilecount($to_directory, $snode, $directory, $from_directory, $report_dir, $subsystem);
my $call = call::get_sentfilecount($to_directory, $snode, $directory, $from_directory, $report_dir, $subsystem);

Code:
#!/usr/local/bin/perl -w
use strict;
package call;

sub get_sentfilecount
{
    use POSIX qw(strftime);
    my $to_directory = shift;   # The target directory
    my $snode        = shift;   # The Secondary node
    my $directory    = shift;   # cd log dirs
    my $from_directory = shift; # The directory where lis files are kept
    my $report_dir   = shift;   # Report Directory
    my $subsystem    = shift;   # e.g. M for Message Server
    my $line         = undef;
    my $lastline     = undef;
    my $CD_OUT       = undef;
    my $CD_IN        = undef;
    
    my $date = strftime "%d%m%Y", localtime;
    my $filename = "dir$date.lis";
    my $trans_file = $from_directory.$subsystem."\\". $filename;
    print "$trans_file";
    # connect direct stuff goes here
    if (!open(CDFILE, ">$directory/mstont2.cd"))
    {
        $ArchiveServer::errstr = "can't open mstont2.cd for writing: $!";
        return 0;
    }
    # Form the Connect:Direct copy command and write it into the file mstont2.cd
    #
    # The transfer should be made in binary mode with no translation
    # The transfer mode should be described in both the from and to part of the copy
    # statement
    #
    my $get_liscount = qq(
                       mstont2 process snode=$snode
                       step01
                         run task snode (PGM=WinNT)
                         sysopts="cmd(dir $to_directory\\*.TXT  > $from_directory\\dir$date.lis) desktop(no)"
                       step02
                       copy from (file =$trans_file
                                      snode
                                      sysopts="datatype(binary) xlate(no)"
                                     )
                                to   (file = $report_dir
                                      pnode
                                      sysopts=":datatype=binary:xlate=no:"
                                      disp = rpl
                                     )
                       pend;
                      );
    print CDFILE $get_liscount;
    close(CDFILE);
    my $errcd = 0;
    # Open Connect:Direct CLI and submit job in file mstont2.cd
    eval
    {
        $errcd = open2($CD_OUT, $CD_IN, 'direct 2>/dev/null');
    };
    if ($@)
    {
       $ArchiveServer::errstr = "Cannot Create command for file transfer due to: $!";
       return 0;
    }
    print $CD_IN "submit file=$directory/mstont2.cd;\n";
    print $CD_IN "quit;\n";
    close($CD_IN);
    my $OKflag = 0;
    while ($line = <$CD_OUT>)
    {
        chomp($line);
        if ($line =~ "Process Submitted")
        {
           $OKflag = 1;
        }
        $lastline = $line;
    }
    if (0 == $OKflag )
    {
       $ArchiveServer::errstr = "Cannot create submit process command for file transfer due to : $lastline";
       return 0;
    }
    close($CD_OUT);
    if ($@)
    {
       $ArchiveServer::errstr = "Cannot Create command for file transfer due to: $!";
       return 0;
    }
    print $CD_IN "submit file=$directory/mstont2.cd;\n";
    print $CD_IN "quit;\n";
    close($CD_IN);
    my2 $OKflag = 0;
    while ($line = <$CD_OUT>)
    {
        chomp($line);
        if ($line =~ "Process Submitted")
        {
           $OKflag = 1;
        }
        $lastline = $line;
    }
    if (0 == $OKflag )
    {
       $ArchiveServer::errstr = "Cannot create submit process command for file transfer due to : $lastline";
       return 0;
    }
    close($CD_OUT);
    return 1;
}
1;

Just need to get the Connect Direct bit to work now!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl SSH without a perl module

I'm trying to create a perl script that will do 1 SSH session, but be able to write multiple commands to the session and receive multiple outputs. I know there are modules out there like Net:SSH::Perl, but I'm not allowed to use it. I was thinking of doing something like an open3 on an ssh... (4 Replies)
Discussion started by: mrwatkin
4 Replies

2. Shell Programming and Scripting

Perl - Call a sub routine in a command

Hi all I have written a simple perl script that has different options i.e. myscript -l -p etc i have it so when it runs without any switches it runs a subroutine called nvrm_norm i want to be able to do a -p option and run pall -w -f and then called the subruotine pall is... (1 Reply)
Discussion started by: ab52
1 Replies

3. Shell Programming and Scripting

calling perl subroutine from perl expect module

All, Is it possible to call a subroutine from the perl expect module after logging to a system that is within the same program. My situation is I need to run a logic inside a machine that I'm logging in using the expect module, the logic is also available in the same expect program. Thanks,... (5 Replies)
Discussion started by: arun_maffy
5 Replies

4. Shell Programming and Scripting

Which Perl Module to use?

Hi, I need to read an excel binary file and write the data to a text file. Is it possible using Spreadsheet-ParseExcel-0.58 ? If not, is there any module available in CPAN to do this? Thanks, Js (1 Reply)
Discussion started by: jisha
1 Replies

5. Shell Programming and Scripting

Perl - run sub routine for list of devices

Hi, Can anyone please correct the script such that it run on all the devices in the devicelist.txt file. The problem is when the script runs it only reads the first device in the list, configures the device and exists. Script: The devicelist.txt: device.crs... (1 Reply)
Discussion started by: sureshcisco
1 Replies

6. Shell Programming and Scripting

Perl Module

Hi, Please help me!! Im wondering if anyone can help me with a problem i have with some perl modules. My problem is: I'm trying to connect remote host to a unix box from a windows machine. So i'm developing an application to do this. I'm programming it in perl with tcl/tk Gui interface.... (13 Replies)
Discussion started by: Phi01
13 Replies

7. Shell Programming and Scripting

Help with Perl Module

I dont know if this is a dumb question, but I am unable to move ahead and need help - There is a perl module called Header.pm which was written by someone else. I am trying to write a simple perl script which uses a function provided by the module. The function has been exported by the module... (9 Replies)
Discussion started by: NewDeb
9 Replies

8. Shell Programming and Scripting

Replace Perl Module name in all Perl scripts

I want to replace a Perl module name in all my Perl Scripts in the cgi-bin directory. How is it possible? I have the following statement in my scripts use myUtil; I want to change it to use myUtil777; Regards, Rahul (2 Replies)
Discussion started by: rahulrathod
2 Replies

9. Shell Programming and Scripting

Correct Syntax For Calling Shell Script in Perl Module

Problem: I have a shell script that will be called by a Perl module that will connect to a db and delete rows. The Perl module will be called by CRON. I am using a Perl module to call a shell script because I need to get the db connection from Perl. Here is the Perl pseudocode: ... (4 Replies)
Discussion started by: mh53j_fe
4 Replies

10. UNIX for Dummies Questions & Answers

Calling privately installed module from script help please

hello, i need help calling a privately installed module from a script. my server admin installed perl with the standard modules and simply no extras, including the LWP::Simple mod i need. (side note: ive asked for it to be installed). in the meantime, i installed it (libwww-perl-5.62.tar.gz)... (2 Replies)
Discussion started by: sdiva
2 Replies
Login or Register to Ask a Question