Return multiline $AGI->get_variable('CURL') value -- how?

I have an AGI application that queries a web app and uses it response. The web response contains newline characters, so when I do this:

my $returnval = $agi->get_variable(‘CURL’);

I always get only the first “line” back (which is empty), which I assume is because the first line of the web’s response is a NEWLINE character.

I know that my call to curl is working fine, and on the console I start debug and see this:

AGI Rx << EXEC Curl myhost:8080/LookupByPhone/do/loo … 6105551212
AGI Tx >> 200 result=0
AGI Tx >> 200 result=1 (




If I substitue a call to a static text file on the webserver, instead of the webapp, the value of $returnval is the first line of the file, and if I put into the file a single line containing any data, things work. So I know that the problem involves the fact that the response has more than one line, with newline characters.

My question is how do I get the CURL field value into a Perl variable so that I may work with it? I’m no Perl guru, but it appears to me that I can’t assign a string with embedded newlines to a scalar via “$AGI->get_variable”.

I’d really appreciate a tip on how to get the message in its entirety to a field so that I can work with it. I already know how to take it from that point on.

Thanks for any assistance you may offer.


you’re going to need to chop/chomp the string up until you get the piece you want (not sure how you decide from that example) and return that.

Thanks for the reply!

I guess that this is where I’m really getting confused. I have seen numerous examples of chomp<> in action, but they almost always involve a file handle that would be expected to return line after line on demand.

In my case, I’m using $agi->exec(‘curl’ ‘myurl’); which causes the CURL variable to be set for the channel. Then, I use "$agi->get_variable(‘CURL’) to retrieve the value set by curl, which includes all lines. If I build a loop around a result like so:

my $target = $agi->get_variable(‘CURL’);
while ( $target = chomp($target) ) {
$agi->verbose( $target );

I get but one pass – an empty string. Will the get_variable function return the entire original value (all lines) or will it only return the substring through the newline character?