"...and at the end of the day, is
somewhat more readable."
There, fixed that for you
:-)
(Unless I missed a
use whoosh; here... don't think so because your post seems sincere.)
At the point where you're using Perl idioms to slurp an entire file into memory... is the
array reference really the hard bit to understand here?
:-)
I'll grant you the point about not needing to be a reference at all because of function locality.
But
my $x = [ ]; and
my @x; both establish an array.
push is actually suggestive of what it does, unlike the input operator's ability here
@x = <$fileHandle>; to return all lines in a file as a list context... That is as obscure as references; if your target audience is expected to know how that aspect of the input operator works I wouldn't be
too hard on your coworker for expecting them to understand array references.
Oh so this!
I have had to tell cow-orkers to knock that crap off. They've got the job, and from this point on the only thing that will impress us is code that can be maintained by anyone else on the team, even if they have not set eyes on it in years.
Programmer did:
my $something = [];
open my $filehandle, '<', $filename or croak "Can't read file";
push @$something, <$filehandle>;
close $filehandle;
How about:
open(my $filehandle, '<', $filename) or croak "Can't read file";
my @something = <$filehandle>;
close($filehandle);
Much more succinct, gets rid of a pointless use of an array reference (seriously, it was used as an array in that function only, never passed around or returned), and at the end of the day, is far more readable.