in reply to perldelta unclear on 'given's fate
I imagine that given/when will be kept. However, the perception is that their current implementation is highly flawed. A new implementation will probably break some existing uses of given/when, so it makes sense to start warning people about this.
given originally used the lexical $_ rather than the global $_ (but this has changed in 5.18). This was confusing for many people.
when adds a whole extra layer of weird.
Quick quiz! What does this output?
use v5.10; use strict; no warnings; sub two () { 2 } sub three { 3 } sub english_number { my $number = shift; given ($number) { when ( 1 ) { return 'one' } when ( two ) { return 'two' } when ( three ) { return 'three' } when ( 4 ) { return 'four' } default { return 'more' } } } say english_number($_) for 1..5;
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: perldelta unclear on 'given's fate
by iguanodon (Priest) on Jan 04, 2014 at 18:37 UTC | |
by tobyink (Canon) on Jan 04, 2014 at 20:38 UTC | |
Re^2: perldelta unclear on 'given's fate
by morelenmir (Beadle) on Jan 04, 2014 at 18:45 UTC |
In Section
Seekers of Perl Wisdom