Christopher Spears wrote:
> I'm trying to brush up on my Perl by learning object
> oriented Perl!  This may not be the best way to brush
> up on this subject, but I am sure that I will learn a
> lot!  Here is a script:
> 
> #!/usr/bin/perl -w
> use strict;
> 
> my @array = [1, 2, ['a','b','c','d']];

You are assigning to $array[0] a reference to an anonymous array.


> my $arrayref = [EMAIL PROTECTED];

You are assigning to $arrayref a reference to @array.


> my $arraySize = scalar $arrayref->@array;

$arrayref is a reference to @array so:

my $arraySize = @$arrayref;

will give you the size of @array and:

my $arraySize = @{ $arrayref->[0] };

will give you the size of the anonymous array in $array[0] and:

my $arraySize = @{ $arrayref->[0][2] };

will give you the size of the anonymous array in $array[0][2].


> print $arraySize."\n";
> 
> I received the following error message:
> Array found where operator expected at ./anonymousData
> line 8, at end of line
>       (Missing operator before ?)
> syntax error at ./anonymousData line 8, near
> "->@array"
> Execution of ./anonymousData aborted due to
> compilation errors.
> 
> What am I doing wrong?  Out of curiousity, if the
> array was anonymous, then how can I find it's size.  
> 
> $arrayref = [1, 2, ['a', 'b', 'c', 'd']];
> How can I find the size of this array with dereferencing?

There are a few Perl documents on data structures and references:

perldoc perldata
perldoc perldsc
perldoc perllol
perldoc perlreftut
perldoc perlref



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to