Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Blessed be the OOP'ers

by mdillon (Priest)
on Jun 29, 2000 at 01:07 UTC ( #20255=note: print w/replies, xml ) Need Help??


in reply to Blessed be the OOP'ers

you are initializing @employees as an array containing a single element, which is an anonymous array. the initialization should read: my @employees = ();
this will initialize it as an array with no elements.

Replies are listed 'Best First'.
RE: Re: Blessed be the OOP'ers
by chromatic (Archbishop) on Jun 29, 2000 at 02:26 UTC
    More specifically, the original code could be written this way: my $employees = [];
    Hopefully that makes it clear that a list enclosed in square brackets is an anonymous list. Assigning that somewhere creates a reference. (That's why you can stuff it in a scalar.)

    The original code creates @employees and sets the first (and only) element to a reference to that anonymous list.

      And the push would then be
      push @$employees, $person;
      
      with printing them looking like
      foreach $p (@$employees) {
         print $p->name(),"\n";
      }
      
      Using the array reference would make it easy to stuff this list of employees into another object/list/whatever.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://20255]
help
Chatterbox?
[Discipulus]: LA something a little more perlish? @mts = map {qx!mp3info -p $_!} glob '/path/*.mp3 (hazarded code)
[Discipulus]: many monks want to be hired tonight, other haired and some aired
[Lady_Aleena]: Discipulus, do glob recurse?
[Lady_Aleena]: s/do/does/;
LanX wants to be fired
[Discipulus]: i fear no

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2017-04-23 20:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (432 votes). Check out past polls.