Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 4th, 2012, 10:32 AM
Kumarsanu Kumarsanu is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 Kumarsanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 45 sec
Reputation 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

Reply With Quote
  #2  
Old October 4th, 2012, 11:04 AM
Laurent_R Laurent_R is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2012
Posts: 507 Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 4 Days 19 h 12 m 26 sec
Reputation Power: 385
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:
Original - Perl Code
  1. use strict;
  2. use warnings;


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

Second, this line:

Perl Code:
Original - Perl Code
  1. @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:
Original - Perl Code
  1. my ($user1, $user2, $user3) ;
  2. @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.

Reply With Quote
  #3  
Old October 4th, 2012, 02:17 PM
Kumarsanu Kumarsanu is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 Kumarsanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 45 sec
Reputation 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).

Reply With Quote
  #4  
Old October 4th, 2012, 08:31 PM
FishMonger FishMonger is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2009
Posts: 1,649 FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 2 h 2 m 34 sec
Reputation Power: 1170
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.

Reply With Quote
  #5  
Old October 5th, 2012, 07:17 AM
TheTechguys TheTechguys is offline
Permanently Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 8 TheTechguys User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 49 sec
Warnings Level: 10
Number of bans: 1
Reputation 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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Toggle list

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap