Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: if (defined @arr) problem

by secret (Beadle)
on Dec 15, 2005 at 10:49 UTC ( [id://516922]=note: print w/replies, xml ) Need Help??


in reply to Re^2: if (defined @arr) problem
in thread if (defined @arr) problem

    Still, testing definedness of an array is a very bad idea. Try running this code first:
    @a = qw(a b c);
Ah yes :) that's very true !  scalar @array is, of course, much better !

( i did meant the undef value, btw, and not the string 'undef' but it's true that my use of single quotes was indeed a bad idea !! )

I'll add something : suppose the OP wanted to undef arrays in a sub . I think I would pass the array as a reference, undef it in the sub and return the reference .

Replies are listed 'Best First'.
Re^4: if (defined @arr) problem
by davorg (Chancellor) on Dec 15, 2005 at 11:22 UTC
    I'll add something : suppose the OP wanted to undef arrays in a sub . I think I would pass the array as a reference, undef it in the sub and return the reference.

    In technical discussions terms have precise meanings and it's important to use them in the same way that other people do. I don't think that "undef an array" means what you think it means.

    If you mean to remove all of the elements of the array, then say that. If you want to replace all of the elements with the value undef then say that. Or do you actually mean that you want to call undef @ARRAY? According to the docs that will "forget @ARRAY ever existed". Which of these do you mean?

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

        remove all of the elements of the array

      Well that would be @array = ()

        replace all of the elements with the value undef

      That could be @a = (undef) x scalar @a

      So yes , saying "undef an array" i meant  undef @a . I do think it's what the OP was meaning to do when trying to affect one single undef value to the whole array . This really sounds like undef @array.

      Now about delete for the moment i never got to use it, neither did i use exist . I gather it's because they are used mainly with objects, are they ?

      Regards,
      secret

Re^4: if (defined @arr) problem
by blazar (Canon) on Dec 16, 2005 at 10:14 UTC
    Ah yes :) that's very true ! scalar @array is, of course, much better !
    And while we're here, it's worth reminding that if you use @array in scalar context, then an explicit call to scalar is not needed:
    D'Oh unless @array; # Valid Perl!!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://516922]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-25 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found