Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Unidentified code

by Chmrr (Vicar)
on Oct 22, 2001 at 03:53 UTC ( [id://120415]=note: print w/replies, xml ) Need Help??


in reply to Unidentified code

Note: Ahbeyra was under the impression that one had to put print inside the code tags. Thus, this question and the next should be considered to be s/print "(.*)\\n"/$1/

Hrm -- an interesting bit of code, there. Taking it apart:

  • $main::cmdbase_mult is a fully qualified variable name -- that is, it's saying "there's this scalar in package main whose name is cmdbase_mult."
  • $main::cmdbase_mult->{'ignore'} takes that scalar, uses it as a hash reference, and looks up a key in said hash.
  •  = sub {...} creates an anonymous subroutine. That is, it'll return a (scalar, or course) reference to a subroutine that can be used later on down the line to call the subroutine that we put together now.
  • $_[0]->uid_ignore($_[1]) is the body of the subroutine that we're making. It takes the first argument ($_[0]), treats it as an object, and calls the uid_ignore method on it with the second argument that was passed to it.

There are quite a few different things going on here. If you're curious about references, this piece by Dominus or perlref might help; "Coping with Scoping" or perlmod educates about the $main::cmdbase_mult bit, while perltoot might be useful for learning about objects.

Update: Added links to Dominus's pages, which are a bit more digestable than the plain ole' docs.

perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^+*`^ ve^#$&V"+@( NO CARRIER'

Replies are listed 'Best First'.
Re: Unidentified code
by Ahbeyra (Monk) on Oct 22, 2001 at 04:54 UTC
    Also, I was wondering how you would go about getting information out of this:  print "$main::objbase->[155] = sub { my $i = item->new('FILLABLE', 1, 'NAME', 'an empty vial', 'VAL', 10, 'VOL', .5, 'MASS', .5, 'DESC', 'A simple glass vial, about three inches long. There is a bit of cork stuffed into the opening to help protect any liquids that may be placed inside.'); return($i); };\n";

      Let's reformat the code to be a little more readable:

      $main::objbase->[155] = sub { my $i = item->new('FILLABLE'=> 1, 'NAME'=>'an empty vial', 'VAL'=>10, 'VOL'=>.5, 'MASS'=>.5, 'DESC'=>'A simple glass vial, about three in +ches long. There is a bit of cork stuffed into the opening to help pr +otect any liquids that may be placed inside.' ); return($i); };

      Looked at this way, it's a little easier to see what's going on. First, off, there's this scalar in package main named objbase, which we'll treat as an array reference. Item number 155 of that array we're going to set to an anonymous subroutine. This subroutine makes a new "item" object, passing it a bunch of key=>value pairs. It'll then return the objevt that it just created.

      Thus, the way you'd use this would probably be:

      $vial = $main::objbase->[155]();

      perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^+*`^ ve^#$&V"+@( NO CARRIER'

Re: Re: Unidentified code
by Ahbeyra (Monk) on Oct 22, 2001 at 04:05 UTC
    Thanks a lot, that makes more sense now, and thanks for the links, I'll check those out right now.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://120415]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-03-28 10:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found