Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Passing hash arguments

Expand Messages
  • Arun Pandey
    In your method setA change $self- {VAR} = %{(shift)}; to $self- {VAR} = {@_}; hope this helps. ... From: sumit_bhattacharjee_2004 To:
    Message 1 of 3 , Feb 19, 2007
    • 0 Attachment
      In your method setA change
      $self->{VAR} = %{(shift)};

      to
      $self->{VAR} = {@_};

      hope this helps.
      ----- Original Message -----
      From: sumit_bhattacharjee_2004
      To: perl-beginner@yahoogroups.com
      Sent: Monday, February 19, 2007 9:47 PM
      Subject: [PBML] Passing hash arguments


      Hi,

      Can anyone help me with this? I just cant figure out what I am
      doing wrong here.keep getting the error "Can't use an undefined
      value as a HASH reference.".
      *********************************************************************
      **********************************

      ==============
      Main.pl
      ==============
      #! usr/bin/perl -w

      use strict;
      use A;
      use C;

      my $a = new A;
      my %has = $a->get;
      my $c = new C;
      $c->setA(%has);
      print $c->getA;

      1;

      ===============
      a.pm
      ===============
      #! usr/bin/perl -w

      package A;

      sub new {
      my $self = {};
      return bless $self;
      }

      sub get {
      my $self = shift;
      my %h = ("1"=>"one","2"=>"two","3"=>"three");
      return %h;
      }

      1;

      ===============
      c.pm
      ===============
      #! usr/bin/perl -w

      package C;

      sub new {
      my $self = {};
      $self->{VAR} = {};
      return bless $self;
      }

      sub setA {
      my $self = shift;
      $self->{VAR} = %{(shift)};
      }

      sub getA {
      my $self = shift;
      return $self->{VAR}->{1};
      }

      1;

      *********************************************************************
      ***************************************

      Thanks in advance for any help!

      Sumit




      "Legal Disclaimer: This electronic message and all contents contain information from Cybage Software Private Limited which may be privileged, confidential, or otherwise protected from disclosure. The information is intended to be for the addressee(s) only. If you are not an addressee, any disclosure, copy, distribution, or use of the contents of this message is strictly prohibited. If you have received this electronic message in error please notify the sender by reply e-mail to and destroy the original message and all copies. Cybage has taken every reasonable precaution to minimize the risk of malicious content in the mail, but is not liable for any damage you may sustain as a result of any malicious content in this e-mail. You should carry out your own malicious content checks before opening the e-mail or attachment."
      www.cybage.com




      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.