Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl Syntax characters "::"

Tags:

syntax

perl

I can't find anywhere what the :: is for in Perl. Example:

$someVariable::QUERY{'someString'};

Thanks!

like image 271
moby Avatar asked Jun 13 '13 19:06

moby


People also ask

How do I insert a special character in Perl?

The Special Character Classes in Perl are as follows: Digit \d[0-9]: The \d is used to match any digit character and its equivalent to [0-9]. In the regex /\d/ will match a single digit. The \d is standardized to “digit”.

What is \W in Perl regex?

Under /a , \d always means precisely the digits "0" to "9" ; \s means the five characters [ \f\n\r\t] , and starting in Perl v5. 18, the vertical tab; \w means the 63 characters [A-Za-z0-9_] ; and likewise, all the Posix classes such as [[:print:]] match only the appropriate ASCII-range characters.

What are the special characters in Perl?

There are three types of character classes in Perl regular expressions: the dot, backslash sequences, and the form enclosed in square brackets. Keep in mind, though, that often the term "character class" is used to mean just the bracketed form. Certainly, most Perl documentation does that.

What does =~ mean in Perl?

=~ is the Perl binding operator. It's generally used to apply a regular expression to a string; for instance, to test if a string matches a pattern: if ($string =~ m/pattern/) {


1 Answers

These are package separators. I suspect the actual code is more like $SomePackage::SomeHash{'SomeKey'}. This syntax allows accessing a "package variable", in this case a hash, from some other package, or by its fully qualified name. You are probably more accustomed to seeing something like:

package SomePackage; 
our %SomeHash; 
$SomeHash{'SomeKey'} # do something with $SomePackage::SomeHash{'SomeKey'} here

A use case is setting up some module, like say Data::Dumper, which uses these package variables to control output:

use Data::Dumper;
local $Data::Dumper::Sortkeys = 1;
print Dumper { c => 3, a => 1, b => 2 };

... though this type of usage is typically avoided by using Object Oriented style.

See also: the famous "Coping with Scoping" article by MJD: http://perl.plover.com/FAQs/Namespaces.html

like image 150
Joel Berger Avatar answered Oct 23 '22 00:10

Joel Berger