pass an argument into a perl module

Posted on 2007-10-09
Last Modified: 2011-09-20
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" );

Question by:codenoober
    LVL 39

    Accepted 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:


    Author Comment

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

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
    Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now