how to refer to array data with aliases??? 
Author Message
 how to refer to array data with aliases???

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc,

:another newbie question:
:i have an array with several fields.  to make the script more readable, i want
:to refer to the different items in the array by names (aliases).  is there a
:way to do this?  right now, i'm having to write the data to new variables -
:a waste of memory.

:        ...
:    }

:any help would be greatly appreciated.

First, I must once again strongly counsel you *NOT* to use all uppercase
identifiers especially of such common things: you have in fact just
accidentally attempted to reset your real user and group IDs by assigning
to $UID and $GID.  Perl uses these for its own purposes (at least, it does
when you ask to use the English translations of this stuff).

when you really mean $var[2].  Please think about these:

    $var        = `ls`;
    $var[2]     = `ls`;

    ($var[2])   = `ls`;

In fact, the compiler will notify you of this as of sometime early in 1994.

Now, for what you are doing, you could said

    $fieldno = 0;
    foreach $name ( qw(login passwd uid gid gcos dir shell) ) {
        ${ "pw_$name" } = $fieldno++;

And then you could saw

    if ($pwent[$pw_dir] eq '/') { ... }

Now, for some of you reading this, you might like to know that a much
better solution is my Struct interface, in which you can do this:

    $pwent = getpwnam("someone");
    if ($pwent->pw_dir eq '/') { ... }

The interface is set and a working prototype exists, but I need to rewrite
it so it works properly for inheritance purposes.


    "They'll get my perl when they pry it from my cold, dead /usr/local/bin."

Wed, 15 Apr 1998 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Referring to an array in an array...

2. Referring to an array in an array...

3. File handles referring to non-file data.

4. How to best refer to sections of 2D arrays

5. how to refer to the array?

6. Referring to multidimensional arrays

7. ANNOUNCE: Alias-2.0 - give that data a name

8. lists direct sendmail aliases for a user/aliasname

9. adding to arrays, testing strings (implementing aliases)

10. No data entering @array from open(DATA...)

11. Referencing data in an array of arrays

12. URGENT and Easy : How to acces Data in an array of array with foreach


Powered by phpBB® Forum Software