$code_or_die suggested:if ($input eq $matching[0..2]) {die "bastard\n"};
merlyn wrote:if ($input eq $matching[0||1||2]) {die "bastard\n"};
Were you expecting it to mean something different, especially since you said it "works"? In what manner did you mean "works"?if ($input eq $matching[1]) {die "bastard\n"};
Coleoid said:
Schwartz, do you sometimes give the less-godly a break, or do you always present them with an insult which gives them no more useful knowledge than they began with? Where do you get your kicks from being an expert? Power-trip or education?
In this case, even though $code_or_die might hope the [0||1||2] would iterate over the values in the array, Perl uses short-circuiting logic to return a value, with the first true value in the set (in this case, the 1) being used for the subscript to the array. So I'm guessing you tested it with the middle ("duck") value, saw it work, and posted.
Lesson 1: Test more thoroughly--Success by coincidence sucks.
Lesson 2: Read up on short-circuiting logic--it's a sharp knife that can simplify problems for you...or slip in your hand and cost you a thumb.
But none of this bears on why dusk's original code didn't work:
In this case, the '0..2' resolved to three values, which means the 'matching[0..2]' subexpression is a 'slice'. The '$' in front of that all means that subexpression has to resolve to one scalar value--in this case, the first one in the list.if ($input eq $matching[0..2]) {die "bastard\n"};
But after all this, dusk, I don't know why you get that paticular error message--I don't, in 'perl -de 0'...and I can't concoct in my head why that would happen. This is something I'd love to have Randall answer--I don't get it.
In reply to Re: Re: Re: Why does this happen?
by Coleoid
in thread Why does this happen?
by dusk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |