Thread: Toggle list

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Toggle list


    Could you please give me a hint how to create a user toggle list like following?

    #!/usr/bin/perl
    $currentuser = $ENV{'USER'};
    @allow_list = (user1, user2, user3) = 1
    @deny_list = ($currentuser ne $allow_list) = 0
    @deny_all = ????? =0
    @allow_all=???? = 0

    If someone change from 0 to 1 in above list then whatever the program is, it will take that value and behave accordingly.

    Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    836
    Rep Power
    496
    Hi,

    not sure what you want to do, but there are a number of things that will not work in your code (it probably won't even compile).

    First, add the following pragmas:

    Perl Code:
    use strict;
    use warnings;


    This will give you a lot of information about faulty constructs in your code.

    Second, this line:

    Perl Code:
    @allow_list = (user1, user2, user3) = 1


    has the following defacts:
    - it contains 3 bare words (user1, etc.); if they are supposed to be scalar variables, add the $ sigil at their begijnning;
    - there is no semi-colon at the end;
    - it probably does not do what you want.

    Even if you correct the obvious mistakes as:

    Perl Code:
    my ($user1, $user2, $user3) ;
    @allow_list = ($user1, $user2, $user3) = 1;


    this will set $user1 to 1, $user 2 and 3 to undef, and @allow_list to an array whose first element is the value of$user1 (i.e.: 1) and whose se'cond and third element are undefined. I doubt that this is what you want.

    The next line:

    Code:
    @deny_list = ($currentuser ne $allow_list) = 0
    will not compile, due to the absence of semi-colon, and also does not make sense because you can't assign a value to a comparison between two variables. In addition, since one of the variables is an array and the other a scalar (an undefined scalar, BTW), this comparison is unlikely to give what you expect (although I don't even know what you expect).

    I have no idea of what you are trying to do with the next two lines, but, at the very least, they also lack semi-colons.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0
    Thanks guys to take a look into it and sorry for confusion. Let me try to explain: Acutally we have a program which some time we like to enable to all users, some time deny to all and some time permit to execute this command to partial list of users. When users run this program, backend logic first check this script and verify which users are allowed to execute it. What I want instead of changing script logic again and again, I would like to set toggle list so if allow_users has value 1, means it is enabled and others should have value 0, so no one else can run this program. To acheive this I would like to set four toggle lists, allow_all, deny_all, allow_users (a list of users) and deny_users (a list of users).
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,940
    Rep Power
    1225
    Using four arrays like that is very kludgy.

    Instead, create a database of your users where one of the fields is a boolean named "authorized". Your script would query the DB and based on the value of that field either allow or disallow the script to continue. You also would what/need to write an admin script that allows you to update the authorization status as needed.

    Using this approach is clean, much more robust and scales well.
  8. #5
  9. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0
    Perl 6 is a sister language, part of the Pearl family. Perl 6 is not yet ready for production, you can engage with evolution though.

IMN logo majestic logo threadwatch logo seochat tools logo