undefine @array

Discussion in 'Perl Misc' started by George Mpouras, Aug 22, 2012.

  1. I want to delete an array completly.

    use strict; use warnings; my
    @array=qw/a b c/;
    @array=();
    undef @array;
    print @array;

    I expect a warning like "Global symbol "@array" requires explicit..." but it
    did not compaint
     
    George Mpouras, Aug 22, 2012
    #1
    1. Advertising

  2. yes I want to clear symbol @array completly but at the same scope
     
    George Mpouras, Aug 22, 2012
    #2
    1. Advertising

  3. George Mpouras

    Tim McDaniel Guest

    George Mpouras <> wrote:
    > I expect a warning like "Global symbol "@array" requires explicit..."
    > but it did not compaint


    but later
    >yes I want to clear symbol @array completly but at the same scope


    These goals are not consistent. As Eli explained, that is not
    possible in Perl.

    If you clear an array, like
    my @array;
    ...
    @array = ();
    or
    my @array;
    ...
    undef @array;
    that sets @array to have zero elements, but @array still exists as a
    variable and you will not get a message for using @array later.

    "Global symbol ... requires explicit" is an error, not a warning, so
    far as I know. The only way to get that error is to declare @array in
    a scope that ends, like
    {
    my @array = (12, 14, 16);
    ...
    }

    --
    Tim McDaniel,
     
    Tim McDaniel, Aug 22, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UmljaA==?=
    Replies:
    15
    Views:
    8,087
    aparnalr
    Sep 14, 2011
  2. Rafal 'Raf256' Maj

    undefine all macros from a file

    Rafal 'Raf256' Maj, Jan 19, 2005, in forum: C++
    Replies:
    1
    Views:
    3,008
    Jonathan Turkanis
    Jan 19, 2005
  3. Alden Pierre
    Replies:
    7
    Views:
    414
  4. Pietro Cerutti

    undefine for functions

    Pietro Cerutti, Aug 30, 2007, in forum: C Programming
    Replies:
    8
    Views:
    393
    Eric Sosman
    Aug 31, 2007
  5. T Ryi

    Undefine a function from header file

    T Ryi, Mar 24, 2010, in forum: C Programming
    Replies:
    6
    Views:
    718
    Kenny McCormack
    Mar 25, 2010
Loading...

Share This Page