[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1347
  • Last Modified:

pass an argument into a perl module

Hi all,

I created a perl module for subroutines that I use often like this sub below.

sub setVcc {
   my ( $vcc )  = @_;
   print "==========================================================================\n";
   print "\nsetVcc( $vcc )\n";
   if ($vcc > 1.2) {
       $vcc = 1.2;
   if ($vcc <0.7) {
      $vcc = 0.7;
   ExecClo("SetTestParam  -type Level -name vccc_spec -value $vcc");
   print "==========================================================================\n";

When I execute the perl script I do not see the correct value being passed into the setVcc subroutine in the perl module.

I get this result from the line    print "\nsetVcc( $vcc )\n";

setVcc( debuggerHelper=HASH(0x80f7bf0) )

when I execute this line in the main script
$debuggerHelperObject->setVcc( "0.94" );

1 Solution
You are calling the function in object oriented style.  When doing this, the first argument passed to your subroutine is a reference to the object, $debuggerHelperObject in this case.

You could change your subroutine like so:
sub setVcc {
    my $self=shfit;    #get reference to self
    my ($vcc) = @_;

Or you could change your calling method like so:

codenooberAuthor Commented:
Thanks Adam. I used the first option and it worked like a champ. The variiable passed into the perl module.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now