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

Re: [FWP] Stupid uses of AUTOLOAD



On Wed, 18 Aug 1999 18:06:49 -0400, you wrote:

>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!

Thanks, Uri. Normally I'm as opposed to symrefs as anyone, but for
some reason (late night?) didn't spot them there, or know what to do
about it. Blindingly obvious, though.

Monterey... hmmm... Not as easy to get to when you're in Vienna
(that's Austria, not Virginia).


Anyway, here's another version:


#!/usr/bin/perl

sub AUTOLOAD {
	($_ = $AUTOLOAD ) =~ s/^.*:://;
	s/(?:(^_)?)the_//gi;
	if (/^who_is_(\w+)_of_(\w+)$/) { $autohash{"$1_by_key"}{$2} }
	elsif (/^who_is_(\w+)_(\w+)_of$/) {
$autohash{"$2_by_value"}{$1} }
	elsif (/^(\w+)_of_(\w+)_is_(\w+)$/) {
		$autohash{"$1_by_key"}{$2} = $3;
$autohash{"$1_by_value"}{$3} = $2
	}	elsif (/^(\w+)_is_(\w+)_of_(\w+)$/) {
		$autohash{"$2_by_key"}{$3} = $1;
$autohash{"$2_by_value"}{$1} = $3
	}
}

The_father_of_luke_is_anakin();
shmi_is_the_mother_of_anakin();
print who_is_the_mother_of_anakin(), "\n";
print who_is_the_father_of_luke(), "\n";
print who_is_shmi_the_mother_of(), "\n";



Marcel
-- 
sub AUTOLOAD{($_=$AUTOLOAD)=~s,^.*::,,;y,_, ,;print} Just_Another_Perl_Hacker();

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