in reply to arrays : splice or undef ?
"Using either method with a test script, Perl doesn't openly acknowledge the existence of the array after it's been undef'd or spliced.
if ( @TestArray ) { print"\nPush - TestArray IS here\n\n"; } else { print"\nAfter Push - TestArray is NOT here\n\n"; }
In the condition if (@TestArray), Perl is not checking whether @TestArray exists. It does exist. (You'd get a compilation error thanks to strict if it did not exist.)
if (...) is (dare I say "always"?) equivalent to if (scalar(...)), and an array evaluated as a scalar yields the count of elements within it. So if (@TestArray) just means the same as <c>if (is_true(count(@TestArray))), if Perl had is_true and count built-ins. Zero is of course false.
Personally, I think the easiest/clearest way of emptying an array is simply:
@TestArray = ();
I'm not sure how it benchmarks against undef or splice, but there's probably little difference.
There may be some behaviour difference between undef, splice and =() in the case of tied arrays, but I've not investigated this.
And I concur with Dave's conclusion that if possible you should avoid slurping the entire file into an array to begin with.
|
|---|