Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is @. in Perl?

Tags:

variables

perl

What is the @. variable in perl?

It appears be a special, writeable global, and (surprisingly) does not interpolate in double-quoted strings:

use strict;
use warnings;

                 # Under 5.8, 5.10, 5.12, 5.14, and 5.16,
                 # the following lines produce:

@. = (3, 2, 1);  # no error
print "@.\n";    # "@."
print @., "\n";  # "321"

eval 'my @.; 1'  # Can't use global @. in "my" at (eval 1)
  or die $@;     #  line 1, near "my @."

I couldn't recall ever encountering it before, and didn't see it in perlvar nor perldata.

like image 862
pilcrow Avatar asked Jun 22 '12 18:06

pilcrow


2 Answers

perldoc perlvar states:

Perl variable names may also be a sequence of digits or a single punctuation or control character. These names are all reserved for special uses by Perl;

and

Perl identifiers that begin with digits, control characters, or punctuation characters are exempt from the effects of the package declaration and are always forced to be in package main; they are also exempt from strict 'vars' errors.

You are using a reserved name. You should not expect to be able to rely on any features.

like image 101
Sinan Ünür Avatar answered Sep 28 '22 09:09

Sinan Ünür


$. is current line number (or record number) of most recent filehandle.

@. has no special meaning or use


"@." does not interpolate, but "@{.}" does.

@. is reserved for future use and should not be used

like image 32
Ωmega Avatar answered Sep 28 '22 08:09

Ωmega