CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Help updating a simple if statement

 



runner16
New User

Aug 28, 2012, 7:49 AM

Post #1 of 5 (936 views)
Help updating a simple if statement Can't Post

I'm have very little knowledge of perl. I'm hoping someone can help me do a simple update to an if statement.

How can I add another user to this if statement? That is, only user1, user2 or the original author can edit.


Code
      # Only "user1" or the original author can edit. 
if ( $regname ne "user1" && $author ne $regname )


Thank you for any assistance.


FishMonger
Veteran / Moderator

Aug 28, 2012, 7:58 AM

Post #2 of 5 (931 views)
Re: [runner16] Help updating a simple if statement [In reply to] Can't Post

Instead of extending the if statement, my recommendation would be to crate a hash of the authorized users and then do a simple and efficient hash lookup.


Code
my %authorized_user = ( 
'user1' => 1,
'user2' => 1,
'user3' => 1,
);

if ( ! $authorized_user{$regname} ) {



runner16
New User

Aug 28, 2012, 8:12 AM

Post #3 of 5 (927 views)
Re: [FishMonger] Help updating a simple if statement [In reply to] Can't Post

Thanks FishMonger. I can give that a try. However, where it is a large file, I would feel a bit more comfortable with extending the if statements that I need to update (add another user to each statement). Is that method possible?


Laurent_R
Veteran / Moderator

Aug 28, 2012, 8:34 AM

Post #4 of 5 (925 views)
Re: [runner16] Help updating a simple if statement [In reply to] Can't Post

I think FishMonger's proposal really makes sense, as it make it far easier to authorize again new users in the future.

But if you insist on keeping the existing syntax, you can do simply this:


Code
if ( $regname ne "user1" && $regname ne $author  && $regname ne "user2" )



runner16
New User

Aug 28, 2012, 11:41 AM

Post #5 of 5 (914 views)
Re: [Laurent_R] Help updating a simple if statement [In reply to] Can't Post

Thank you!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives