Home > Software engineering >  what the following syntax means in perl?
what the following syntax means in perl?

Time:05-07

my $dir = $ENV{"CDSSITE_INI_DIR"};

hello, I'm new to Perl. I'm confused with the curly braces above syntax. I know it is declared a scalar variable $dir. But what do the curly braces mean in that statement?

CodePudding user response:

Perl populates a global hash (%ENV) with the environment variables. To get any value, you must use the $ENV{'env-var-name'} syntax. That is the way to access a concrete value in a hash, using curly braces.

CodePudding user response:

It's retrieving the value from a hash based on key 'CDSITE_INI_DIR'. But in this case it's a special hash from the OS variables. You can code your own hash such as this:

my            
  •  Tags:  
  • perl
  • Related