Except perhaps for purposes of enhanced readability/maintainability, is the explicit stringification ever needed? Doesn't ne or any other stringwise comparator implicitly stringify everything it operates on, including references (but with due deference to undef)? (Granted, stringifiying a reference for comparison purposes is usually useless, but that's another discussion.)
c:\@Work\Perl\monks>perl -wMstrict -le "use warnings; use strict; ;; use Data::Dump qw(dd); ;; my @stuff = ('abc', 123, 'ab4', '123', 456, [ 123 ], { 123 => 'x', x +=> 123 }); ;; my $thing = 123; my @filtered = grep { $thing ne $_ } @stuff; dd \@filtered; ;; $thing = '123'; @filtered = grep { $thing ne $_ } @stuff; dd \@filtered; " ["abc", "ab4", 456, [123], { 123 => "x", x => 123 }] ["abc", "ab4", 456, [123], { 123 => "x", x => 123 }]
OT: I sometimes see what one might call "super stringification" in code that often seems to originate from biological users, e.g.:
my $filename = '...';
open my $fh, '<', "$filename" or die "...";
Can anyone comment on the origin or history of this apparent (mis-)meme?
OT: Update: The other odd idiomatic usage I see that seems to be of biological origin is along the lines of:
my $fh;
unless (open $fh, ...) {
print "open failed...";
exit;
}
Huh?!? Are BioMonks constitutionally averse to die-ing? Is it that exit; is needed to return a non-error exit code to the OS?
Give a man a fish: <%-{-{-{-<
In reply to Re^2: Filtering array of strings and numbers
by AnomalousMonk
in thread Filtering array of strings and numbers
by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |