Brian McCauley chided:
> 
> Yves Orton wrote:
> 
> > I don't know if this is a bug or not, it seems sorta 
> reasonable although
> > entirely _not_ dwim:
> > 
> >   C:\>perl -e "sub X { print eval 'shift' } X(1)" A
> >   A
> > 
> > Is this correct?
> 
> See
>    perldoc -f shift
> 
> (I've just drifted over from comp.lang.perl.* where I mostly hang-out 
> and where we take a dim view of failures to RTFM.  If anything would 
> expect p5p to take an even dimmer view).
> 

Well, the thing is that this foxed three experienced perl programmers,
including two with signifigant contributions to the core perl base. Not only
that but a strict reading of the documentation reveals it is ambiguous:

"If ARRAY is omitted, shifts the @_ array within the lexical scope of
subroutines and formats, and the @ARGV array at file scopes or within the
lexical scopes established by the eval '', BEGIN {}, INIT {}, CHECK {}, and
END {} constructs. "

So it does not say that the inner most scope is the relevent one. For
instance I believe it is entirely reasonable to read it to say that

 eval ' sub { shift }->(1) '

Will actually shift off of the @ARGV, or to read it that 

 sub { eval 'shift' }->(1) 

Will actually shift off of the @_ array.

Personally id say that any shift inside of an eval string inside of a
subroutine and not part of a BEGIN, INIT, CHECK, or END construct should
operate on @_ and not @ARGV.

Also, just because the docs say something doesn't mean that what they say is
right or popper. The docs are often wrong or ambiguous or just plain
misleading, so asking for clarification from the p5p community is hardly out
of line. 

If this behaviour IS correct then it should probably read:

"If ARRAY is omitted, then when used inside an innermost scope created by a
subroutine or format will shift from the @_ array, within an innermost scope
established by the eval '', BEGIN {}, INIT {}, CHECK {}, and END {}
constructs it will shift from the @ARGV array. This means that sub X { eval
'shift' } will shift from @ARGV and not @_. (Despite the fact that such
behaviour will almost never be the right thing to do.)" 

Or maybe with the last parenthetical remark omitted.

:-)

Yves



Reply via email to