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
shivakiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ventolinCommented:
i would fix the way you pass your arguments and then work on you socket implementation.

try passing them with a hash like:

getSign( PORT => '88',
         IP => '127.0.0.1' );

if this is a module, you will first  want to catch the reference:

sub getSign {      
 my $self = shift;

then i'd get arguments:

 %args = @_;

to access them, do this:

 my $port = $args{'PORT'};
 my $ip = $args{'IP'};

and then use this in your socket implementation


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shivakiAuthor Commented:
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
0
ozoCommented:
What arguments are you trying to pass to the sub?
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

shivakiAuthor Commented:
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
0
shivakiAuthor Commented:
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
0
ventolinCommented:
post your revised code and i'll show you.
0
shivakiAuthor Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.