in reply to Re: chopping a string into slices - is there a more elegant way to do it?
in thread chopping a string into slices - is there a more elegant way to do it?

talking about elegance

IMHO additional parentheses improve the readability, emphasizing that the match-op is evaluated in a list-context. *

@a = ( "abcdefg" =~ /.{1,$ml}/g ) ;
or alternatively an extra newline
@a = "abcdefg" =~ /.{1,$ml}/g ;
well maybe a matter of taste ...

* UPDATE: well it's not evaluated in list-context, but it empasizes the order of evaluation, making it IMHO more readable..

Replies are listed 'Best First'.
Re^3: chopping a string into slices - is there a more elegant way to do it?
by JavaFan (Canon) on Nov 04, 2008 at 16:54 UTC
    IMHO additional parentheses improve the readability, emphasizing that the match-op is evaluated in a list-context.
    That's a really bad reason to use parenthesis, because they do NOT provide list context. Compare:
    $a = ("abcdefg" =~ /.{1,$ml}/g);
    Here parenthesis are used, but the match is in scalar context.
      UPDATE:(Dec 1. 2008) further down the thread I admit and show that I was wrong in this node! No need to discuss it further I don't think so, IMHO you are getting at first hand a list which is later reevaluated in scalar context!

      ... I'll run some tests to find the "truth" ; )

      UPDATE: I think your example is equivalent to

      my @a= ( $str =~ /.{1,$ml}/g ) ; $a=scalar @a; print $a;
      nevertheless is =~ evaluated in list-context!

        It's not in that one case either. Except when empty, parens never do more than control precedence. Except when empty, they never create a list context.

        It's almost always used with lists because "," has very low precedence, but it's the commas that create the list, not the parens.

        I apologize, you were right!
        $a= ( test() ); print $a; #> 9 sub test { return (1,2) if wantarray; return 9; }
        the paranthesis don't force list context, they seem to be interpreted for the precedence of the lexer!