in reply to Re^2: 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?

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.
  • Comment on Re^3: chopping a string into slices - is there a more elegant way to do it?
  • Download Code

Replies are listed 'Best First'.
Re^4: chopping a string into slices - is there a more elegant way to do it?
by LanX (Saint) on Nov 04, 2008 at 17:11 UTC
    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.

        thanx, actually I knew this once ... : (

        But in my example they do no harm, just emphasizing the right-to-left priority auf the evaluation. My explanation anyway was wrong!

        Anyway: I'm a great fan of the syntactical cleansing in Perl 6 and longing to use it ASAP, with or without parrot!

        UPDATE: You know, sometimes Perl-syntax is like "fizzbin" - the card game Kirk invents on the Mob planet

        > Except when empty, parens never do more than control precedence. Except when empty, they never create a list context.

        And what about ($a)=@_; ???

        Unfortunately, it's not that easy!

        Cheers Rolf

        PS: Just Another example of perl-Fizzbin! ; )

      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!