in reply to Re^4: writing two files (different in length) to one output
in thread writing two files (different in length) to one output

> Again, list context is needed..

of course you are right, that's the punishment for not using strictures. :)

Just one nitpick: the benefit of parens here is technically not "list context" but precedence.

my has a higher precedence than comma, to allow other constructs like (my $a,my $b) =...

Maybe the perldoc should be clearer writing my (VARLIST) like in the doc of chomp (LIST)

> the number of source code lines does not equate directly into actual "code savings

Of course not, my intention here was readability.

It's right away obvious that both files are treated symmetrically, if the code is aligned in 2 dimensions.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^6: writing two files (different in length) to one output
by Marshall (Canon) on May 30, 2017 at 22:31 UTC
    The use of "precedence" instead of "list context" is better. Thanks for the clarification!

    As to whether or not the comma operator is more readable in this situation, I leave that to the reader(s) to decide. My C background enables me to easily understand this construct, but many folks here may not find that "readable".

    I think we are "drilling way down into the dirt here". The main point that is important here is testing of eof instead of !defined. I personally declare this thread a "success". Been "beat to death" and a definite, informative, high-performance, clear answer has been arrived at.

      I share your doubts about using comma in void context to separate commands like semicolon does, I only do it in exceptional cases.

      OTOH it's not too different of comma's behavior in list context

       print sqrt($i), $i, $i**2;

      just without returning the results.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

        Geez, ok, round #n

        The use of comma in your print statement works exactly the same.
        Consider:

        #!/usr/bin/perl use strict; use warnings; my $i = 3; # $i is not modified in this print statement: print sqrt($i), $i, $i**2; # 1.7320508075688839 ## 1.73205080756888 3 9 # $i is modified and new value of $i is used: print sqrt($i), --$i, $i**2; # 1.7320508075688824 ## 1.73205080756888 2 4
        I like the comma statement when it simplifies a loop, an example is a loop that prompts for an input:
        #!/usr/bin/perl use strict; use warnings; my $line; while ( (print "Prompt: "), $line=<STDIN>, $line !~ /^\s*Q(uit)\s*$/i +) { $line =~ s/^\s*//; $line =~ s/\s*$//; print"xyzzy \"$line\" and nothing happens\n"; } print "Some version of QUIT, QuIt, quit entered\n"; __END__ C:\Projects_Perl\testing>perl simplecommandline.pl Prompt: 123 xyzzy "123" and nothing happens Prompt: abc xyzzy "abc" and nothing happens Prompt: 123 abc xyzzy "123 abc" and nothing happens Prompt: qui xyzzy "qui" and nothing happens Prompt: quit doing that! xyzzy "quit doing that!" and nothing happens Prompt: QUiT Some version of QUIT, QuIt, quit entered
        Without the use of the comma statement in the while() statement, there has to be a "prompt" printed before the loop starts and a "prompt" must also be printed within the loop to "keep the loop going". The comma statement allows: a)ask for input, b)get input, c)test input all in one syntactically correct single statement. The "truthfulness" of a comma statement only rests upon the very last clause. This comma statement idea should be used sparingly. Very sparingly. I think we agree upon that.