in reply to Snippet explanation please

In English: If the string $args{DOUBLE_BYTE} has a 'y' or 'Y' in it, sets $tempport to the constant DB_CATPORT, otherwise sets it to SB_CATPORT.

In Perl:
my $tempport; # declare var if( $args{DOUBLE_BYTE} =~ /y/i ) # try to match with a regex # regex is just looking for 'y' # the /i means case-insensitive { $tempport = DB_CATPORT; # Set to DB_CATPORT } else { $tempport = SB_CATPORT; # Set to SB_CATPORT }
The key uses here are the regex (perldoc perlre) and the ternary operation (perldoc perlop).

Update: Note that $args{DOUBLE_BYTE} represents the value in the %args hash for key 'DOUBLE_BYTE'. (though i guess DOUBLE_BYTE could be a constant, in which case the key is really the constant's value.) Update: thanks Errto! Note to self: don't overthink.

Replies are listed 'Best First'.
Re^2: Snippet explanation please
by Errto (Vicar) on Jul 04, 2005 at 21:37 UTC
    (though i guess DOUBLE_BYTE could be a constant, in which case the key is really the constant's value.)
    Actually, it's not:
    use constant a => 'b'; my %foo; $foo{a} = "x"; print keys %foo; __END__ a
    By that logic, it should print 'b' instead. Remember, "constants" in Perl are really just subroutines, not C-style macros. The rule that a bareword as a hash key is always treated as a string applies whether or not there's a subroutine or constant with that name defined.