W
Wolfram Humann
Would someone be so kind to explain the following (quotes are for
win32 perl):
perl -E" $u='foo'; given($u){ when('foo' and 'bar'){say 'f'}
default{say 'd'} } "
d
perl -E" $u='bar'; given($u){ when('foo' and 'bar'){say 'f'}
default{say 'd'} } "
f
perl -E" $u='baz'; given($u){ when('foo' and 'bar'){say 'f'}
default{say 'd'} } "
d
perl -E" $u='foo'; given($u){ when('foo' or 'bar'){say 'f'}
default{say 'd'} } "
f
perl -E" $u='bar'; given($u){ when('foo' or 'bar'){say 'f'}
default{say 'd'} } "
d
perl -E" $u='baz'; given($u){ when('foo' or 'bar'){say 'f'}
default{say 'd'} } "
d
My expectation was: smart matching of two strings uses 'eq'. $u can
not be equal to both 'foo' and 'bar' at the same time so in the 'and'
case I always expect the default 'd'. In the 'or' case I expect 'f' to
be printed if $u is either 'foo' or 'bar'.
Why is my expectation wrong?
win32 perl):
perl -E" $u='foo'; given($u){ when('foo' and 'bar'){say 'f'}
default{say 'd'} } "
d
perl -E" $u='bar'; given($u){ when('foo' and 'bar'){say 'f'}
default{say 'd'} } "
f
perl -E" $u='baz'; given($u){ when('foo' and 'bar'){say 'f'}
default{say 'd'} } "
d
perl -E" $u='foo'; given($u){ when('foo' or 'bar'){say 'f'}
default{say 'd'} } "
f
perl -E" $u='bar'; given($u){ when('foo' or 'bar'){say 'f'}
default{say 'd'} } "
d
perl -E" $u='baz'; given($u){ when('foo' or 'bar'){say 'f'}
default{say 'd'} } "
d
My expectation was: smart matching of two strings uses 'eq'. $u can
not be equal to both 'foo' and 'bar' at the same time so in the 'and'
case I always expect the default 'd'. In the 'or' case I expect 'f' to
be printed if $u is either 'foo' or 'bar'.
Why is my expectation wrong?