471,873 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,873 software developers and data experts.

GLOBAL Variables with qw()

Icecrack
174 Expert 100+
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
6 7243
nithinpes
410 Expert 256MB
'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
174 Expert 100+
'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
32,468 Expert Mod 16PB
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
4,059 Expert 2GB
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
4,059 Expert 2GB
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
174 Expert 100+
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.

Similar topics

4 posts views Thread by Andrew V. Romero | last post: by
5 posts views Thread by Sandman | last post: by
8 posts views Thread by rottmanj | last post: by
112 posts views Thread by istillshine | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.