> Can it be done?


well, yes.. it's possible to do exactly what you've asked, but there
are other, cleaner ways to do the same thing.


if you have a set of lists:

    @list_one   = (1..5);
    @list_two   = (2..10);
    @list_three = (a..e);
    @list_four  = (j..n);
    @list_five  = (A..Z);

you can store the name of the list you want in a variable, and use
that to reference the list:

    for $item ('one', 'two', 'three', 'four', 'five') {
        $list_name = "list_" . $item;
        print ${ $list_name }[3], "\n";
    }

basically, the interpreter says, "hmm.. there's a variable where i'd
normally expect to see the name of the list.   oh well, i'll just find
out what's in the variable, then see if there's a list that goes by
that name."

that technique has some problems, though.. for one thing, it's a bitch
to try and track down a typo.   if you pass the name of the list in
from a form, f'rinstance, but accidentally type "admiin" instead of
"admin", your script won't work.   that's not such a big deal by
itself, but you can't learn that by looking at the code.


a cleaner way to do the same job, which is also a bit easier to read
and debug, is:

    %PERMISSIONS = (
        'admin',    '1,2,3,4,5',
        'user',     '1,2,3',
    );

    $permission = $PERMISSIONS{ $form_data{'access'} };

    if ( ! defined ($permission) ) {
        &do_error ("no permissions for $form_data{'access'}");
        exit (1);
    }

    @perm_list = split (/,/, $permission);

    for $item (@perm_list) {
        print "<p> $PERMISSIBLE_ARRAY{ $item }\n";
    }


which, if you want to be showy, can be compressed into:

    %PERMISSIONS = (
        'admin',    '1,2,3,4,5',
        'user',     '1,2,3',
    );

    if (defined ($PERMISSIONS{ $form_data{'access'} })) {
        for $item ( split (/,/, $PERMISSIONS{ $form_data{'access'}) ) {
            print "<p> $PERMISSIBLE_ARRAY{ $item }\n";
        }
    } else {
        &do_error ("no permissions for $form_data{'access'}");
    }



of course, if you really want to geek out, you can use what are called
'references', and put the lists directly into the array:

    @auth_admin = ('1', '2', '3', '4', '5');
    @auth_user = ('1', '2', '3');

    %PERMISSIONS = (
        'admin',    \@auth_admin,
        'user',     \@auth_user,
    );

    $permission = $PERMISSIONS{ $form_data{'access'} };

    if ( ! defined ($permission) ) {
        &do_error ("no permissions for $form_data{'access'}");
        exit (1);
    }

    for $item (@{ $permission }) {
        print "<p> $PERMISSIBLE_ARRAY{ $item }\n";
    }


or, at geek levels approaching the toxic:

    %PERMISSIONS = (
        'admin',    [ 1,2,3,4,5 ],
        'user',     [ 1,2,3 ],
    );

    if (defined ($PERMISSIONS{ $form_data{'access'} })) {
        for $item ( @$PERMISSIONS{ $form_data{'access'}) ) {
            print "<p> $PERMISSIBLE_ARRAY{ $item }\n";
        }
    } else {
        &do_error ("no permissions for $form_data{'access'}");
    }







mike stone  <[EMAIL PROTECTED]>   'net geek..
been there, done that,  have network, will travel.



____________________________________________________________________
--------------------------------------------------------------------
 Join The Web Consultants Association :  Register on our web site Now
Web Consultants Web Site : http://just4u.com/webconsultants
If you lose the instructions All subscription/unsubscribing can be done
directly from our website for all our lists.
---------------------------------------------------------------------

Reply via email to