Re: better idiom for appending to list from file




Mirco Wahab wrote:
Hi all,

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?

push @Array, <FH>;
chomp @Array;

This harmlessly chomps the elements that were already in @Array.

.



Relevant Pages