Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

php arrays to perl

by bigup401 (Pilgrim)
on May 16, 2017 at 11:17 UTC ( [id://1190365]=perlquestion: print w/replies, xml ) Need Help??

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

am confused about perl arrays and php arrays. where by am making post request and the server still failed to understand my post data in array. it only understand php array data

how can i make similar in perl

#php $data = array( 'text1': 'text', 'text2': 'tes1', 'text3': 'tes2', );

Replies are listed 'Best First'.
Re: php arrays to perl
by tobyink (Canon) on May 16, 2017 at 11:45 UTC

    You probably want to use a hash in Perl, not an array.

    my %data = ( text1 => 'text', text2 => 'tes1', text3 => 'tes2', );

    Also, your PHP syntax is wrong. Those colons should be => like in Perl.

Re: php arrays to perl
by Corion (Patriarch) on May 16, 2017 at 11:28 UTC

    If you want to create HTTP posts, it is always quite instructive to look at the actual data that gets sent over the wire, regardless of the program(ming language) that generates the data.

    So, please look at the data that the PHP program sends to the remote end. It likely is not too hard to create similar data from within Perl, but without a specification things are much harder.

      well, it says missing data text1. thats the problem it cant get text1 data

      my $ua = HTTP::Tiny->new; my $url = "link"; my $param = { text1 => 'text0', text2 => 'text01', text3 => 'text02', }; my $params = $ua->www_form_urlencode( $param ); my $response = $ua->post( $url . '/?' . $params );

        You are trying to send POST data like it was GET data.

        Try this:

        my $ua = HTTP::Tiny->new; my $url = "link"; my $param = { text1 => 'text0', text2 => 'text01', text3 => 'text02', }; my $response = $ua->post_form($url, $param);

        In my previous reply I gave you very concrete steps to follow to investigate where the cause of your problems lies:

        1. So, please look at the data that the PHP program sends to the remote end.

        Which of these steps have you followed, and what were the results?

        What were the problems you encountered when trying the steps?

        Please try the steps again and report the exact results.

Re: php arrays to perl
by Discipulus (Canon) on May 16, 2017 at 11:29 UTC
    well .. mmh.. Perl variable types are described in the very basic doc

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-19 03:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found