ABright
ABright

Reputation: 11

Perl - double dollar sign: what function does it perform?

I understand that the $$ is a way to dereference a variable, but in this example, I am unable to determine what it is used for:

opendir (CUST, "D:/opt/customer");  
foreach $area (grep /^\d\d\d\d$/, readdir CUST) { 
  push @areas, $area; 
  $$area{acc} = shift ;
  open (AREA_DISP, "<D:/opt/customer/$area/displays/dir.mnu");
  while (<AREA_DISP>) {
    $$area{dir} = $$area{dir} . $_; 
    }
  close (AREA_DISP);
  }
closedir (CUST);

The only other place that it is used, is further down in the code:

foreach $area (@areas) {s/.+( $area)/"$$area{acc} $1/;}

Any help would be appreciated.

Upvotes: 1

Views: 1039

Answers (1)

asjo
asjo

Reputation: 3194

Most people would write $area->{acc} instead of $$area{acc}, these days.

Example:

$ perl -E '$area={ acc=>"some" }; say $$area{acc}; say $area->{acc}'
some
some
$

If I were you, I would rewrite that script, as it seems to be using old idioms, and reuses variables in a rather questionable way.

Upvotes: 4

Related Questions