[Pdx-pm] Changing contructors w/o breaking compat.

Ovid poec at yahoo.com
Sat Oct 26 13:20:31 CDT 2002

--- Austin Schutz <tex at off.org> wrote:
> 	Err.. Randal's solution supports both forms of the syntax.
> 	Btw, never seen the %{+shift} syntax before. Is that a new thing,
> a sneaky trick, or have I been living under a rock?

That's an old trick.  A unary plus sign can be used to ensure that that function name is used as a
function name rather than being interprested as an argument list.  See perldoc perlop.

  [ovid at ovid ovid]$ perl -MO=Deparse -e '%{shift}'
  -e syntax OK
  [ovid at ovid ovid]$ perl -MO=Deparse -e '%{+shift}'
  %{shift @ARGV;};
  -e syntax OK
  [ovid at ovid ovid]$

As for changing the constructor, another solution may be to take the Sub::NamedParams module
(http://search.cpan.org/author/OVID/Sub-NamedParams-1.01/) and extend it to work with methods in
addition to functions.  I had never bothered to do that.  Perhaps it's time ...

Curtis "Ovid" Poe

"Ovid" on http://www.perlmonks.org/
Someone asked me how to count to 10 in Perl:
push at A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//;
shift at a;shift at a if $a[$[]eq$[;$_=join q||, at a};print $_,$/for reverse @A

Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site

More information about the Pdx-pm-list mailing list