Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Config::Config{osname} and Config{osname}

by PhillipHuang (Sexton)
on Dec 07, 2011 at 08:56 UTC ( #942178=perlquestion: print w/replies, xml ) Need Help??
PhillipHuang has asked for the wisdom of the Perl Monks concerning the following question:

Would any one explain what the difference is between "Config::Config{osname}" and "Config{osname}"? They both give the same result when 'use Config '.
  • Comment on Config::Config{osname} and Config{osname}

Replies are listed 'Best First'.
Re: Config::Config{osname} and Config{osname}
by Corion (Pope) on Dec 07, 2011 at 09:00 UTC

    They are the same variable. See Config. It exports %Config::Config into your namespace.

Re: Config::Config{osname} and Config{osname}
by Anonymous Monk on Dec 07, 2011 at 09:09 UTC

    %Config::Config like @Config::ISA lives in package Config; while %Config lives in package main;

    When you use Config; it exports %Config into your current package (main). If you use package Huang; use Config; it exports (creates) %Config in package Huang; The fully qualified name of this exported (created) %Config is %Huang::Config;

    It is a global variable.

    This "exporting" is a copy. Copies take memory. So if you use Config(); or require Config; no copy gets made in your current namespace, but you can still access the original by its full name %Config::Config;

    Read Tutorials: Variable Scoping in Perl: the basics, Coping with Scoping

      This "exporting" is a copy. Copies take memory.

      Actually, it only copies a reference, not a lot of memory

      perl -MConfig -le " print \%Config::Config; print \%Config; " HASH(0x99abe4) HASH(0x99abe4)
      I see. When 'use Config' first, and then in 'package Huang', it must be identified with original path as "$Config::Config". If use '$Config{osname}', it will warn 'Global symbol "%Config" requires explicit package'.

        Yup, it all depends what package you're in

        $ perl -l use strict; use warnings; use Config; # main package Huang; use Config; package Batman; use Config; package main; print \%Config; print \%Huang::Config; print \%Batman::Config; print \%main::Config; print \%Config::Config; __END__ HASH(0x99abcc) HASH(0x99abcc) HASH(0x99abcc) HASH(0x99abcc) HASH(0x99abcc)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://942178]
Approved by marto
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2018-05-21 19:42 GMT
Find Nodes?
    Voting Booth?