467,926 Members | 1,753 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,926 developers. It's quick & easy.

scalar variable declaration

Hi

I have a set of salaras as $a, $b etc..
Since I am using strict and warnings, how do I declare them. I am not initialising to any value. Is there any way to declare them instead of
my $a;
my $b;
...etc

Thanks.
Jul 23 '08 #1
  • viewed: 1694
Share:
2 Replies
numberwhun
Expert Mod 2GB
The 'warnings' pragma is very good to use. It allows you to catch a number of syntactical errors before posting your code here in the forums.

On the other hand, the strict pragma is also good as it forces you to create safe constructs. The only way to declare variables with strict on is by preceding them with "my", "out", or "uise", with the most common one being my as you have already done. Once you do that once though, you don't have to do it again.

Regards,

Jeff
Jul 23 '08 #2
KevinADC
Expert 2GB
Hi

I have a set of salaras as $a, $b etc..
Since I am using strict and warnings, how do I declare them. I am not initialising to any value. Is there any way to declare them instead of
my $a;
my $b;
...etc

Thanks.
If you have a list of variables to declare you can do this:

my ($var, @var, %var, $var2);

That packages them and you can then use them as needed. But don't get into the habit of just declaring all your variables at the beginning of a script, only declare them when and where needed, otherwise they are just global variables and that defeats the purpose of using lexical variables.

I think if you had read the strict pragmas documentation the list declaration is discussed. Try and get used to reading the documentation, it might be confusing sometimes but the more you read it the clearer it becomes.
Jul 23 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

83 posts views Thread by Alexander Zatvornitskiy | last post: by
2 posts views Thread by Thomas Matthews | last post: by
134 posts views Thread by James A. Donald | last post: by
1 post views Thread by G Fernandes | last post: by
3 posts views Thread by Ken Adeniji | last post: by
14 posts views Thread by subramanian100in | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.