Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Orbital starters

by holyghost (Sexton)
on Oct 10, 2017 at 08:50 UTC ( #1201083=perlmeditation: print w/replies, xml ) Need Help??

I started out on some code for making molecular orbitals, here'sthe beginning for atomic oribtals :
package orbital2::TimeD; sub new { my ($class,$d) = shift; my $td = $d; bless $self, $class; return $self; } package orbital2::TimeDelta; sub TimeDelta { my ($class) = shift; bless $self, $class; return $self; } sub Tick { my ($class) = shift; my ($seconds, $interval, $milliseconds) = shift; ### 2 args my $hope = undef; bless $self, $class; } sub TickCalculate { my ($self) = shift; return my $self->hope = $self->$seconds / $self->interval } package orbital2::TimeF; sub new { my ($class,$f) = shift; my $tf = $f; bless $self, $class; } package orbital2::TimeP; sub new { my ($class,$p) = shift; my $tp = $p; }

Replies are listed 'Best First'.
Re: Orbital starters
by soonix (Monsignor) on Oct 10, 2017 at 09:27 UTC
    my ($class,$d) = shift;
    in my understanding, this "initializes" $d with undef. Why don't you
    my ($class,$d) = @_;
    Personally, I'd do it this ("mixed") way:
    my $class = shift; my ($args, $as, $needed) = @_;
    to have the argument list in the same manner as in the corresponding method call.

    Update: see also this discussion from several years ago

    Update: typo corrected. Thanks AnomalousMonk!
      You can use $_ and @_ AFAIK

        They are different. You can run the following example.

        The part below the __DATA__ shows the expected output: $VAR1 is $_, $VAR2 is @_
        (the \ in the Dumper statement is to have @_ formatted as array rather than individual scalars).

        Before you go hunting for that odd Perl version: it specifies the minimum version. If your Perl is even older, you can change use 5.011 to use strict and say by print.

        #!/usr/bin/env perl use 5.011; # implies strict + feature 'say' use warnings; use Data::Dumper; for (1 .. 2) { say "in loop:"; say Dumper $_; test(3, 4); } sub test { say "in sub:"; # $VAR1 $VAR2 say Dumper $_, \@_; } __DATA__ in loop: $VAR1 = 1; in sub: $VAR1 = 1; $VAR2 = [ 3, 4 ]; in loop: $VAR1 = 2; in sub: $VAR1 = 2; $VAR2 = [ 3, 4 ]; ];
        No and yes, respectively.
Re: Orbital starters
by Your Mother (Chancellor) on Oct 10, 2017 at 13:16 UTC

    This is a fun idea. The code is a mess though. A lot doesn't work and the parts that do probably don't do what they're supposed to do. Even without strict and warnings, we get-

    orbital2.pm did not return a true value. BEGIN failed--compilation aborted.

    And with-

    "my" variable $self masks earlier declaration in same scope at orbital +2.pm line 38. Global symbol "$self" requires explicit package name at orbital2.pm li +ne 10. Global symbol "$self" requires explicit package name at orbital2.pm li +ne 12. Global symbol "$self" requires explicit package name at orbital2.pm li +ne 21. Global symbol "$self" requires explicit package name at orbital2.pm li +ne 22. Global symbol "$self" requires explicit package name at orbital2.pm li +ne 32. Global symbol "$seconds" requires explicit package name at orbital2.pm + line 38. Global symbol "$self" requires explicit package name at orbital2.pm li +ne 47. Compilation failed in require. BEGIN failed--compilation aborted.

    Fun project though. I hope you keep plugging away at it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://1201083]
Approved by Athanasius
help
Chatterbox?
[james28909]: conversations like that make my pee pee go boom boom
[james28909]: :)

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2017-12-15 16:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (439 votes). Check out past polls.

    Notices?