in reply to Format / Logical Expression / Style Opinions: my, ternary, subroutine, @_

I find it almost completely unreadable, and disagree vehemently with PBP's suggestion that nested ternaries are anything other than a horrible idea.

I can think of no good reason why this simple functionality should be written so tersely, when a more sensible approach takes up almost the same amount of space.

sub xyz { my ( $ttt, $xxx, $yyy ); ( $xxx, $yyy ) = @_ if @_ == 2; ( $ttt, $xxx, $yyy ) = @_ if @_ == 3; croak 'Not good' unless $xxx and $yyy; }

As a tangent, I'd also consider thinking about why you have a sub where the first parameter is optional -- it's a lot easier if optional parameters go on the end.

Replies are listed 'Best First'.
Re^2: Format Style Opinions: my, ternary, subroutine
by jffry (Hermit) on Dec 04, 2007 at 18:37 UTC

    friedo wrote:
    > ...consider thinking about why you have a sub where the first parameter is optional...

    Because it is a wrapper for a command. Suppose the command was ls. It would be convenient to call the sub, thus:

    ls('-lrt', '/home');

    Does this convenience not outweigh breaking from the convention that optional args go last?

      My first thought is "If it's good enough for system, it's good enough for me"

      $ perl -e 'system("ls", "/home/brian");' # ... my stuff $ perl -e 'system("ls", "-lrt", "/home/brian");' # ... my stuff