[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

RE: [FWP] aCertainName.pm



At 02:15 PM 11/10/99 -0800, Larry Rosler wrote:
> > From: Ronald J Kimball [mailto:rjk@linguist.dartmouth.edu]
> > > > wouldn't the functions that take either a scalar
> > > > or list argument be easier to write using:
> > > >
> > > >   @_ = ($_) unless @_;
> > > >
> > > > instead?
> > >
> > > Easier, perhaps.  Correct, no!
> > >
> > > We're trying to reproduce the semantics of abs(), which say nothing
> > > about clobbering @_ if there is not argument.
> >
> > If there is no argument, then there is nothing in @_ to clobber.
> >
> > Correct, yes!
>
>Correct, no!
>
>my foo {

Do you know something about lexical subroutine syntax that we don't? :-)

>    my $x = abs; # Sets @_ to $_.
>    &bar; # Expects the same arguments as foo(), namely none, but now
>gets $_.
>}
>
>@_ has been 'clobbered' by abs()!

Eh?  It's not the same @_.  Consider:

sub bar {
   @_ = 'x';
   print "bar: @_\n";
}

sub baz {
   print "baz: @_\n";
}

sub foo {
   my $x = bar;
   print "foo: @_\n";
   &baz;
}

Calling foo; prints

bar: x
foo:
baz:

Calling foo qw(a b c); prints

bar: x
foo: a b c
baz: a b c

Wither clobber?


--
Peter Scott
Pacific Systems Design Technologies


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe