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

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.

Replies are listed 'Best First'.
Re^9: writing two files (different in length) to one output
by hippo (Archbishop) on May 31, 2017 at 07:29 UTC
    while ( (print "Prompt: "), $line=<STDIN>, $line !~ /^\s*Q(uit)\s*$/i )

    Having spent 5 minutes looking at this one line I'm still stumped as to the purpose of the capture group in the regex. Can you explain the purpose? ie. why would /^\s*Quit\s*$/i not perform exactly the same in your given code (since you have not subsequently referred to the captured data)? Thanks.

      You spotted a missing ? to make (uit) optional. Should be:
      while ( (print "Prompt: "), $line=<STDIN>, $line !~ /^\s*Q(uit)?\s*$/i + )
      That way both the single letter q,Q or the full word Quit works. I just made a typing goof and didn't fully test, otherwise I would have seen that a simple "q" didn't work.
Re^9: writing two files (different in length) to one output
by LanX (Saint) on May 31, 2017 at 00:39 UTC
    Round #n+1 ;)

    As a side note, I think you can always use do {cmd;cmd } when you want to avoid cmd,cmd

    Update: nice trick with the while statement! :)

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