#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2009
    Location
    Washington, DC
    Posts
    11
    Rep Power
    0

    Problem with: my $ww = XX::YY -> new( $zz )


    Sorry to say I am so old school procedural programming, that I don't even know how to ask this object oriented question. (at least I think that's what this is )

    Here's the code that works:
    Code:
      my $request = Something::Something->new(
         {DomainName=>'xx',ItemName=>'yy',Attribute=>[
           {Name=>'data',Value=>'1234567890'}
         ],}
      );
    My goal was to replace the "informtion" with a string:
    Code:
      $string="{DomainName=>'xx',ItemName=>'yy',Attribute=>[
                 {Name=>'data',Value=>'1234567890'} 
               ],}";
      my $request = Something::Something->new(
         $string
      );
    This causes an error stating string can't be used as a hash reference while "strict refs" in use at... I need to avoid modifying the module.

    Am I doing something horribly wrong? Suggestions?
  2. #2
  3. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,264
    Rep Power
    1810
    You can't supply a string and expect it to be recognized as a hash, array, or reference. It's possible that a receiving module could 'eval' the string and try to turn it into data, but you aren't changing the module so that is out of the question.

    You can build the data in pieces rather than trying to write it all out as one block. Might be easier to visualize:
    Code:
    my @attr;
    # push in as many attributes as you want
    push @attr, {'Name'=>'data', 'Value'=>'1234567890'};
    
    my %request;
    $request{'DomainName'} = 'xx';
    $request{'ItemName'} = 'yy';
    $request{'Attribute'} = \@attr;
    
    my $request = Something::Something->new(\%request);

    Comments on this post

    • dougbunger agrees
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2009
    Location
    Washington, DC
    Posts
    11
    Rep Power
    0
    Brilliant reply! Thanks for explaining this. Its not a problem with instantiation, its a problem with providing the data in the expected format. Your code example helped to clarify the situation.

    Thank you... And Happy 2010!

IMN logo majestic logo threadwatch logo seochat tools logo