Yay, I finally learned how to get screwed by Perl



Hell, I didn't even have to have my gf dress me up and put makeup on me
for this kind of screw job either.

#!/usr/bin/perl -w

package Person;

#Please note that new() and name() are taken from perltoot.

sub new {
my $self = {};
$self->{NAME} = undef;
$self->{AGE} = undef;
$self->{PEERS} = [];
bless($self);
return $self;
}

sub name {
my $self = shift;
if (@_) { $self->{NAME} = shift }
return $self->{NAME};

}

package main;

$him = Person->new();
$him->{NAME} = "Chad";

print "The name is: ", $him->name , "\n";

$./person.pl
The name is: Chad

Somewhere buried in all this technical crap, there was a section on
using closures to avoid this kind of screw job. I might try to find it,
because the solution presented in the Perl Cookbook is too complicated.
Ie, I haven't quite figured out the whole regular expression thingy yet.

.



Relevant Pages

  • SSIS - Adding Mappings Programatically
    ... I am stuck with Adding Mappings, ... '// Here is subset of my sample code ... Sub SSISPackageDemo() ... Savepackage(pkg, True) '//Save Package to SQL Server ...
    (microsoft.public.sqlserver.dts)
  • Re: best practice ... requires
    ... affect the way Perl parses your program, like strict and warnings). ... Do you know what calling a sub with & does? ... so you can see that my package is nested and I am now wondering how ...
    (comp.lang.perl.misc)
  • Re: perl menubased user interface
    ... actually use a perl package OR a hash for this, In a "perl package" ... sub map_method { ... # and they're all shell commands. ... Do whatever you want to wrap a shell command. ...
    (comp.lang.perl.misc)
  • Re: Using a DBI connection in many places (in the code)
    ... # non-exported package globals go here ... sub set_name { ... nothing to do with DBI. ...
    (comp.lang.perl.modules)
  • Re: multiple packages/classes in one file
    ... > so you can use globals under strict and not just lexicals. ... > this means global to the package that our is used in. ... > sub set_member ... > return $member; ...
    (comp.lang.perl.misc)