Can anybody show with some examples the exact difference between ..
and ...
operator?
From the perlop man page:
If you don't want it to test the right operand until the next evaluation, as in sed, just use three dots ("...") instead of two.
But what exactly this mean? I don't understand the perlop's example:
@lines = (" - Foo", "01 - Bar", "1 - Baz", " - Quux" ); foreach (@lines) { if (/0/ .. /1/) { print "$_\n"; } }
with ...
will print the Baz
- but why? More precisely, why is Baz
not printed with two dots and only with ...
?
«...
» doesn't do a flop check immediately after a true flip check.
With «..
»,
" - Foo"
/0/
returns false...
returns false."01 - Bar"
/0/
returns true. Flip!/1/
returns true. Flop! ⇐ ..
returns true (since the first check was true)."1 - Baz"
/0/
returns false...
returns false." - Quux"
/0/
returns false...
returns false.With «...
»,
" - Foo"
/0/
returns false....
returns false."01 - Bar"
/0/
returns true. Flip!...
returns true."1 - Baz"
/1/
returns true. Flop!...
returns true." - Quux"
/0/
returns false....
returns false.If you have cases like /start/ .. /end/
with input
start some text end start some other text end
the ..
operator will process the end
in the first line as soon as it reads it and will only print some text
. The ...
operator will not process the end
on the first line so the other text will also be printed. Basically you can avoid stopping the range if the ending value is matched on the same line as the start. The ...
postpones the check until the next iteration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With