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

Re: [FWP] Stupid uses of AUTOLOAD



>>>>> "MG" == Marcel Grunauer <marcel.grunauer@lovely.net> writes:

  MG> Hi all,
  MG> inspired by Mark-Jason Dominus', ahem, ingenius uses of AUTOLOAD,
  MG> please laugh with, laugh at, dissect, ignore etc. the following:


  MG> #!/usr/bin/perl

  MG> sub AUTOLOAD {
  MG> ($_ = $AUTOLOAD ) =~ s/^.*:://;
  MG> s/(^|_)the_/ $1 eq '_' ? '_' : ''/gei;

make the () non-grabbing to save a useless copy

  MG> if (/^who_is_(\w+)_of_(\w+)$/) {
  MG> eval "\$$1_by_key\{'$2'}"

this is as evil as symrefs. why not do a HoH? you are generating the
keys of the first and second levels with the calls without who, so that
is not a problem. i leave the coding as an exercise to this list. i am
going to a party now and in 2 days, off to monterey!

  MG> } elsif (/^who_is_(\w+)_(\w+)_of$/) {
  MG> eval "\$$2_by_value\{'$1'}"
  MG> } elsif (/^(\w+)_of_(\w+)_is_(\w+)$/) {
  MG> eval "\$$1_by_key{'$2'} = '$3'; \$$1_by_value{'$3'} = '$2'"
  MG> } elsif (/^(\w+)_is_(\w+)_of_(\w+)$/) {
  MG> eval "\$$2_by_key{'$3'} = '$1'; \$$2_by_value{'$1'} = '$3'"
  MG> }
  MG> }

  MG> Not sure about all those evals either.

they suck, as i said!

but the overall hack is amusing, i.e. taking data from the method name
itself. it also is probably a big as AUTOLOAD is slow.

uri


-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.

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