Your skill will accomplishwhat the force of many cannot PerlMonks

### Re^2: Scalar range operator again

by kejv2 (Acolyte)
 on Jul 06, 2012 at 18:33 UTC ( #980352=note: print w/replies, xml ) Need Help??

in reply to Re: Scalar range operator again
in thread Scalar range operator again

Yes, I have read all those articles on the internet. But nowhere was described this counterintuitive behaviour. Of course, they point out that perl -we'my @l = qw/ac qw/; for (@l) { print if /a/../c/ }' would print ac and the same only with three dots prints acqw. This is completely understandable but not the case with @l = qw/ca qw/. Maybe it's really better to avoid such constructs as other monk has said.

Replies are listed 'Best First'.
Re^3: Scalar range operator again
by dsheroh (Prior) on Jul 07, 2012 at 08:08 UTC
I have read all those articles on the internet. But nowhere was described this counterintuitive behaviour.
Maybe it's just me, but perldoc's "It can test the right operand and become false on the same evaluation it became true (as in awk), but it still returns true once." seems to describe exactly this behavior. I'd even call it a clear description.
they point out that perl -we'my @l = qw/ac qw/; for (@l) { print if /a/../c/ }' would print ac and the same only with three dots prints acqw. This is completely understandable but not the case with @l = qw/ca qw/.
I don't get what you mean here. qw/ac qw/ and qw/ca qw/ are treated identically by the flip-flop operator:
```\$ perl -E 'my @l = qw/ac qw/; for (@l) { say if /a/../c/ }'
ac
\$ perl -E 'my @l = qw/ca qw/; for (@l) { say if /a/../c/ }'
ca
I don't get what you mean here. qw/ac qw/ and qw/ca qw/ are treated identically by the flip-flop operator:

Yes, I know that. Also the description on perldoc seems clear if you already know what to expect. My whole point is that the result of perl -we'my @l = qw/ca qw/; for (@l) { print if /a/../c/ }' is not logical.

Suppose that I want to process html file where I have tags like this:

```<tag>
a
</tag><tag>
b
</tag><tag>
c
If my flip-flop condition is /<tag>/../<\/tag>/ it would print
```<tag>
a
</tag><tag>
</tag><tag>
which is not what you want. With three dots you get
```<tag>
a
</tag><tag>
</tag><tag>
c
</tag>
still not good :(

Basically, what I originally (and incorrectly as I see now) expected from this operator was that it processes each element char by char (as a real flip-flop) and not as a whole. Of course, in my html example I can first format the file but that is another story.

BTW: I am new here and have a question about writeup formatting. How do you cite someone's text if it contains a code? Copy-pasting and than manually putting those code tags back (which I did) seems pretty tedious.

BTW: I am new here and have a question about writeup formatting. How do you cite someone's text if it contains a code? Copy-pasting and than manually putting those code tags back (which I did) seems pretty tedious.

If you have the latest firefox,
select the text, right context menu, View selection source
then paste into your textbox where you have a convenient template of

``` <blockquote><i>  quoted </i></blockquote>
<p> response </p>

or
``` <p><i> quoted </i></p>
<p> response </p>

or
``` <dl>
<dt><p> quoted </p></dt>
<dd> response </dd>
</dl>

The alternative is to use the xml link ( ?displaytype=xml;node_id=980252 ) and copy/paste from the original

Create A New User
Node Status?
node history
Node Type: note [id://980352]
help
Chatterbox?
 [Corion]: The data is the game ;) [marto]: good morning all [hippo]: Great slogan :) [Corion]: Hi marto ;) [mxb]: Hi all. [Discipulus]: Hi marto Discipulus mmh .oO(perl data chess.. 8 scalar, 2 arrays, 2 hashes, 2 refernses, 1 typeglob and atied scalar)

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (11)
As of 2018-03-19 09:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When I think of a mole I think of:

Results (236 votes). Check out past polls.

Notices?