This place rocks! I didnt expect such prompt replies :-)
The thing is I want each element in the array to be seperated by newlines so that when the script outputs the final list it will be nice and orderly, one word per line.
What the script does is read from @argv some files that it will read into an array, lowercase, sort, remove dups (not done yet) and then output the final array to out.txt
Is there a way to "unchomp" an array making sure that each element has a newline (but not add one if it already does) or something like that?
Thanks to everyone who replied
Im reading also while Im trying everyones ideas
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
my @out;
my $num = scalar(@ARGV);
if (-e "out.txt"){
print "Please move or rename out.txt\n";
exit 0;
}
for (my $i = 0; $i < $num; $i++) {
open (FH, "$ARGV[$i]") || die "Cant open: $!";
while (<FH>) {
push (@out, lc);
}
close FH || die "Cant close: $!";
}
print sort @out
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.