http://www.perlmonks.org?node_id=892916


in reply to My questions: new to perl

Explain difference between my and local ?

To explain the differences, there would have to similarities.

my creates a lexically scoped variable.

local temporarily saves a package variable, (Upd: array element or hash element. ) The previous value of the variable will be restored when the current scope is exited.

What is the purpose of -w , strict , -T ?

See perlrun for -w and -T.

strict detects errors that aren't detected by default for backwards compatibility reasons.

How do we set environment variables in perl ?

Assign to %ENV. See perlvar.

How to turn on perl warnings? Why is this important ?

use warnings; detects lots of situations which are very likely to have resulted from errors.

What are scalar data and scalar variables ?

"Scalar data" is by no means a formal term. I've never heard it. It probably refers to values that can be assigned to a scalar.

Scalar variables are one of Perl's variable types. They hold one* the following: a string, a signed integer, an unsigned integer, a floating point number, a string (array of 8-bit characters), a string (array of 32/64-bit characters), a reference or a glob.

(Upd: See perldata. )

* — Sometimes more than one, such as both the integer 123 and the string "123". These are optimisations or very special cases called "dualvars".

How do we read command line arguments with perl ?

They are provided in @ARGV. See perlvar.

Why does perl donot have overload functions ?

If there isn't, it's because noone coded a way of doing it.

How we sort a hash by the hash key ?

By definition, hashes can't be sorted. Their keys or values can be sorted.

(Upd: Magic can be used to alter their implementation. See reply for some modules that do this. )

How chomp( ) function and chop differs ?

chomp vs chop.