For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > January 2006 > Heterogenous array









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 Heterogenous array
Aditi Gupta

2006-01-10, 4:02 am

Hello Everybody,

A very happy new year to all of you.

Well, I'm trying to create a 2D array in which the 1st array is completely
numeric and the other array is a combination of numbers and text.
If I write it as :
@aoa = ([0..5], [1,2,undef, 3,4]);

then the program accepts this array of array, but if I write it as (I need
the following form):

@aoa = ([0..5], \@values);
where @values = (1, 2, undef, 3, 4);
then the program does not accept it.

Is there a provision in Perl to define heterogenous arrays? Please help!

Best Wishes,
Aditi

Charles K. Clarkson

2006-01-10, 4:02 am

Aditi Gupta <mailto:aditi9783@gmail.com> wrote:

: @aoa = ([0..5], \@values);
: where @values = (1, 2, undef, 3, 4);
: then the program does not accept it.

That works just fine for me. What do you mean by
"the program does not accept it"?

#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper 'Dumper';

my @values = (1, 2, undef, 3, 4);
my @aoa = ([0..5], \@values);

print Dumper \@aoa;

__END__


HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328


Aditi Gupta

2006-01-10, 4:02 am

Hello,

The error message "argument "1,2,undef,3,4" isn't numeric" was being
displayed. But with Data Dumper it is working.

Thanks:-)

On 1/2/06, Charles K. Clarkson <cclarkson@htcomp.net> wrote:
>
> Aditi Gupta <mailto:aditi9783@gmail.com> wrote:
>
> : @aoa = ([0..5], \@values);
> : where @values = (1, 2, undef, 3, 4);
> : then the program does not accept it.
>
> That works just fine for me. What do you mean by
> "the program does not accept it"?
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> use Data::Dumper 'Dumper';
>
> my @values = (1, 2, undef, 3, 4);
> my @aoa = ([0..5], \@values);
>
> print Dumper \@aoa;
>
> __END__
>
>
> HTH,
>
> Charles K. Clarkson
> --
> Mobile Homes Specialist
> 254 968-8328
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>


Xavier Noria

2006-01-10, 4:02 am

On Jan 2, 2006, at 12:53, Aditi Gupta wrote:

> The error message "argument "1,2,undef,3,4" isn't numeric" was being
> displayed. But with Data Dumper it is working.


That message is a warning, your code was probably doing some math
with something that didn't look like a number. From your message
looks like your code was treating the very string "1,2,undef,3,4" as
a number. That smells like a bug.

Additionally, I wanted to comment the subject of the post suggests
you think 1 and "1", and undef are "heterogeneous" data. Arrays in
Perl are _homogeneous_ indeed, they can only store scalars.

-- fxn

Sponsored Links







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

Copyright 2009 codecomments.com