in reply to how to write a modified return() call?

The following would be more readable.
my $start_with = another_value() or ( warn("Could not get another value"), return );
It hides the return at the end of the line, so you could break the lines.
my $start_with = another_value() or ( warn("Could not get another value"), return );

Replies are listed 'Best First'.
Re^2: how to write a modified return() call?
by JavaFan (Canon) on Jul 14, 2009 at 14:51 UTC
    I don't find that very readable. It makes me wonder whether the parens are a list, or whether they are just there for precedence. And it makes me wonder if perl couldn't evaluate the return before the warn.

    I would write it as:

    my $start_with = another_value or do { warn "Could not get another value"; return; };
    Alternatively,
    do { warn "Could not get another value"; return; } unless my $start_with = another_value;
    but that focusses on the exception, not on the action, so I'll be far less likely to write it that way.
      wow! I can't imagine why you're so afraid of using ",". You need to use it for just about every function call!

        Maybe you and JavaFan just have different preferences for coding style? I don't think he was criticizing you as much as stating what works for her/him.

        I also doubt you meant to come across as belittling, but "why you're so afraid..." does have that effect to some ears, even those who want to give you the benefit of the doubt.

        Best, beth

Re^2: how to write a modified return() call?
by leocharre (Priest) on Jul 14, 2009 at 18:51 UTC

    Thank you, this is useful!

    Two questions.. One on topic and one off topic.

    1. You say..
      my $start_with = another_value() or ( warn("Could not get another value"), return );
      Why not..
      my $start_with = another_value() or warn("Could not get another value"), return;
      Or even
      my $start_with = another_value() or warn "Could not get another value", return;
      I tried these out and they seem to work fine. I suppose it's maybe trying to mess with the compiler/interpreter being vague with arguments to warn(), in the last example.

      Are you using parenthesis as good practice/legibility only?

    2. It seems that unless I want to create my own perl distro, there's no way to do as JavaFan suggests ( 779943 ).

      Perl's pretty freaking liberal with what it lets you do with symbol tables, but.. we can't just add another function to the language at compile time.

      I wonder if this is something lisp could do- probably not- this must be on the language design (compiler/interpreter) level, not the coding level (?).
      ( Actually, as Corion noted initially.. 779928 )

      Why not..

      I didn't check the relative precedence of "or" and ",". I also liked the visual grouping.

      Or even

      No, it doesn't work. It returns before evaluating warn.

      It seems that unless I want to create my own perl distro, there's no way to do as JavaFan suggests

      What JavaFan suggested works as is. If you mean to make it pretty... The best way probably would require language-level support.

      we can't just add another function to the language at compile time

      I guess it depends on what you mean by function. Out of context, I'd say that's not true.