in reply to Perl array declaring
See perldata.
A variable (a symbol which lets you reference some data) in perl is ruled by two constraints, or boundaries, or scopes:
Package scoped variables are recorded in the symbol table of their associated namespace.
The default namespace is main, and its symbol table is accessible via the hash %main:: (or shorthand %::).
This scope can span files.
Lexical scoped variables are visible only in the current BLOCK, file or eval.
These variables are not associated with any symbol table, but rather with their (static) execution path.
The package variables are either just written without any declaration (e.g $file = "myfile.txt"; - the strict pragma forbids that), used fully qualified (e.g. $main::file = "myfile.txt"; (that is ok under strict) or declared with our (e.g. our $file = "myfile.txt";). The our creates a symbol table entry for a variable declared that way and a lexical alias for that symbol.
The lexical variables are declared with my (e.g. my $file = "myfile.txt";). At runtime, they are reset when their scope is entered.
Just for completeness - a package variable can be used in a lexical sort of way, too - masking the original symbol table variable slot with a local declaration. They are valid during the execution time in the current scope, even branching to different files.
Phew. Now back to your question:
Hello i am a new to Perl and i am trying to understand what is differences between declare :my @array or @arry?
Short answer:
If anything of the above is unclear, just ask again.
|
|---|