Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: backslash found where operator expected at

by GrandFather (Saint)
on Apr 21, 2021 at 21:12 UTC ( [id://11131554]=note: print w/replies, xml ) Need Help??


in reply to backslash found where operator expected at

use strict; use warnings; use Switch; package SES; sub call_ses { my ($paramHash, $optHash) = @_; print "$_ $paramHash->{$_}\n" for keys %$paramHash; return 400, ''; } package main; my %params = (hello => "world"); my %opts; my ($response_code, $response_content) = SES::call_ses \%params, \%opt +s; switch() { case '400' {} }

prints:

hello world

as expected so there is more going on than you are showing. Maybe you should generate the sensible minimum code required to reproduce the issue? See I know what I mean. Why don't you? for some hints.

Note that use of the Switch module is strongly discouraged and has been for a long time. Not the smoking gun in this case, but best practice would avoid using it.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Replies are listed 'Best First'.
Re^2: backslash found where operator expected at
by jmc (Initiate) on May 06, 2021 at 20:56 UTC
    Sorry for hijacking the thread, my issue is on the SES::call_ses side. If I shift $self I get an error about an empty hash for %$opts, if I don't shift $self it works. This works:
    sub call_ses { my $params = shift; my $opts = shift; %opts = %$opts; %params = %$params; my $endpoint_name = $endpoint; }
    This doesn't:
    sub call_ses { my $self = shift; my $params = shift; my $opts = shift; %opts = %$opts; <-- Line 559 %params = %$params; my $endpoint_name = $self->AWS_endpoint; }
    Can't use an undefined value as a HASH reference at /usr/share/perl5/vendor_perl/SES.pm line 559 (#1) (F) A value used as either a hard reference or a symbolic referenc +e must be a defined value. This helps to delurk some insidious errors. Uncaught exception from user code: Can't use an undefined value as a HASH reference at /usr/share +/perl5/vendor_perl/SES.pm line 559. SES::call_ses('HASH(0x243cc00)', 'HASH(0x26a2138)') called at +/opt/aws/apitools/ses/bin/ses-get-stats.pl line 168
    Should I abandon $self and just call the subs like I did in the working version? Thanks to the Monastery for all the years of saving my butt as I stumbled through PERL.

      $self as the first parameter of a subroutine is required if - and only if - the subroutine is called as an object or class method, and the name "self" is just a convention for the object or class the method operates on. You did not provide the code how you're calling call_ses and the only reference I found for your module is that aws-apitools have been deprecated as of 2015. Perhaps you might want to have a look for CPAN modules which provide an interface to SES, like e.g. Net::AWS::SES or Paws::SES?

        Apologies, I should have noted the code being used to call call_ses is the same code as in the original post. I am looking at modules but rewriting this isn't really an option, it's a legacy system that is failing now due to the AWS signature version change from 3 to 4. I'm just trying to get it to send the Signature V4 header instead of the V3.

      Further to haj's reply ...

      According to the code examples posted so far in this thread, SES::call_ses does not appear to be a method of the SES class, so assigning to a $self variable, which is, by convention, usually used to denote an object reference to or the class name of a class method, makes no sense.

      In the invocation
          my ($response_code, $response_content) = SES::call_ses \%params, \%opts;
      \%params is not a bless-ed reference (i.e., an object reference) of any kind, so don't treat it as such in a call to $self->AWS_endpoint in the

      sub call_ses { my $self = shift; ... my $endpoint_name = $self->AWS_endpoint; }
      function.

      SES::call_ses seems to be an ordinary subroutine defined in the SES package. This subroutine does not seem to be exported, so it must be invoked via the fully-qualified SES::call_ses syntax. According to the error message, this subroutine was called with two arguments, so shifting three arguments off of the @_ argument array will leave someone holding an undefined bag. Don't do that.


      Give a man a fish:  <%-{-{-{-<

        Thanks Haj for the breakdown.
      Thanks to the Monastery for all the years of saving my butt

      Welcome back, jmccall! ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11131554]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-03-29 08:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found