Home > Archive > PERL Beginners > October 2006 > reference to array of references to arrays
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 |
reference to array of references to arrays
|
|
| magdafrog@yahoo.de 2006-10-12, 6:59 pm |
| hi,
have some troubles with references(see comments)
sub generatePie() {
my $ref = read_file('/var/log/exim4/mainlog.5');
########################################
########################
#how could i access the length of the first element of array??
# length( @{ $ref->[0] } is wrong
########################################
#########################
my @array =
( [ 'In' . length( @{ $ref->[0] } ), 'Out' . length( @{ $ref->[1]
} ), 'failed' . length( @{ $ref->[2] } ) ],
[ length( @{ $ref->[0] } ), length( @{ $ref->[1] } ), length(
@{ $ref->[2] } ) ] );
plot_graph( generate_pie( \@array ) );
}
############################
#only part of this function#
############################
sub read_file
{
while (<LOG> ) {
if ( $_ =~ /(\d{4})-(\d{2})-(\d{2})\s.*<=/ ) {
$in++;
push( @in, [ $1, $2, $3 ] );
}
}
my @array = ( \@in, \@out, \@frozen, \@failed );
return \@array;
}
thanks in advance
many greetings
m.muskala
| |
| usenet@DavidFilmer.com 2006-10-12, 6:59 pm |
| magdaf...@yahoo.de wrote:
> ########################################
########################
> #how could i access the length of the first element of array??
> # length( @{ $ref->[0] } is wrong
> ########################################
#########################
That's because @{ $ref->[0]} is an array (reference), not a scalar.
You need to drill down a bit deeper, such as:
@{$aref->[0]}[0]
--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)
| |
| Uri Guttman 2006-10-12, 6:59 pm |
| >>>>> "u" == usenet <usenet@DavidFilmer.com> writes:
u> magdaf...@yahoo.de wrote:[color=darkred]
u> That's because @{ $ref->[0]} is an array (reference), not a scalar.
u> You need to drill down a bit deeper, such as:
u> @{$aref->[0]}[0]
that is slightly off as well. it is a slice with one index so it should
be $ and not a leading @. but even simpler is to just index down another
level from the ref:
$aref->[0][0]
assuming the data is really an AoA. i didn't see proof of that in the OP
but i didn't look too hard.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
| |
| magdafrog@yahoo.de 2006-10-12, 6:59 pm |
| hi,
thank oyu fpr your answer.
usenet@DavidFilmer.com schrieb:
> That's because @{ $ref->[0]} is an array (reference), not a scalar.
> You need to drill down a bit deeper, such as:
>
> @{$aref->[0]}[0]
@{ $ref->[0]} is an array of references or am i beeing wrong??
what i want is to know how many references are in this array...
@{$aref->[0]}[0] doesnt work for me at all :o/
many greetings
magda
| |
| magdafrog@yahoo.de 2006-10-12, 6:59 pm |
| thank you all for help...
what i wanted is: $#{@{$ref->[3]}}.
stupid /me... :oS
forgotten, that the lenght is used for strings and not for arrays...:oO
greetings
magda
| |
| Uri Guttman 2006-10-12, 6:59 pm |
| >>>>> "m" == magdafrog <magdafrog@yahoo.de> writes:
m> thank you all for help...
m> what i wanted is: $#{@{$ref->[3]}}.
did you read my comment? that is still wrong in several ways. $# is the
index of the last element, not the length. i don't know what that @{} is
doing there. it seems to do no harm but is has no purpose:
perl -le '$a=[1..3]; print $#{$a}'
2
perl -le '$a=[1..3]; print $#{@{$a}}'
2
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
|
|
|
|
|