seaver has asked for the wisdom of the Perl Monks concerning the following question:
I've come across something that I'm sure is related to inheritance, but for all my ignorance, could be a bug.
I have these three packages:
PDB PDB::Line PDB::Line::Atom
Each line from a PDB is saved in a new PDB::Line object, in an array in PDB.
If the line happens to be an ATOM line, then a new PDB::Line::Atom object will be created and stored in PDB::Line. I will be creating a variety of modules that cover all the different types of PDB Lines.
OK, in PDB::Line i do this:
in PDB::Line::Atom, this happens:($self->{'TYPE'},$self->{'data'}) = unpack("A6 A74", $self->{'string'} +); if($self->{'TYPE'} eq 'ATOM'){ $self->{'object'} = new PDB::Line::Atom($self->{'data'}); }
each ATOM line looks like this:sub new { my $class = shift; my $self = {}; $self->{'AN'} = ''; $self->{'A'} = ''; $self->{'AL'} = ''; $self->{'R'} = ''; $self->{'RN'} = ''; $self->{'IC'} = ''; $self->{'X'} = ''; $self->{'Y'} = ''; $self->{'Z'} = ''; $self->{'OC'} = ''; $self->{'TE'} = ''; $self->{'SI'} = ''; $self->{'E'} = ''; $self->{'C'} = ''; bless $self, $class; $self->parse(shift); return $self; } sub parse{ my $self=shift; ($self->{'AN'}) = unpack("A5", $_[0]); print $self->{'AN'}."\n"; }
but the unpack line in the PDB::Line means that PDB::Line::Atom only gets this:ATOM 242 CE2 PHE A 16 9.011 14.465 -20.603 1.00 0.00 + C
Which is true, it works. But ONLY, and ONLY if I subscript the @_ with a number.242 CE2 PHE A 16 9.011 14.465 -20.603 1.00 0.00 + C
If I try using '$_', since I am only passing one value, this is what I used instinctively, it will output "ATOM'. Meaning it passes the entire line including the 'ATOM' header. But how can it, when the '$self->{'data'} doesn't have it!!
My best guess is that when I open and read the file using <>, it is remembering the $_ from that??
Any explanation would be greatly appreciated.
Thanks
Sam Seaver
20030923 Edit by jeffa: Changed title from 'Inheritance of $_?? '
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why are @_ and $_ not linked?
by dragonchild (Archbishop) on Sep 22, 2003 at 17:13 UTC | |
|
Re: Why are @_ and $_ not linked?
by BrowserUk (Patriarch) on Sep 22, 2003 at 17:27 UTC |