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

Re: [PBML] *$ syntax

Expand Messages
  • Shawn H Corey
    ... This is unusual syntax. The following is equivalent to the above: ${*{$obj}}{ net_smtp_host } = $host; But I have no idea what it does. :( -- Just my
    Message 1 of 4 , May 16 5:49 AM
    • 0 Attachment
      On 12-05-14 04:48 PM, Ken Shail wrote:
      > In Graham Barr's Net::SMTP for example he uses the following syntax:
      > ${*$obj}{'net_smtp_host'} = $host;
      > in his sub new and other places.
      >
      > Could someone please explain the *$ syntax.
      > He has already instantiated a socket and presumably is adding some local
      > hash variables.

      This is unusual syntax. The following is equivalent to the above:

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

      But I have no idea what it does. :(


      --
      Just my 0.00000002 million dollars worth,
      Shawn

      Programming is as much about organization and communication
      as it is about coding.

      [updated for today's programming]
      "Show me your code and conceal your interfaces, and I shall continue
      to be mystified. Show me your interfaces, and I won't usually need
      your code; it'll be obvious."
      -- Fred Brooks

      CPAN http://www.cpan.org/
      The world's largest repository of software;
      all of it tested; all of it free.
    • 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 2 of 4 , May 16 6:00 AM
      • 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 3 of 4 , May 16 8:27 AM
        • 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.