Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Problems with passing arguments to a subroutine in a perl package

by mmnormyle (Initiate)
on Jul 17, 2013 at 00:28 UTC ( #1044687=perlquestion: print w/replies, xml ) Need Help??
mmnormyle has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys, I'm new to perl and I'm having a strange issue. I'm trying to pass an argument to a subroutine that is not in the current script, but within a package that the script uses. my code looks like this: first script
use Utilities::utilities; $target_ip1 = GetIPadd(2);
package
sub GetIPadd { my $deviceinfo = shift @_ or die; ...... }
The code always dies at this line, and I'm not sure why. Is it an issue with passing parameters to a subroutine not directly in the perl file? The package utilities.pm is stored in a directory within the working directory of the first script.
ex.
script - C:\scripts\firstscript.pl
oackage - C:\scripts\Utilities\utilities.pm
Any help would be greatly appreciated.

Replies are listed 'Best First'.
Re: Problems with passing arguments to a subroutine in a perl package
by NetWallah (Canon) on Jul 17, 2013 at 00:32 UTC
    Welcome to the Monastery !

    Please post the actual error message - this would help us help you.

    Most likely, you are using "strict", and not "export"ing GetIPadd.

    If this is the case, please try calling it like this:

    $target_ip1 = Utilities::utilities::GetIPadd(2);

                 My goal ... to kill off the slow brain cells that are holding me back from synergizing my knowledge of vertically integrated mobile platforms in local cloud-based content management system datafication.

Re: Problems with passing arguments to a subroutine in a perl package
by mmnormyle (Initiate) on Jul 17, 2013 at 00:39 UTC
    Glad to be here! edit: Nevermind on my previous success.
    The error that I'm getting is Use of uninitialized value in concatenation (.) or string at Utilities/utilities .pm line 374.
    The uninitialized value is referring to the $deviceinfo variable.
    I am using strict...but even when I tried your method of exporting the subroutine it still did not work. When I tried that perl did not recognize the subroutine.

    Thanks for your help
      Its got nothing to do with "subroutines being recognized", you got undef, that is all.

      If you want more help post code that reproduces the problem, a Short, Self Contained, Compilable, Example like

      #!/usr/bin/perl -- use strict; use warnings; use diagnostics; Main( @ARGV ); exit( 0 ); sub Main { my $fb = Foo::Bar(3); $fb++; print "$fb\n"; } sub Foo::Bar { my( $i , $eeb ) = @_; return $eeb + $i; } __END__
Re: Problems with passing arguments to a subroutine in a perl package
by Anonymous Monk on Jul 17, 2013 at 01:12 UTC

    Your class file is being recognized otherwise it would have been mentioned. So there should be something wrong with the class code.

Re: Problems with passing arguments to a subroutine in a perl package
by Anonymous Monk on Jul 17, 2013 at 01:54 UTC

    check out the class build-up of the following example i once made for a blackjack game, i couldn't find another example. Compare that with yours.

    package Bank; our %kaarten = qw/2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 J 10 Q 10 K 10 + A 11/; our @kaarten = keys(%kaarten); our $totaal; our $azen = 0; our $cor; sub new{ $self = shift; $getal = int(rand(13)); $kaart = @kaarten[$getal]; $waarde = $kaarten{$kaart}; if($waarde == 11){ $azen +=1;} print "Bank heeft een $kaart. Puntentotaal = $waarde.\n"; $totaal += $waarde; return $self; } sub bankspeel{shift; $inze = shift; $to = shift; $saldo = shift; while($totaal<17){ $getal = int(rand(13)); $kaart = @kaarten[$getal]; $waarde = $kaarten{$kaart}; $totaal += $waarde; print "Bank heeft een $kaart. Puntentotaal = $totaal.\n"; if($totaal > 21){ if($azen != 0){ $cor = 10 * $azen; if(($totaal-$cor)>21){ print "Busted, u wint $inze.\n" } else {$totaal = $totaal - $cor; if($totaal<12){$totaal += 10;}} }} if($totaal > 21){ print "Busted.U wint $inze.\n";$saldo+=$inze;print "Uw saldo is $saldo +\n"; exit; } sleep(2); } if($to > $totaal){print "U wint $inze\n";$saldo+=$inze;print "Uw saldo + is $saldo\n"} elsif($to < $totaal){print "U verliest $inze\n";$saldo-=$inze;print "U +w saldo is $saldo\n"} else{ print "stand-off\n";} } sub kaart{ $self = shift; $tot = shift; $getal = int(rand(13)); $kaart = @kaarten[$getal]; print "U heeft een $kaart gekregen\n"; $waarde = $kaarten{$kaart}; $tot += $waarde; return $tot; } sub double{ shift; $to = shift; $getal = int(rand(13)); $kaart = @kaarten[$getal]; print "U heeft een $kaart gekregen\n"; $waarde = $kaarten{$kaart}; $to+=$waarde; print "U past op $to.\n"; return $to; } 1;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1044687]
Approved by Athanasius
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2018-07-22 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (455 votes). Check out past polls.

    Notices?