develooper Front page | perl.perl5.porters | Postings from March 2000

[ID 20000307.007] Bug in perlop man page (=~ return value)

Thread Next
From:
Piotr Piatkowski
Date:
March 7, 2000 13:11
Subject:
[ID 20000307.007] Bug in perlop man page (=~ return value)
Message ID:
Pine.LNX.4.21.0003072148110.12136-100000@tau.ceti.com.pl

I have answered on pl.comp.lang.perl with one of my favorite one-liners
(how to sort list of <a href=...>name</a> lines by names:
print sort { ( $a =~ />(.*)</ )[0] cmp ( $b =~ />(.*)</ )[0] } <>; 
- not very efficient but fits in one line :-) )

then friend of mine pointed to me, that perlop lies about =~'s return
value:

       Binary "=~" binds a scalar expression to a pattern match.
       [...]
       or transliterated instead of the default $_.  The return
       value indicates the success of the operation.
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Which is true only in scalar context - in list context it returns the same
value as patter match operator itself (well, I didn't check for operators
others than m// but I hope perl is consistent at last here :-) ).

I hope someone will fix perlop manpage in next revision (althought it is
very intuitive and I guess much people are using this not knowing it is
actually "undocumented feature" :-) ).

Greetings

-- 
Piotr Pi±tkowski, Kraków
perl -le 's**02).4&9%4^[./4(%2^0%2,^([#+%2&**y%& -;^[%"`-{ a%%s%%$_%ee'


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About