Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] *$ syntax

Expand Messages
  • merlyn@stonehenge.com
    ... Ken In Graham Barr s Net::SMTP for example he uses the following syntax: Ken ${*$obj}{ net_smtp_host } = $host; Ken in his sub new and other places.
    Message 1 of 4 , May 16, 2012
    • 0 Attachment
      >>>>> "Ken" == Ken Shail <shailken@...> writes:

      Ken> In Graham Barr's Net::SMTP for example he uses the following syntax:
      Ken> ${*$obj}{'net_smtp_host'} = $host;
      Ken> in his sub new and other places.

      Ken> Could someone please explain the *$ syntax.
      Ken> He has already instantiated a socket and presumably is adding some local
      Ken> hash variables.

      The scalar package variable named by $obj contains a hash ref, and this
      sets the value to $host for the key net_smtp_host of that variable.

      So if $obj was 'fred', this'd be the same as:

      $fred{net_smtp_host} = $host;

      presuming "my %fred" was not in scope.


      **************************************************
      *
      * THIS IS NOT THE OFFICIAL perl BEGINNERS GROUP.
      *
      * The official one is at beginners@..., with instructions on how to
      * join at http://lists.perl.org/list/beginners.html.
      *
      * You'll get far better response there, not to say you won't get *any* here.
      *
      **************************************************


      --
      Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
      <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
      Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
      See http://methodsandmessages.posterous.com/ for Smalltalk discussion
    • andy_bach@wiwb.uscourts.gov
      ... ${*{$obj}}{ net_smtp_host } = $host; My guess is $obj is the name the *{$obj} gets you to the typeglob (all the Perl variable types using the word in
      Message 2 of 4 , May 16, 2012
      • 0 Attachment
        > This is unusual syntax. The following is equivalent to the above:

        ${*{$obj}}{'net_smtp_host'} = $host;


        My guess is $obj is the 'name' the
        *{$obj}

        gets you to the typeglob (all the Perl variable types using the word in
        $obj - hash, array, scalar, filehandle etc) so then
        ${*{$obj}){...

        gets you to the hash named for the work in $obj. So it's a tricky (too
        tricky?) way to work w/ a not-known-until-runtime variable name. Often
        this is done by using references too - see perldoc perlref or
        http://perldoc.perl.org/perldata.html#Typeglobs-and-Filehandles

        and
        http://perldoc.perl.org/perlref.html


        a
        ----------------------
        Andy Bach
        Systems Mangler
        Internet: andy_bach@...
        Voice: (608) 261-5738, Cell: (608) 658-1890

        "People create programs to direct processes. In effect, we conjure the
        spirits
        of the computer with our spells." - The Structure & Interpretation of
        Computer Programs
        Abelson, Sussman, and Sussman - http://mitpress.mit.edu/sicp/

        [Non-text portions of this message have been removed]
      Your message has been successfully submitted and would be delivered to recipients shortly.