Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Sep 2001
Posts: 379
Member
Member
Offline
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"

Sponsored Links
Joined: Aug 2000
Posts: 335
Member
Member
Offline
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
Offline
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
Offline
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
Offline
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;
}

Sponsored Links
Joined: Sep 2001
Posts: 379
Member
Member
Offline
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!")! smile

Edit: Nope, that doesn't seem to do the trick, either.

Joined: Aug 2000
Posts: 335
Member
Member
Offline
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
Offline
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
Offline
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
Offline
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";

Sponsored Links
Joined: Aug 2000
Posts: 335
Member
Member
Offline
Joined: Aug 2000
Posts: 335
Ok, add my $user_status = ''; at the top (after my $custom_title = ...).

Joined: Sep 2001
Posts: 379
Member
Member
Offline
Joined: Sep 2001
Posts: 379
Same error...

Joined: Aug 2000
Posts: 335
Member
Member
Offline
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
Offline
Joined: Sep 2001
Posts: 379
Oops, I'm stupid. Forgot to set my custom title... shocked

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
Offline
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
Offline
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
Offline
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
Offline
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. smile

Joined: Sep 2001
Posts: 379
Member
Member
Offline
Joined: Sep 2001
Posts: 379
I got it!
Works like a charm now. smile

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. laugh

Joined: Aug 2000
Posts: 335
Member
Member
Offline
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
Offline
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!


Link Copied to Clipboard
Donate Today!
Donate via PayPal

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.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
Gizmo
Gizmo
Portland, OR, USA
Posts: 5,833
Joined: January 2000
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)