So, I'm working with data lines which end with a return code and an optional non numeric message code. What I have so far is
No problem with that, it works but why can't I use
or
Both of those always set retcode to $bits[-2]. An explanation would be greatly appreciated.
Thanks.
On the internet no one knows you're a dog
Columb Healy
Code:
my @bits = split /\s+/;
if ( $bits[-1] =~ /^\d+$/ )
{ $retcode = $bits[-1]; }
else
{ $retcode = $bits[-2]; }
Code:
my @bits = split /\s+/;
$bits[-1] =~ /^\d+$/ and $retcode = $bits[-1] or $retcode = $bits[-2];
Code:
my @bits = split /\s+/;
$bits[-1] =~ /^\d+$/ ? $retcode = $bits[-1] : $retcode = $bits[-2];
Both of those always set retcode to $bits[-2]. An explanation would be greatly appreciated.
Thanks.
On the internet no one knows you're a dog
Columb Healy