W
wana
Is there a better way to it than this?
$_ .= "\n" for @ARGV;
wana
$_ .= "\n" for @ARGV;
wana
Is there a better way to it than this?
$_ .= "\n" for @ARGV;
ASU> (e-mail address removed) (wana) wrote in
ASU> @posting.google.com:
ASU> Of course. Read perldoc -f chomp.
and how would chomp append newlines?
w> Is there a better way to it than this?
w> $_ .= "\n" for @ARGV;
s/for/x/ ;
uri
Is there a better way to it than this?
$_ .= "\n" for @ARGV;
w> Is there a better way to it than this?
w> $_ .= "\n" for @ARGV;
ASU> I am confused.
untested as always. must have been too late at night. i didn't see the
$_ being aliased to the elements of @ARGV.
A. Sinan Unur said:Of course. Read perldoc -f chomp.
Is there a better way to it than this?
$_ .= "\n" for @ARGV;
James Willmore said:Maybe ...
#append a newline to each element in @ARGV
$_ = join("\n", @ARGV);
(one liner)
perl -e '$_ = join("\n", @ARGV);print "$_\n";' 1 2 3
If all you want to do is append a newline to each element of @ARGV, then
'join' is probably the best way to do it ...but, of course, TMTOWTDI
Hue-Bond said:Paul Lalli, Thu20041118@14:07:40(CET):
Then what about:
@ARGV = map { $_ . "\n" } @ARGV;
Uri Guttman said:ASU> It would not. But it would explain what one needs to do to write an
ASU> 'antichomp'.
ASU> So, "the antichomp" would have to do the opposite of what chomp does,
ASU> wouldn't it?
but that isn't an antichomp. it is appending a newline it over and over
to a single string. and writing an antichomp for such a simple op makes
little sense. see my other post for a better solution.
uri
where did you get the impression that it was hard to use? how would
making a hard to use module be useful? one thing i strive for in all my
work is making stuff easy to use without sacrificing speed and
flexibility and file::slurp does all that.
and if you have your lines in an array then this is how you would do it:
use File::Slurp ;
write_file( 'my_file_with_newlines', map "$_\n", @array );
really hard to use!!
uri
wana said:To install, I had to copy the File directory from lib to use it
because I am on a shared server where I don't have root access, so
make install won't work for me.
wana said:Uri Guttman wrote:
I would not thought of it myself (the use of map), but now I will.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.