Disclaimer: the above code was inspired by a CB conversationuse With; my $foo = "a string"; print "before with: $foo\n"; with($foo) { s/a /not a /; } print "after with: $foo\n"; with(foo) { sub new { bless {}, shift; } } print foo->new; __output__ before with: a string after with: not a string foo=HASH(0x80fbbf0)
package With; use strict; use Regexp::Common; use Filter::Simple; FILTER_ONLY code => sub { s[ with \s* ( $RE{balanced}{-parens => '()'} ) \s* { ] < my($t) = $1 =~ /\((.*)\)/; $t =~ /^[_a-zA-Z](?:(?:\w*)(?:(?:'|::)(?:\w+)+)?)*\z/ ? "{ package $t;" : "for($t) {" >iexsg; }, ; q{ they think it's all over, and now it is };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: a 'with' statement for perl
by mirod (Canon) on Apr 25, 2003 at 11:59 UTC | |
by broquaint (Abbot) on Apr 25, 2003 at 12:05 UTC | |
|
Re: a 'with' statement for perl
by demerphq (Chancellor) on Apr 26, 2003 at 15:48 UTC |