Bloehdian has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

the following script should send an http-request to httpbin.org. But it fails with the creation of the proper request string, probably since the script interprets it as a sequence of namespaces separated in the old style using apostrophe. What am I doing wrong?

#!/usr/bin/perl use strict; use REST::Client; my $client = REST::Client->new(); my $request=q{DELETE('https://www.httpbin.org/delete')}; print $request; eval( $client->$request ); print $client->responseCode();

Execution leads to the following

Can't locate object method ")" via package "DELETE('https://www.httpbin.org/delete" (perhaps you forgot to load "DELETE('https://www.httpbin.org/delete"?) at test.pl line 7.

Replies are listed 'Best First'.
Re: Problem creating http request string using apostrophe
by LanX (Saint) on Dec 14, 2017 at 00:49 UTC
    My guess

    $request is not interpolated, the whole string is considered to be a method name.

    You could wrap it into doublequotes "..." to create meaningful code-text

     eval( "\$client->$request" )

    (Untested)

    but I see your approach a bit critical, why not simply

    $client->DELETE($url)

    without any eval?

    And if you need to keep the method flexible try

    $client->$method($url)

    (Untested again)

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Wikisyntax for the Monastery