To help you with improving your Perl technique,
some minor Perl style advice on your originally posted code:
- Always start your scripts with "use strict" and "use warnings"
- You don't need to quote "$tmpfile" in your open call
- Your use of split on newline is pointless; you're reading line-by-line and have already chomp'ed the newline
- Prefer the close function to the ->close method call
That is, I would write your originally posted code:
open my $fh1, "<:encoding(utf-8)","$tmpfile" or die "$tmpfile: $!";
while (<$fh1>) {
chomp;
push @names, split (/\n/);
}
$fh1->close;
as:
use strict;
use warnings;
my $tmpfile = 'f.tmp'; # test file used only for testing this script s
+tandalone
my @names;
open my $fh1, "<:encoding(utf-8)", $tmpfile or die "$tmpfile: $!";
while (<$fh1>) {
chomp;
push @names, $_;
}
close $fh1;
That said, I strongly endorse the other comments exhorting you to write the whole thing in Perl
without using Unix shell at all.
As for why, see: Unix shell versus Perl
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.