For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > March 2006 > array concatenation









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author array concatenation
ekilada

2006-03-28, 6:57 pm

Hi,
I need to concatenate 2 arrays like that:
@list=glob('*.txt');
@list.=glob('*.log');
But it doesn't work.
Have I missed anything please?

Thanks And Best Regards,
Eliyah

Paul Lalli

2006-03-28, 6:57 pm

ekilada wrote:
> Hi,
> I need to concatenate 2 arrays like that:
> @list=glob('*.txt');
> @list.=glob('*.log');
> But it doesn't work.
> Have I missed anything please?


The . is the *string* concatenation operator. It evaluates both its
arguments in a scalar context.

You simply want to add values to the end of the array. That's what the
push() function does.

perldoc -f push

my @list = glob('*.txt');
push @list, glob('*.log');

Alternatively, if you want syntax more consistant with concatenation:

my @list = glob('*.txt');
@list = (@list, glob('*.log'));
But I would never use that in real life. Use push().

Paul Lalli

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com