Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Code from PHP to Perl

by remya (Initiate)
on May 04, 2013 at 06:39 UTC ( #1031998=perlquestion: print w/ replies, xml ) Need Help??
remya has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am using the following php code for posting paypal IPN to some url(postAffiliatePro).
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://affiliate.frankstrade.com/plugin +s/PayPal/paypal.php?pap_custom=".$_GET['pap_custom']); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST); curl_exec($ch);
Can anyone please help me to change this into perl... Please Help... thanks Remya

Comment on Code from PHP to Perl
Download Code
Re: Code from PHP to Perl
by Anonymous Monk on May 04, 2013 at 06:52 UTC
    No thanks, try stackoverflow
Re: Code from PHP to Perl
by Corion (Pope) on May 04, 2013 at 08:05 UTC

    Where exactly do you have problems changing the code to Perl? What have you tried so far? Have you looked at what CPAN has to offer? Paypal, Curl...

Re: Code from PHP to Perl
by tobyink (Abbot) on May 04, 2013 at 10:47 UTC
    use v5.12; use HTTP::Tiny; # Some empty hashes. I'll leave populating them with # the correct data as an exercise for the reader. my %_GET = (); my %_POST = (); my $url = "http://affiliate.frankstrade.com/plugins/PayPal/paypal +.php?pap_custom=$_GET{pap_custom}"; my $response = "HTTP::Tiny"->new->post_form($url, \%_POST); if ($response->{success}) { say $response->{content}; } else { warn $response->{reason}; }
    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
Re: Code from PHP to Perl
by roboticus (Canon) on May 04, 2013 at 17:02 UTC

    remya:

    You need only change your square brackets to curly brackets to turn it into valid perl code. Of course, you'll also need the appropriate constants and subroutines:

    $ cat php_2_perl.pl #!/usr/bin/perl -w use strict; use warnings; use constant { CURLOPT_URL => 0, CURLOPT_POST => 0, CURLOPT_POSTFIELDS => 0, }; sub curl_init { print "Need to write curl_init\n"; } sub curl_setopt { print "Need to write curl_setopt\n"; } sub curl_exec { print "Need to write curl_exec\n"; } my ($ch, %_GET, $_POST); $_GET{pap_custom} = 5; # your code appears to be valid perl, given appropriate constant and # subroutine definitions... $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://affiliate.frankstrade.com/plugins/PayPal/paypal.php?pap_cu +stom=" . $_GET{'pap_custom'}); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST); curl_exec($ch); $ perl php_2_perl.pl Need to write curl_init Need to write curl_setopt Need to write curl_setopt Need to write curl_setopt Need to write curl_exec

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: Code from PHP to Perl
by sundialsvc4 (Abbot) on May 04, 2013 at 20:47 UTC

    Okay, gentlepeople, let’s try to seriously answer this poor bloke’s question.   (After all, (s)he has finally seen the light!)

    In the PHP language, “everything but the kitchen sink” is built in to the PHP executable at compile-time ... so the executable is “big and phat, but self-contained.”   Per contra, in the Perl environment, the executable is relatively small.   (On my computer right now, for example, /usr/bin/php is 32.2 megabytes, whereas /usr/bin/perl weighs in a svelte 86K.)  

    So, where does the needed functionality come from?   From external modules, such as this one:   Net::Curl.   Start by clicking on this examples-link ... Net::Curl::examples.   Most of what you see here should seem very familiar.

    As the case may be, you might find that this module is already installed, or you might have to install it.   That’s fine:   if you need it, you can install it ... not megabytes of kitchen-sink that you don’t.

    If you do as suggested and search for Curl at http://search.cpan.org, you’ll find 181 modules that support Curl.   But, can we do better than that?   Yes, we can.   Search for what you want to achieve... PayPal (130 hits), or PayFlowPro (7 hits).

    This is the most-significant difference between the PHP approach and the Perl approach:   the kernel of Perl is almost microscopic by comparison, but the scope of the CPAN library is vast:   90,429 Uploads; 27,446 Distributions; 120,905 Modules; 10,605 Uploaders as of today.   And these are often very specific ... very close to where you actually want to be, such as (say...) Business:PayPal::API.   Instead of trying to figure out, “how do I write this?” ... you instead start with, “I presume that I don’t have to write this at all, because somebody out there most likely already did.”

    PHP.   Perl.   (And all the rest ...)   Different tools, all good, and all very different.   Nearly all of us, use all of them, all the time, but ... Come closer, and check out this world called Perl.   Come see what all the fuss is about.   See for yourself why so many of us return to this tool again and again.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2014-12-25 17:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (161 votes), past polls