tford has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to write Perl code that checks whether a given portion of a data structure (an array) has elements in it, or not.
It will need to perform this check many many times, so I'm worried about efficiency.
What I'm thinking about writing is
if( @{ $complete->{landmarks}->{LOG}->[$i][$j][$p] } ) { # return early, there's nothing to do here }
The $complete->{landmarks}->{LOG}->[$i][$j][$p] element has to be an array reference (right ?) so I want to test if the array pointed to by that actually holds stuff or not.
What I would hope is that the array is just examined "in place" and it already has some field that records how many elements it contains. Then the check could be performed very quickly. However, for some reason I have the idea that it would copy the whole array to an anonymous location first, and then return the number of elements it copied. Is this even close to the truth?
If so is there a more efficient way to do it?
Thanks in advance,
~tford
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Does @{ } copy arrays?
by jwkrahn (Abbot) on Oct 16, 2009 at 20:08 UTC | |
|
Re: Does @{ } copy arrays?
by Anonymous Monk on Oct 16, 2009 at 22:49 UTC | |
|
Re: Does @{ } copy arrays?
by bv (Friar) on Oct 16, 2009 at 20:06 UTC | |
by dave_the_m (Monsignor) on Oct 16, 2009 at 21:45 UTC | |
by BrowserUk (Patriarch) on Oct 16, 2009 at 21:57 UTC | |
by dave_the_m (Monsignor) on Oct 17, 2009 at 10:50 UTC | |
by BrowserUk (Patriarch) on Oct 17, 2009 at 15:41 UTC | |
| |
by QM (Parson) on Oct 17, 2009 at 01:06 UTC | |
by dave_the_m (Monsignor) on Oct 17, 2009 at 10:57 UTC | |
by QM (Parson) on Oct 17, 2009 at 19:57 UTC | |
by ikegami (Patriarch) on Oct 28, 2009 at 18:00 UTC | |
by bv (Friar) on Oct 17, 2009 at 16:34 UTC | |
by ikegami (Patriarch) on Oct 23, 2009 at 20:57 UTC | |
by Anonymous Monk on Oct 17, 2009 at 18:09 UTC | |
|
Re: Does @{ } copy arrays?
by lamprecht (Friar) on Oct 16, 2009 at 20:10 UTC |