By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,903 Members | 1,104 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,903 IT Pros & Developers. It's quick & easy.

GLOBAL Variables with qw()

Icecrack
Expert 100+
P: 174
Thanks in Advance,

when declaring GLOBAL Variables can we use qw() ?

example:
Expand|Select|Wrap|Line Numbers
  1. my qw($data $id $test $var);
etc.


i will be testing this but if any one knows with in the next 1 hr please post
thanks

Thank You,

Charlie
Oct 3 '08 #1
Share this Question
Share on Google+
6 Replies


nithinpes
Expert 100+
P: 410
'my' is used to declare local variables. To declare multiple variables at once, you may use:
Expand|Select|Wrap|Line Numbers
  1. my ($data,$id,$test,$var); 
  2.  
qw() can be used only on RHS of any assignment statement, as in:
Expand|Select|Wrap|Line Numbers
  1. my @a = qw(ad sat d f g);
  2.  

-Nithin
Oct 3 '08 #2

Icecrack
Expert 100+
P: 174
'my' is used to declare local variables.
Thank's i know that you may use:

Expand|Select|Wrap|Line Numbers
  1. use var qw($test $perl $var $etc);
Oct 3 '08 #3

NeoPa
Expert Mod 15k+
P: 31,530
Charlie,

There seems to have been a little misunderstanding about what the Experts area is for.

Not a problem. I can move this thread for you, but technical questions still go in the relevant technical forum.

The Experts forum is for directing the attention of other experts to a tricky problem thread, or discussing issues related to the experts generally.
Oct 5 '08 #4

KevinADC
Expert 2.5K+
P: 4,059
Thanks in Advance,

when declaring GLOBAL Variables can we use qw() ?

example:
Expand|Select|Wrap|Line Numbers
  1. my qw($data $id $test $var);
etc.


i will be testing this but if any one knows with in the next 1 hr please post
thanks

Thank You,

Charlie

If you look up qw in perl operators you will see it also does not interpolate variables. In other words, its the same as using single-quotes, so scalars will not be interpolated when used in a qw list.

Expand|Select|Wrap|Line Numbers
  1. $foo = 'test';
  2. my @list = qw($foo);
  3. print $list[0]; 
prints $foo
Oct 5 '08 #5

KevinADC
Expert 2.5K+
P: 4,059
Thank's i know that you may use:

Expand|Select|Wrap|Line Numbers
  1. use var qw($test $perl $var $etc);
Yes that is OK, because it supplies a list to the vars pragma. Note that "vars" is obsolete but still supported.
Oct 5 '08 #6

Icecrack
Expert 100+
P: 174
Yes that is OK, because it supplies a list to the vars pragma. Note that "vars" is obsolete but still supported.

Thank you all for your input,

Charlie
Oct 8 '08 #7

Post your reply

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