Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Unknown entries in %main::

by jerrygarciuh (Curate)
on Dec 18, 2002 at 02:51 UTC ( #220743=perlquestion: print w/ replies, xml ) Need Help??
jerrygarciuh has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,
While trying to learn more about the symbol table I printed out %main:: in a script whose only imported package was strict. The code and it's output are below, can anyone tell me what the mystery entries are on lines 5, 11, and 14 of the output text? Apparently the standard windows charset doesn't represent them?
TIA
jg
#!/usr/bin/perl -w use strict; while (my ($k, $v) = each %::) { print "key is $k, value is $v\n"; } key is STDOUT, value is *main::STDOUT key is @, value is *main::@ key is ARGV, value is *main::ARGV key is STDIN, value is *main::STDIN key is , value is *main:: key is attributes::, value is *main::attributes:: key is DB::, value is *main::DB:: key is _<..\xsutils.c, value is *main::_<..\xsutils.c key is _<perllib.c, value is *main::_<perllib.c key is UNIVERSAL::, value is *main::UNIVERSAL:: key is , value is *main:: key is <none>::, value is *main::<none>:: key is DynaLoader::, value is *main::DynaLoader:: key is , value is *main:: key is Win32::, value is *main::Win32:: key is BEGIN, value is *main::BEGIN key is stderr, value is *main::stderr key is INC, value is *main::INC key is _, value is *main::_ key is ", value is *main::" key is _<.\win32.c, value is *main::_<.\win32.c key is $, value is *main::$ key is stdout, value is *main::stdout key is IO::, value is *main::IO:: key is ENV, value is *main::ENV key is strict::, value is *main::strict:: key is stdin, value is *main::stdin key is CORE::, value is *main::CORE:: key is /, value is *main::/ key is 0, value is *main::0 key is _<..\universal.c, value is *main::_<..\universal.c key is STDERR, value is *main::STDERR key is main::, value is *main::main::

_____________________________________________________
"The man who grasps principles can successfully select his own methods.
The man who tries methods, ignoring principles, is sure to have trouble.
~ Ralph Waldo Emerson

Comment on Unknown entries in %main::
Select or Download Code
Re: Unknown entries in %main::
by pg (Canon) on Dec 18, 2002 at 03:12 UTC
    (Update: I read your reply, so you really want to know. Okay, don't forget those perlvars named $^C (COMPILING), $^F (SYSTEM_FD_MAX) etc., when you print them, they show as little unrecognizable symbols. Use ord to print out their ascii values, then you will recognize them. :-)

    The output from your code is not that meaningful, isn't it?

    Yes, Symbol table is a hash, but not really that straight. Think about this, in a hash you can not have duplicate keys, but in your program, you might have a hash and a scalar both named abc.

    Don't forget typeglob.
    foreach $symname (sort keys %main::) { local *sym = $main::{$symname}; if (defined $sym) { print "\$$symname is defined, and value is $$symname\n"; } if (defined @sym) { print "\@$symname is defined, and value is @$symname\n"; } if (defined %sym) { print "\%$symname is defined, and value is %$symname\n"; } }
      Hmm, well your code also produces some mystery entries. Can someone tell me what the sqares represent here?
      TIA
      jg
      $ is defined, and value is 256 $ is defined, and value is C:\Perl\bin\perl.exe $" is defined, and value is $$ is defined, and value is 345389531 $/ is defined, and value is $0 is defined, and value is C:\WINDOWS\Desktop\Edit2 $@ is defined, and value is %CORE:: is defined, and value is %CORE:: %DynaLoader:: is defined, and value is %DynaLoader:: %ENV is defined, and value is %ENV @INC is defined, and value is C:/Perl/lib C:/Perl/site/lib . %IO:: is defined, and value is %IO:: %UNIVERSAL:: is defined, and value is %UNIVERSAL:: %Win32:: is defined, and value is %Win32:: $_<..\universal.c is defined, and value is ..\universal.c $_<..\xsutils.c is defined, and value is ..\xsutils.c $_<.\win32.c is defined, and value is .\win32.c $_<perllib.c is defined, and value is perllib.c %attributes:: is defined, and value is %attributes:: %main:: is defined, and value is %main:: $symname is defined, and value is symname
      _____________________________________________________
      "The man who grasps principles can successfully select his own methods.
      The man who tries methods, ignoring principles, is sure to have trouble.
      ~ Ralph Waldo Emerson
Re: Unknown entries in %main::
by theorbtwo (Prior) on Dec 18, 2002 at 03:43 UTC

    "Funny characters" are generaly control characters, in this case the $^foo family of vars. You're seeing $^H as it really is, Control-H, also known as backspace or "". (If you zoom up your font size a bit, you should see that as a block with a circular hole in the middle (reversed bullet), not a "no such character" glyph.) $^H, as perlvar will tell you, gives the hints to the compiler for things like strict and warnings. You're also seeing $^R and $^X -- apparenly the other control-character vars aren't package vars in Main.

    Oh, my test script: perl -le "foreach (keys %::) {print qq{$_ -- \\c}.chr(ord($_)+64)}" > foo.txt. Oh, and the \cX is only valid where X is a capital letter. I was too lazy to test for that myself.


    Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

      Thank you kindly!
      jg
      _____________________________________________________
      "The man who grasps principles can successfully select his own methods.
      The man who tries methods, ignoring principles, is sure to have trouble.
      ~ Ralph Waldo Emerson

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://220743]
Approved by premchai21
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2014-07-31 02:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (244 votes), past polls