That's lame! I edited the above, even previewed it, and resubmitted it with an inserted 'code' tag (it was missing one before the code, as you can see, it already had one after the code ;-/ ). But only the above version was stored and it seems I can't update it. Oh poo!
Anyway, hopefully this version will stay with the code tag intact!
#!/usr/bin/perl -w
#use strict;
use feature ':5.10';
BEGIN {
sub instance_vars {
my $pck=caller;
foreach(@_) {
eval "sub ${pck}::$_ {
my \$p = shift;
\$p->{$_} = \$_[0] if \@_;
\$p->{$_};
}"
}
}
}
package MyPackage;
*instance_vars=\&main::instance_vars;
{
instance_vars( qw(one two three) );
sub new {
my $package=shift;
my $parms=$_[0];
my $this={};
foreach(%$parms) {
$this->{$_}=$parms->{$_};
}
bless $this, $package;
}
}
package MyPackagetwo;
{ our @ISA = qw (MyPackage);
}
package main;
my $p=new MyPackagetwo({three => 3,});
$p->two(2);
printf "two=%d, three=%d\n",$p->two, $p->three;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.