Re: better idiom for appending to list from file
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 30 May 2006 12:36:51 -0700
Mirco Wahab wrote:
is there a typical Perl-spell when having a list:
@Array = qw( a b c d );
that needs to be appended from a file:
[somefile.txt]
ee
ff
gg
hh
[EOF]
I'd use
splice @Array, @Array, 0, map{ chomp; $_ } <FH>;
for that, but it may look ugly to others.
Any ideas?
Well, first of all,
splice @array, @array, 0, LIST
is exactly equivalent to:
push @array, LIST
so that's one optimization you could make. As for reading the file and
getting rid of the newlines, I might try to take advantage of a module
like Tie::File or IO::All:
tie my @file, 'Tie::File', 'file.txt' or die "Can't tie: $!";
push @array, @file;
(Tie::File auto-chomps the lines for you. Read its docs for more
information...)
Paul Lalli
.
- References:
- better idiom for appending to list from file
- From: Mirco Wahab
- better idiom for appending to list from file
- Prev by Date: better idiom for appending to list from file
- Next by Date: Convert string into incremental date
- Previous by thread: better idiom for appending to list from file
- Next by thread: Re: better idiom for appending to list from file
- Index(es):
Relevant Pages
|
|