निम्न कोड में, मुझे uninitialized value
चेतावनी मिलती है, लेकिन केवल दूसरे given/when
उदाहरण में। ऐसा क्यों है?दिए गए/जब अपरिभाषित मान
#!/usr/bin/env perl
use warnings;
use 5.12.0;
my $aw;
given ($aw) {
when ('string') {
say "string";
}
when (not defined) {
say "aw not defined";
}
default {
say "something wrong";
}
}
given ($aw) {
when (/^\w+$/) {
say "word: $aw";
}
when (not defined) {
say "aw not defined";
}
default {
say "something wrong";
}
}
उत्पादन मैं मिलता है:
aw not defined
Use of uninitialized value $_ in pattern match (m//) at ./perl.pl line 20.
aw not defined
तो उसे ठीक करने के लिए शीर्ष पर 'परिभाषित' चेक डालना चाहिए? – simbabque
@simbabque, हाँ जो चेतावनी को हटा देगा। – Qtax