* demerphq <demerphq@gmail.com> [2010-11-13 13:30]:
> I dont understand really why this needs new syntax. Why cant it
> be done with a pragma.
>
> no autovivification 'lookup';
>
> something like that...
Consider this not very hypothetical example:
my $stash = $c->stash;
if (
$stash->{'foo'}
and $stash->{'foo'}{'bar'}
and $stash->{'foo'}{'bar'}{'baz'}
) {
push @{ $stash->{'quux'}{ $_->{'qux'} }{ $_->{'id'} } }, $_
for @$records;
}
How would one rewrite this with a pragma? Like this?
my $stash = $c->stash;
if ( do {
no autovivification 'lookup';
$stash->{'foo'}{'bar'}{'baz'};
} ) {
push @{ $stash->{'quux'}{$qux}{$id} }, $record;
}
Or this?
{
no autovivification 'lookup';
my $stash = $c->stash;
if ( $stash->{'foo'}{'bar'}{'baz'} ) {
use autovivification 'lookup';
push @{ $stash->{'quux'}{$qux}{$id} }, $record;
}
}
I will prefer the original code over any of the pragma-adorned
versions.
It’s not even the worst example. It would get impossibly messy if
you wanted to protect only some parts of an expression but not
others.
And several of my code bases contain variations on the following
theme, just because of how clumsy it is to inject pragmata:
sub coerce_num {
no warnings qw( numeric uninitialized );
( map { 0+$_ } @_ )[ 0 .. $#_ ];
}
Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>
Thread Previous
|
Thread Next