Re: qr + shift
- From: mritty@xxxxxxxxx (Paul Lalli)
- Date: Wed, 15 Aug 2007 07:14:16 -0700
On Aug 14, 3:57 pm, daggerqu...@xxxxxxxxx (Jay Savage) wrote:
On 8/12/07, Mr. Shawn H. Corey <shawnhco...@xxxxxxxx> wrote:
John W. Krahn wrote:
yitzle wrote:
Works:
my $t = shift;
my $id = qr($t);
Doesn't work:
my $id = qr(shift);
Why?
perldoc -q "How do I expand function calls in a string"
It's because qr is not a function, it's a quote-like operator.
No, it's because shift *is* a function.
As OP's example shows, variables interpolate, functions don't. The
difference between qr($t) and qr(shift) doesn't have anything to do
with qr().
Of course it does. That's utter nonsense. Functions passed as
arguments to functions get called. Functions included in strings do
not. qr() is a quoting mechanism. Its result is a string
It has to do with shift's behavior WRT string
interpolation. It doesn't matter whether the interpolated string is
being passed to an operator, a function, a subroutine, or someplace
else:
More absurdity.
$ perl -le'
sub foo {
print @_;
}
@ARGV = (qw/alpha beta gamma/);
foo(shift);
'
alpha
Of COURSE it matters how the function is being used. If it's being
included in a string (whether it's a "", '', qq, q, qr, qw, or qx)
it's just the name of the function that gets included in the string.
If it's passed as an argument to a function, it gets called and its
return value(s) are passed in its place.
Paul Lalli
.
- References:
- qr + shift
- From: Yitzle
- Re: qr + shift
- From: John W. Krahn
- Re: qr + shift
- From: Mr. Shawn H. Corey
- Re: qr + shift
- From: Jay Savage
- qr + shift
- Prev by Date: RE: Emptying several arrays at once
- Next by Date: Re: Emptying several arrays at once
- Previous by thread: Re: qr + shift
- Next by thread: Re: qr + shift
- Index(es):
Relevant Pages
|