Please don't start new threads in this group. It's defunct. Use
comp.lang.perl.misc instead.
Bolin wrote:
> How to modify a list in a subfunction? E.g. I want to pass a list
> as an argument, and append it another list? Something like
>
> sub append {
> my $listRef = shift;
> my @list = @$listref;
>
> @list = (@list, @anotherlist);
>
> return \@list;
> }
>
> Right now I have to return the pointer to make it work, can I find
> a way to modify the imput argument without having to return the
> result,
Sure. Just don't assign the dereferenced reference to a new variable:
sub append {
my $listRef = shift;
push @$listRef, @anotherlist;
}
> or is that against Perl's coding style?
Not as far as I know.
> Another thing, I am also looking for an elegent way of initializing
> a hash table with two lists, or a list an a value, e.g. sth like
> @hash{@keyList} = @valueList or @hash{@keyList} = $value, which
> does not work.
Can't see why the first example would "not work". You'd better post
some illustrative complete code.
--
Gunnar Hjalmarsson
Email:
http://www.gunnar.cc/cgi-bin/contact.pl