Is there a better way to it than this?
$_ .= "\n" for @ARGV;
This may or may not be of use to you, but it might be handy to
learn about Perl's "-l" switch.
If a Perl script begins with a line like:
#!/usr/bin/perl -l
(or if a script is invoked with "perl -l script.pl"), then two things
will happen:
1. The newline will be automatically stripped from any
input read with the <...> operator.
2. The newline will automatically be printed with every
call to print().
This switch is handy if anyone wants to, say, add a certain string
to the end of lines of input, but before their newlines.
For example, let's say that you wanted to add "!!!" to the end of
each line of input that you process (but before the newline). A
programmer who is not aware of the "-l" switch might write a script
like this:
#!/usr/bin/perl
use strict;
use warnings;
while (<>)
{
chomp; # remove the newline
$_ .= "!!!"; # append the "!!!" string
print "$_\n"; # print the line with a newline
}
__END__
or perhaps as a one-liner, like this:
perl -pe 'chomp; $_ .= "!!!\n"'
In each case, the programmer has to explicitly remove the newline
(done here with chomp()) and add it back in later.
However, a programmer who knows about the "-l" switch might write a
script like this:
#!/usr/bin/perl -l
use strict;
use warnings;
while (<>)
{
$_ .= "!!!"; # append the "!!!" string
print;
}
__END__
or perhaps as a one-liner, like this:
perl -lpe '$_ .= "!!!"'
Of course, this switch works well only if you don't mind that the
newline is always stripped out or that the newline is always printed
with the print() function. So don't use it if this poses a problem
for you.
I hope what I said was clear.
-- Jean-Luc