XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).
Moderator: General Moderators
-
chaser010
- Forum Newbie
- Posts: 7
- Joined: Thu Jun 21, 2007 8:20 am
Post
by chaser010 »
How will the following PHP code look like in PERL?
Code: Select all
foreach ($arrResults as $result)
{
print_r(explode('||', $result));
echo("<br />");
}
=======================
This is what I have, but its not working.
Code: Select all
@result_array = $result;
foreach $line ( @result_array )
{
$line2 = split('\|\|', $line);
print "$line2\n";
}
-
chaser010
- Forum Newbie
- Posts: 7
- Joined: Thu Jun 21, 2007 8:20 am
Post
by chaser010 »
Thank you for your reply, but is doesn't work:
$VAR1 = 'ARRAY(0x8627d24)';
<br />
-
volka
- DevNet Evangelist
- Posts: 8391
- Joined: Tue May 07, 2002 9:48 am
- Location: Berlin, ger
Post
by volka »
Works fine for me.
$VAR1 = 'a';
$VAR2 = 'b';
<br />
$VAR1 = 'c';
$VAR2 = 'd';
$VAR3 = 'e';
<br />
$VAR1 = '';
$VAR2 = 'f';
<br />
Your @result_array probably isn't an array of strings. But how would I know.
-
chaser010
- Forum Newbie
- Posts: 7
- Joined: Thu Jun 21, 2007 8:20 am
Post
by chaser010 »
It returns a one-dimensional array. Each array element is a string.
I am using Soap::Lite to call a function and then get a result back that I am unable to read using Perl.
-
volka
- DevNet Evangelist
- Posts: 8391
- Joined: Tue May 07, 2002 9:48 am
- Location: Berlin, ger
Post
by volka »
chaser010 wrote:It returns a one-dimensional array. Each array element is a string.
But the array in my example also is an one-dimensional array of strings, no?
What does
print?
-
chaser010
- Forum Newbie
- Posts: 7
- Joined: Thu Jun 21, 2007 8:20 am
Post
by chaser010 »
Excellent!!
$VAR1 = [
'Result||-1',
'TransactionIndex||sdds-we-2334-dsf2-sdfdsf',
'AcquirerDateTime||2007/06/22 12:28:20 PM'
];
I will need to use some of the return results, any idea how to asign the values?
-
volka
- DevNet Evangelist
- Posts: 8391
- Joined: Tue May 07, 2002 9:48 am
- Location: Berlin, ger
Post
by volka »
ah, the square brackets indicate an array reference not an array (did I mention I never got comfortable with perl?)
Code: Select all
use Data::Dumper;
$a = [ # note the $a instead of @a
'Result||-1',
'TransactionIndex||sdds-we-2334-dsf2-sdfdsf',
'AcquirerDateTime||2007/06/22 12:28:20 PM'
];
foreach $l ( @$a ) { # note the @$a
print Dumper(split('\|\|', $l)), "\n";
}
-
chaser010
- Forum Newbie
- Posts: 7
- Joined: Thu Jun 21, 2007 8:20 am
Post
by chaser010 »
Thank you for all your help!
It works!!!!!
-
chaser010
- Forum Newbie
- Posts: 7
- Joined: Thu Jun 21, 2007 8:20 am
Post
by chaser010 »
One more thing.
If I just want the value of TransactionIndex and Result assigned to different variables?
At the moment the Dumper prints the following:
$VAR1 = 'Result';
$VAR2 = '-1';
$VAR1 = 'TransactionIndex';
$VAR2 = '929dwe-23djs-ds2dsd-234sddw';
-
volka
- DevNet Evangelist
- Posts: 8391
- Joined: Tue May 07, 2002 9:48 am
- Location: Berlin, ger
Post
by volka »
Code: Select all
use Data::Dumper;
$a = [ # note the $a instead of @a
'Result||-1',
'TransactionIndex||sdds-we-2334-dsf2-sdfdsf',
'AcquirerDateTime||2007/06/22 12:28:20 PM'
];
%hash = map { split('\|\|', $_) } @$a;
print 'Result: ', $hash{Result}, "\n";
print 'TI: ', $hash{TransactionIndex}, "\n";
ask me in a month and i won't understand the code

-
chaser010
- Forum Newbie
- Posts: 7
- Joined: Thu Jun 21, 2007 8:20 am
Post
by chaser010 »
Thank you!!
That did the trick!
