On Thursday, Nov 20, 2003, at 12:18 US/Pacific, Jeff Kowalczyk wrote:
I'm not yet able to read certain parts of perl code. What is this
comparison/alternation after the hash lookup on 'otherid' called, and what
does the code do?
$myvar->{id} = ($myvar->{otherid}) ? 'stringA' : 'stringB';
it is short for
if ($myvar->{otherid})
{
$myvar->{id} = 'stringA';
}else{
$myvar->{id} = 'stringB';
}so you too might like Data::Dumper and go with a short script like:
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
# #FILENAME# - is for
my $myvar = { otherid => 'bob', id => 'alice' };
print Dumper $myvar ;
$myvar->{id} = ($myvar->{otherid}) ? 'stringA' : 'stringB';
print Dumper $myvar ;
delete $myvar->{otherid};
$myvar->{id} = ($myvar->{otherid}) ? 'stringA' : 'stringB';
print Dumper $myvar ;which generates
$VAR1 = {
'otherid' => 'bob',
'id' => 'alice'
};
$VAR1 = {
'otherid' => 'bob',
'id' => 'stringA'
};
$VAR1 = {
'id' => 'stringB'
};ciao drieux
---
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
