GLOBAL Variables with qw()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Icecrack
    Recognized Expert New Member
    • Sep 2008
    • 174

    GLOBAL Variables with qw()

    Thanks in Advance,

    when declaring GLOBAL Variables can we use qw() ?

    example:
    Code:
    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
  • nithinpes
    Recognized Expert Contributor
    • Dec 2007
    • 410

    #2
    'my' is used to declare local variables. To declare multiple variables at once, you may use:
    Code:
    my ($data,$id,$test,$var);
    qw() can be used only on RHS of any assignment statement, as in:
    Code:
    my @a = qw(ad sat d f g);

    -Nithin

    Comment

    • Icecrack
      Recognized Expert New Member
      • Sep 2008
      • 174

      #3
      Originally posted by nithinpes
      'my' is used to declare local variables.
      Thank's i know that you may use:

      Code:
      use var qw($test $perl $var $etc);

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32662

        #4
        Charlie,

        There seems to have been a little misunderstandin g 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.

        Comment

        • KevinADC
          Recognized Expert Specialist
          • Jan 2007
          • 4092

          #5
          Originally posted by Icecrack
          Thanks in Advance,

          when declaring GLOBAL Variables can we use qw() ?

          example:
          Code:
          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.

          Code:
          $foo = 'test';
          my @list = qw($foo);
          print $list[0];
          prints $foo

          Comment

          • KevinADC
            Recognized Expert Specialist
            • Jan 2007
            • 4092

            #6
            Originally posted by Icecrack
            Thank's i know that you may use:

            Code:
            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.

            Comment

            • Icecrack
              Recognized Expert New Member
              • Sep 2008
              • 174

              #7
              Originally posted by KevinADC
              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

              Comment

              Working...