Convert perl script to php

Asked

Viewed 116 times

0

I have a perl script working right and a script in php tbm working right.

the only difference between the 2 is that my perl file has a command that makes a Return to the other script that calls it , and my php doesn’t have that, I need to know how to do in php a Return similar to this. Below are the details:

Part of the script that generates variables to send to the Return function

foreach (split(/\n/,$uaresponse->content)) {
        my $jdata = decode_json($_);
        for ( $jdata->{result}[0]->{alternative}[0] ) {
                $response{utterance}  = encode('utf8', $_->{transcript});
                $response{confidence} = $_->{confidence};
        }
}
warn "$name The response was:\n", $uaresponse->content if ($debug);

foreach (keys %response) {
        warn "$name Setting variable: $_ = $response{$_}\n" if ($debug);
        print "SET VARIABLE \"$_\" \"$response{$_}\"\n";
        checkresponse();
}

Perl script that gives Return

 sub checkresponse {
        my $input = <STDIN>;
        my @values;

        chomp $input;
        if ($input =~ /^200 result=(-?\d+)\s?(.*)$/) {
                warn "$name Command returned: $input\n" if ($debug);
                @values = ("$1", "$2");
        } else {
                $input .= <STDIN> if ($input =~ /^520-Invalid/);
                warn "$name Unexpected result: $input\n";
                @values = (-1, -1);
        }
        return @values;
}

I tried to do this here in php but evidently it’s not so because it didn’t work.

$return = '("'.$resposta.'", "'.$result['sessionId'].'", "'.$andamento.'")';

return $return;

note that in perl I am returning 2 variables but with the need to modify the system I made a php that returns 3 arguments to work the way I need

Note: I am using php 5.1.6 on this server and centos 5.11

could someone help me ? I am grateful des already your attention

1 answer

0

arroba in front of the perl variable is nothing more than an array, so it would look something like this:

<?php

function checkresponse(){
    $input = "200 result=55 abc";

    $values = array();

    if(preg_match("/^200 result=(-?\d+)\s?(.*)$/", $input, $matches)){
        array_shift($matches);
        $values = $matches;
    } else {
        $values = array(-1, -1);
    }


    return $values;



}

print_r(checkresponse());



?>
  • humm I will test thank you

  • look I still can’t because I didn’t understand with my perl script returns the data . i did the php scritp do q it does but the perl script somehow passes it to the main script and I don’t know how

Browser other questions tagged

You are not signed in. Login or sign up in order to post.