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
The use of comma in your print statement works exactly the same.
Consider:
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 $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
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.#!/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
|
|---|
| 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 | |
by Marshall (Canon) on Jun 01, 2017 at 18:30 UTC | |
|
Re^9: writing two files (different in length) to one output
by LanX (Saint) on May 31, 2017 at 00:39 UTC |