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

Re: [FWP] Stupid uses of AUTOLOAD



On Wed, 18 Aug 1999, Marcel Grunauer wrote:

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

What an evil feature! Perl is worse than I thought! I like it, I like
it....


#!/usr/bin/perl

sub AUTOLOAD {
  ($AUTOLOAD =~ /for_([a-zA-Z]+)_from_(\d+)_to_(\d+)/) || 
    die "Subroutine $AUTOLOAD not found.";

  my( $id, $start, $end, $arg) = ($1, $2, $3, shift);
  my( $copy) = $arg;
  $copy =~ s/\b$id\b/$start/e;
  print "$copy=" . eval( $copy) . "\n";
  $start++;
  return if $start > $end;
  $arg =~ s/"/\\"/g;
  my $cmd = "for_$id" . "_from_$start" . "_to_$end( \"$arg\")";
  eval( $cmd);
}

for_x_from_0_to_10( "2*(x**2)" );

for_myVar_from_10_to_12( "for_sog_from_14_to_17( \"myVar*sog\")");


John Carter <ece@dwaf-hri.pwv.gov.za> Telephone : 27-12-808-0374x194 
Fax:- 27-12-808-0338		      Cell      : 083-543-6915
<http://www.geocities.com/SoHo/Cafe/5947> or <http://iwqs.pwv.gov.za>

When I grow up, I'm going to be a range of mountains!


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