Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl variables defined with * vs $

Tags:

variables

perl

What's the difference between defining a variable with a * vs a $? For example:

local $var;
local *var;
like image 699
erichar7 Avatar asked Jan 18 '26 14:01

erichar7


1 Answers

The initial character is known as a sigil, and says what sort of value the identifier represents. You will know most of them. Here's a list

  • Dollar $ is a scalar value

  • At sign @ is an array value

  • Percent % is a hash value

  • Ampersand & is a code value

  • Asterisk * is a typeglob

You are less likely to have come across the last two recently, because & hasn't been necessary when calling subroutines since Perl 5.0 was released. And typeglobs are a special type that contains all of the other types, and are much more rarely used.

I'm considering how much deeper to go into all of this, but will leave my answer as it is for now. I may write more depending on the comments that arise.

like image 120
Borodin Avatar answered Jan 21 '26 06:01

Borodin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!