[Israel.pm] A question of style - print()

Madani, Srikanth, VF-DE Srikanth.Madani at vodafone.com
Wed Oct 19 04:36:33 PDT 2005


Thanks Dov and Gaal for your input.

Gaal Yahas wrote on Mittwoch, 19. Oktober 2005 12:15

> print <<"END_WARNING";
> 
> $0: Warning - couldn't find alias $emails in $EmailAliases
> Alias $emails cannot be resolved - no email will be sent
> 
> Please contact file owner to update your desired group in 
> $EmailAliases.
> END_WARNING


I guess the only case where this construct will not be the optimal one
is when I wish to print text on a single line on STDOUT (or whereever),
but this text is wrapped inside the script (because of identation, Perl
keywords like print etc.) and I would like to format it better. Here's
an example of code, where my desired on-screen output is:

./temp.pl generates a version specific core domain change report from
the appropriate synchronization log file.

(It fits all on one line)

sub ParseCommandLine() {
        if (!defined($ARGV[0])) {
                print "$0 generates a version specific core domain
change report from the appropriate sync
hronization log file.\n"; 


(The line is broken in the middle of "synchronization" because that's
where my text editor choses to wrap)

As suggested, I tried:

sub ParseCommandLine() {
        if (!defined($ARGV[0])) {
                print <<"DESC";
                        $0 generates a version specific core domain
change report from the appropriate
                        synchronization log file.\n
DESC

However, this adds an extra newline (after "appropriate") AND (like Gaal
mentioned) script indentation is treated as significant whitespace; the
output is:

                        ./temp.2.pl generates a version specific core
domain change report from the appropriate
                        synchronization log file.


I wasn't able to try the Perl 6 example.


I tried my idea:

sub ParseCommandLine() {
        if (!defined($ARGV[0])) {
                print "$0 generates a version specific core domain
change report from the appropriate ",
                        "synchronization log file.\n";


just to have a better look, and this works fine:

./temp.pl generates a version specific core domain change report from
the appropriate synchronization log file.

Of course, if the text window is resized, all identation will be appear
skewed.


Best regards,
Srikanth Madani




More information about the Perl mailing list