sub tt { my( $cookie, $param ) = @_; my $str = '(' . (defined $cookie ? $cookie : 'undef'); $str .= ',' . (defined $param ? $param : 'undef') . "):\t"; $str .= $cookie # I quickly realized it was necessary to test this here ? ( ( $param and $param =~ /^\d{1,2}$/ ) ? $param : $cookie ) # and I had to place a few more parens #: ( $param ? ($param and $param =~ /^\d{1,2}$/) : 5 ); # UPDATE: the above line was horribly translated from Grandfathers. # It is corrected below, which also works when the same nested # ternary idea (substituting /^\w{1,6}$/ for example) is used to # parse textual data. : ( ( $param and $param =~ /^\d{1,2}$/ ) ? $param : 5 ); # END UPDATE $str .= "\n"; return $str; } print tt( 4, 3 ); print tt( 4, 333 ); print tt( 444, 333 ); print tt( 2, undef ); print tt( undef, 1 ); print tt( undef, undef ); #### (4,3): 3 (4,333): 4 (444,333): 444 # famous last words, but "this can never happen" ;) (2,undef): 2 (undef,1): 1 (undef,undef): 5 #### $/ = q#(\w)# ; sub sig { print scalar reverse join ' ', @_ } sig map { s$\$/\$/$\$2\$1$g && $_ } split( ' ', ",erckha rlPe erthnoa stJu" );