|
Joined: Sep 2001
Posts: 379
Member
|
Member
Joined: Sep 2001
Posts: 379 |
I'm a little bit lost here... eh, I'm trying to write a rather simple statement using if-elsif and those freakin' logical operators confuse me. This is what I've come up with so far (but doesn't work as expected): code:
# get status line $status_sep = " "; $append_overwrite = $vars_idle{append_status}; if ($user_profile[31] ne "" && $append_overwrite eq "APPEND"
|
|
|
|
Joined: Aug 2000
Posts: 335
Member
|
Member
Joined: Aug 2000
Posts: 335 |
Could you post a bit more of your code, and explain what "doesn't work as expected" means?
|
|
|
|
Joined: Sep 2001
Posts: 379
Member
|
Member
Joined: Sep 2001
Posts: 379 |
Sorry, but UBB didn't like my code and everything is screwed (note that I'm shown as "Unregistered"). I contacted Allen and asked him to delete those two topics I posted, I'll start a new one with a link to my code so UBB doesn't screw up again. :rolleyes: Edit: Wow, I can reply now, and edit! Weird... Anyway, the code can be viewed from here . Thanks!
|
|
|
|
Joined: Aug 2000
Posts: 335
Member
|
Member
Joined: Aug 2000
Posts: 335 |
I think this does what you want: code:
# get status line
my $status_sep = ' '; my $status = $user_profile[8]; my $custom_status = $user_profile[31]; my $custom_title = &CustomTitle($status);
if (($status eq 'Moderator'
|
|
|
|
Joined: Aug 2000
Posts: 335
Member
|
Member
Joined: Aug 2000
Posts: 335 |
(This board is messed up, so I'll try again.)
I think this does what you want:
# get status line
my $status_sep = ' '; my $status = $user_profile[8]; my $custom_status = $user_profile[31]; my $custom_title = &CustomTitle($status);
if (($status eq 'Moderator' || $status eq 'Administrator') && $vars_idle{append_status} eq 'APPEND') { $user_status = $custom_title . ($custom_status ? "$status_sep$custom_status" : ''); } else { # overwrite $user_status = $custom_status ? $custom_status : $custom_title; }
|
|
|
|
Joined: Sep 2001
Posts: 379
Member
|
Member
Joined: Sep 2001
Posts: 379 |
"Messed up" sounds about right... I have no idea why it doesn't like my code. :rolleyes: Thanks, I'll give it a try (but if it doesn't work, "I'll be back!")! Edit: Nope, that doesn't seem to do the trick, either.
|
|
|
|
Joined: Aug 2000
Posts: 335
Member
|
Member
Joined: Aug 2000
Posts: 335 |
"doesn't seem to do the trick"
Could elaborate on that? I.e., how do the results differ from what you want?
|
|
|
|
Joined: Sep 2001
Posts: 379
Member
|
Member
Joined: Sep 2001
Posts: 379 |
When I set it to append mode, and my admin/mod has a custom status, all it returns is the moderator/admin status.
|
|
|
|
Joined: Aug 2000
Posts: 335
Member
|
Member
Joined: Aug 2000
Posts: 335 |
I've added some debug prints (universal debugging technique #1). Try this, and post at least one START-END section from the debug.txt file which has incorrect results.
my $status_sep = ' '; my $status = $user_profile[8]; my $custom_status = $user_profile[31]; my $custom_title = &CustomTitle($status);
my $debug_file = "$vars_config{VariablesPath}/debug.txt"; # comment-out this line to suppress debug output if ($debug_file) { open(my $debug_fh, '>>', $debug_file) or die "$!"; print $debug_fh "START, append-status hack, @{[scalar localtime]}n"; print $debug_fh "status_sep='$status_sep'n"; print $debug_fh "status='$status'n"; print $debug_fh "custom_status='$custom_status'n"; print $debug_fh "custom_title='$custom_title'n"; print $debug_fh "append_status='@{[$vars_idle{append_status}]}'n"; }
if (($status eq 'Moderator' || $status eq 'Administrator') && $vars_idle{append_status} eq 'APPEND') { $user_status = $custom_title . ($custom_status ? "$status_sep$custom_status" : ''); } else { # overwrite $user_status = $custom_status ? $custom_status : $custom_title; }
if ($debug_file) { print $debug_fh "user_status='$user_status'n"; print $debug_fh "ENDn"; close($debug_fh) or warn "$!"; }
|
|
|
|
Joined: Sep 2001
Posts: 379
Member
|
Member
Joined: Sep 2001
Posts: 379 |
It just throws an error at me... Says it can't use an undefined value as a symbol reference at print $debug_fh "user_status='$user_status'n";
|
|
|
|
Joined: Aug 2000
Posts: 335
Member
|
Member
Joined: Aug 2000
Posts: 335 |
Ok, add my $user_status = ''; at the top (after my $custom_title = ...).
|
|
|
|
Joined: Sep 2001
Posts: 379
Member
|
Member
Joined: Sep 2001
Posts: 379 |
|
|
|
|
Joined: Aug 2000
Posts: 335
Member
|
Member
Joined: Aug 2000
Posts: 335 |
Oops, I declared $debug_fh in the wrong scope. Here's the corrected code:
my $status_sep = ' '; my $status = $user_profile[8]; my $custom_status = $user_profile[31]; my $custom_title = &CustomTitle($status); my $user_status = '';
my $debug_file = "$vars_config{VariablesPath}/debug.txt"; # comment-out this line to suppress debug output my $debug_fh; if ($debug_file) { open($debug_fh, '>>', $debug_file) or die "$!"; print $debug_fh "START, append-status hack, @{[scalar localtime]}n"; print $debug_fh "status_sep='$status_sep'n"; print $debug_fh "status='$status'n"; print $debug_fh "custom_status='$custom_status'n"; print $debug_fh "custom_title='$custom_title'n"; print $debug_fh "append_status='@{[$vars_idle{append_status}]}'n"; }
if (($status eq 'Moderator' || $status eq 'Administrator') && $vars_idle{append_status} eq 'APPEND') { $user_status = $custom_title . ($custom_status ? "$status_sep$custom_status" : ''); } else { # overwrite $user_status = $custom_status ? $custom_status : $custom_title; }
if ($debug_file) { print $debug_fh "user_status='$user_status'n"; print $debug_fh "ENDn"; close($debug_fh) or warn "$!"; }
|
|
|
|
Joined: Sep 2001
Posts: 379
Member
|
Member
Joined: Sep 2001
Posts: 379 |
Oops, I'm stupid. Forgot to set my custom title... Here: START, append-status hack, Fri Apr 5 22:35:32 2002 status_sep=' ' status='Moderator' custom_status='UBB Haxxor' custom_title='Cop' append_status='' user_status='UBB Haxxor' END
Seems like it doesn't read from vars_idle anymore or what?
|
|
|
|
Joined: Aug 2000
Posts: 335
Member
|
Member
Joined: Aug 2000
Posts: 335 |
Don't know about %vars_idle. Are you loading it the same way that the standard vars_ hashes are loaded?
|
|
|
|
Joined: Sep 2001
Posts: 379
Member
|
Member
Joined: Sep 2001
Posts: 379 |
Yap. The vars_idle are read using my code, but not when I use your's for some reason...
|
|
|
|
Joined: Aug 2000
Posts: 335
Member
|
Member
Joined: Aug 2000
Posts: 335 |
I added an $append_status variable like you were using originally. If that doesn't work, I'm out of ideas.
my $status_sep = ' '; my $status = $user_profile[8]; my $custom_status = $user_profile[31]; my $custom_title = &CustomTitle($status); my $append_status = $vars_idle{append_status}; my $user_status = '';
my $debug_file = "$vars_config{VariablesPath}/debug.txt"; # comment-out this line to suppress debug output my $debug_fh; if ($debug_file) { open($debug_fh, '>>', $debug_file) or die "$!"; print $debug_fh "START, append-status hack, @{[scalar localtime]}n"; print $debug_fh "status_sep='$status_sep'n"; print $debug_fh "status='$status'n"; print $debug_fh "custom_status='$custom_status'n"; print $debug_fh "custom_title='$custom_title'n"; print $debug_fh "append_status='$append_status'n"; }
if (($status eq 'Moderator' || $status eq 'Administrator') && $append_status eq 'APPEND') { $user_status = $custom_title . ($custom_status ? "$status_sep$custom_status" : ''); } else { # overwrite $user_status = $custom_status ? $custom_status : $custom_title; }
if ($debug_file) { print $debug_fh "user_status='$user_status'n"; print $debug_fh "ENDn"; close($debug_fh) or warn "$!"; }
|
|
|
|
Joined: Sep 2001
Posts: 379
Member
|
Member
Joined: Sep 2001
Posts: 379 |
Doesn't work either. :rolleyes: But thanks for your help, the debug part will be useful if I keep on playing around with my code.
|
|
|
|
Joined: Sep 2001
Posts: 379
Member
|
Member
Joined: Sep 2001
Posts: 379 |
I got it! Works like a charm now. I appreciate your help, it was a good reminder for me. Most of the time if-else statements confuse the hell out of me, so I try to go for something complex and ugly looking... I got it to do what I want in 8 lines of code, instead of 20 or so.
|
|
|
|
Joined: Aug 2000
Posts: 335
Member
|
Member
Joined: Aug 2000
Posts: 335 |
In the past, I've found decision tables useful when dealing with complex if-else situations. I just did a web search, and came up with this link . There may be better references. By the way, how did you fix the problem? (just curious)
|
|
|
|
Joined: Sep 2001
Posts: 379
Member
|
Member
Joined: Sep 2001
Posts: 379 |
I removed the status checking (Moderator/Administrator) after figuring out this would affect normal members in some awful way (no status shown at all, haha).
Here's the finished code: -------------------------
# get status line &RequireVars("$vars_config{VariablesPath}/vars_idle.cgi"); # get status separator if ($vars_idle{status_sep} ne ''){ $status_sep = "$vars_idle{status_sep}"; } else { $status_sep = " "; }# end get status separator $status = $user_profile[8]; $custom_status = $user_profile[31]; if ($vars_idle{append_status} eq 'APPEND' && $custom_status ne '') { $user_status = &CustomTitle($status) . $status_sep . $user_profile[31]; } elsif ($vars_idle{append_status} eq 'APPEND' && $custom_status eq '') { $user_status = &CustomTitle($status); } elsif ($vars_idle{append_status} eq 'OVERWRITE' && $custom_status ne '') { $user_status = $user_profile[31]; } elsif ($vars_idle{append_status} eq 'OVERWRITE' && $custom_status eq '') { $user_status = &CustomTitle($status); } #end get status line -------------------------
I don't get it, but sometimes it would read vars_idle.cgi, sometimes not. So I added the RequireVars and "completed" the if-elsif part so I'd definately get the status looking the way I want it to be.
Interesting site, by the way. Thanks!
|
|
|
Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.
Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
|
|
Posts: 417
Joined: November 2001
|
|
Forums63
Topics37,573
Posts293,925
Members13,849
|
Most Online5,166 Sep 15th, 2019
|
|
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
|
|
|
|