Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does '$::n' mean for perl?

Tags:

perl

Do you know what "$::n;" means ? The section of codes is like below.

use JSON::XS;
# ...
open (YI, "| $cmd");
my $msg = { test => test };
my $emsg = encode_json($msg);
print YI "$msg_inject\n" unless $::n;
close YI;`

I remmeber that I also met $::v before. What is $::v ? Does it have additional usage ?

I only know $: is reserved word for a perl statment with more lines being filling in a field.

Best regards,

TWLMD.

like image 448
user3172696 Avatar asked Jan 08 '14 10:01

user3172696


People also ask

What does ~~ mean in Perl?

Just as with the =~ regex match operator, the left side is the "subject" of the match, and the right side is the "pattern" to match against -- whether that be a plain scalar, a regex, an array or hash reference, a code reference, or whatever.

What is $# in Perl?

$#array is the subscript of the last element of the array (which is one less than the length of the array, since arrays start from zero). Assigning to $#array changes the length of the array @array, hence you can destroy (or clear) all values of the array between the last element and the newly assigned position.

What is the difference between -> and => in Perl?

The former is a function call. The latter is a method call.

What does 1 mean in Perl?

1 at the end of a module means that the module returns true to use/require statements. It can be used to tell if module initialization is successful. Otherwise, use/require will fail.


1 Answers

$::n is same as $main::n or just $n where $n is residing in main:: package.

Such notation ignores eventual lexical (defined with my) definition of $n, ie.

perl -Mstrict -we 'our $n=3; my $n=1; print $::n'

output is 3

like image 53
mpapec Avatar answered Sep 18 '22 11:09

mpapec