Link to home
Start Free TrialLog in
Avatar of shivaki
shivaki

asked on

problem with subroutines

Hello there,
     I have made a perl subroutine lik this

sub getSign {    
#use strict;
require 5.002;
use Socket;

#my(@input) = @_;
my($remote,$port,$iaddr,$paddr,$proto,$line,$retval,$beg,$end,$sign);
$port =  shift || 8888;
$iaddr =  inet_aton("9.184.192.17") or die "Socket S!";
$paddr =  sockaddr_in($port, $iaddr) or die "Socket S!";
$proto = getprotobyname('tcp') or die "socket $!";
socket(SOCK, PF_INET, SOCK_STREAM, $proto) or die "socket $!";
connect(SOCK, $paddr) or die "socket  $!";
send(SOCK, "\%S\#data::Hellow\$\$\$\n", 0) or die "socket $!";    
$line = <SOCK> ;
if($line =~ /\#signature::/ )
 {
   $beg = index($line, "#signature::");
   $end = index($line, "\$\$\$");
   $sign = substr($line, $beg+12, $end-$beg-12);  
 } else
        {  
            $beg =   index($test,"\%");
            $end  =  index($test,"\$\$\$");
            $sign = substr($test, 1,$end-$beg-1);                
        }      
close(SOCK);
return ($sign);
}

This program basically opens socket connection to some system and sends a packet in format "%S#data::datato Sign$$$\n" and then receives the signed data.
       The problem with the above subroutine is if I am using it like this
$ret = getSign or $ret = &getSign or $ret=getSign( )
  it works fine and when I tries to pass some data like this
$ret = getSign("data1", "data2", "data3") or
  $ret = getSign(@myInput)
   the program files at connect saying Unknown Error: 0x0000274d at sign.pl line 21, what is the problem with this?.

      I am very novice at perl and my problem is  I have to submit this to our client urgently, please help me. And please try to make it as module and tell me how to use that module in regular perl programs .
     Thanks in advance.
-shivaki
ASKER CERTIFIED SOLUTION
Avatar of ventolin
ventolin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shivaki
shivaki

ASKER

Thanks for Ur help vetolin,
    I found the bug in my code the real culprit was $port =  shift || 8888; If You help me  how to make this subroutine as apackage/module that's a great help for me.
Thanks alot
shivaki
Avatar of ozo
What arguments are you trying to pass to the sub?
Avatar of shivaki

ASKER

an array comprises 4 arguments. My intention is that this subroutine should be used in many programs, I don't know  whether is there any #include option is available in perl. But I heard that the equivalent concept in Perl is packages/modules, can U help me to build this?.
Thanks & Regards
shivaki
Avatar of shivaki

ASKER

an array comprises 4 arguments. My intention is that this subroutine should be used in many programs, I don't know  whether is there any #include option is available in perl. But I heard that the equivalent concept in Perl is packages/modules, can U help me to build this?.
Thanks & Regards
shivaki
post your revised code and i'll show you.
Avatar of shivaki

ASKER

Thanks for all and I got this. But I landed  in a different problem(not good to ask here itself I am posting a new question) please see and reply for it.

Thanks a lot
shivaki