develooper Front page | perl.perl5.porters | Postings from December 2016

[perl #130198] chop(@x =~ tr///)

Thread Next
From:
Hugo van der Sanden via RT
Date:
December 31, 2016 08:45
Subject:
[perl #130198] chop(@x =~ tr///)
Message ID:
rt-4.0.24-22693-1483173921-1675.130198-14-0@perl.org
On Fri, 30 Dec 2016 16:08:57 -0800, jkeenan wrote:
> In 'perldoc -f tr', I see no documentation of anything like:
> 
> #####
> @x =~ tr/1/1/
> #####
> 
> So if that is essentially undefined behavior [...]

Well the docs say it expects to be supplied a string, and standard perl behaviours in such circumstances would be either to convert what is supplied into a string as best it can, or to give an error.

Consider the analagous behaviour for a pattern match:

% perl -wle '@x=(91..95); $y = (@x =~ /(\d+)/); print "$1 ($y)" if $y'
Applying pattern match (m//) to @x will act on scalar(@x) at -e line 1.
5 (1)
% perl -wle '@x=(91..95); $y = chop(@x =~ /(\d+)/); print "$1 ($y)" if $y'
Applying pattern match (m//) to @x will act on scalar(@x) at -e line 1.
Can't modify pattern match (m//) in chop at -e line 1, near "/(\d+)/)"
Execution of -e aborted due to compilation errors.
% 

Hugo

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