Hi Andrew,

  Thank you for the correction. It looks it was a bug in book.
  I am interested only for curiosity. Hope I don't need to work with the symbol 
table and typeglobs. :-)

  ----- Original Message ----- 

  I did this on my v5.14.2 and got the same result, so I resorted to reading


  $ perldoc perlmod


  (it's rather long so search for "PACKAGE")


  A minor modification has the desired result:




  #!/usr/bin/perl
  # typeglob-name-package.pl
  use v5.10;


  my $foo = "Some value";
  my $bar = "Another value";


  who_am_i(*foo );
  who_am_i(*bar );


  sub who_am_i {
    my $glob = shift;


    say "I'm from package " . *{$glob}{PACKAGE};
    say "My name is " . *{$glob}{NAME};
  }




  Octavian - just out interest - are you just doing this from pure curiosity or 
is there an interesting use case you can tell us about?:)


  Andrew




  On Sun, May 3, 2015 at 11:26 AM, Vincent Lequertier <s...@riseup.net> wrote:

    Same output here, with perl 5, version 20, subversion 2 (v5.20.2) built
    for x86_64-linux-thread-multi.

    I'm from package main
    My name is glob
    I'm from package main
    My name is glob


    Le 03/05/2015 10:01, Octavian Rasnita a écrit :
    > Hello,
    >
    > I've seen the following example in Mastering Perl book, with the comment
    > at the end telling what should be the result:
    >
    > #!/usr/bin/perl
    > # typeglob-name-package.pl
    > use v5.10;
    >
    > $foo = "Some value";
    > $bar = "Another value";
    >
    > who_am_i( *foo );
    > who_am_i( *bar );
    >
    > sub who_am_i {
    > local *glob = shift;
    >
    > say "I'm from package " . *glob{PACKAGE};
    > say "My name is " . *glob{NAME};
    > }
    >
    > Although this probably has limited usefulness, at least outside of any
    > debugging, the
    > output tells me more about the typeglobs I passed to the function:
    >
    > I'm from package main
    > My name is foo
    > I'm from package main
    > My name is bar
    >
    > --- end of text from book ---
    >
    > I ran the code above with StrawberryPerl 5.20 and ActivePerl 5.16 and
    > 5.14 and it gave the following result:
    >
    > I'm from package main
    > My name is glob
    > I'm from package main
    > My name is glob
    >
    > So it doesn't print the original name of the typeglob (foo or bar).
    > Is the code above working for you as wrote in the book?
    >
    > --Octavian
    >
    >

    --

    Vincent Lequertier
    s...@riseup.net


    --
    To unsubscribe, e-mail: beginners-unsubscr...@perl.org
    For additional commands, e-mail: beginners-h...@perl.org
    http://learn.perl.org/








  -- 

  Andrew Solomon


  Mentor@Geekuni http://geekuni.com/
  http://www.linkedin.com/in/asolomon

Reply via email to