Gossamer Forum
Home : Products : DBMan : Customization :

Count of users?

Quote Reply
Count of users?
Hi,

I've currently got this line:

Code:
Welcome, $db_userid! There are currently $count records in the database.

to show how many records there are when you first log on. As my database is still fairly small, I was wondering if there would be a way to also greet them with the number of registered users (about 4 times the number as there are records -- looks much more impressive)?

Thanks,
Dan
Quote Reply
Re: Count of users? In reply to
You can use either

$user_count = $user_count--;

or

$user_count = $user_count-1;

or

$user_count = --$user_count;

or

--$user_count;

or (probably)

$user_count--;

Lots of options. Much of Perl is whatever you prefer.

I'm really grateful for Adam's input. I don't mind at all when he answers things for me. Gives me more time to do other stuff. Smile

------------------
JPD





Quote Reply
Re: Count of users? In reply to
You're getting the count by opening the .db file and putting the contents into an array called @lines, then using
$count = scalar(@lines);
right?

You can do the same thing with the password file. Just copy the code for counting the number of records and use $auth_pw_file instead of $db_file_name. Change
$count to something else -- $user_count would work. Then your printout would be

Code:
Welcome, $db_userid! There are currently $count records in the database and $user_count members.

You may need to open your password file and take out the first line, though. There's a comment line at the beginning of the file. Then again, leaving it in will only inflate your user count by 1. Smile


------------------
JPD





Quote Reply
Re: Count of users? In reply to
Or if you want to leave it in there, just after you get the number, go;

$user_count = $user_count--;

No reason to leave it in there though...

Smile

adam

[This message has been edited by dahamsta (edited May 29, 1999).]
Quote Reply
Re: Count of users? In reply to
Thank you so much for the quick help. Smile That was sure easy! Carol, you were correct as to how I was getting the records count. I took Adam's advice and subtracted one, as I sort of like having the comment line in the password file to remind me what the fields signify.

Adam, I'm assuming you meant to write
$user_count = $user_count-1;
? That's what worked for me.

By the way, me thinks Adam is subtly pushing up on your territory, Carol. His response time is within single digit minutes of yours. Wink Is there a moderator position up for grabs?

Dan
Quote Reply
Re: Count of users? In reply to
Hmm, that's odd. The first method ( $user_count--; ) didn't work for me. No errors, but it didn't subtract one. One of these days I need to get a book and try to get a grasp on this little Perl language...

Dan

[This message has been edited by Dan Kaplan (edited May 29, 1999).]
Quote Reply
Re: Count of users? In reply to
This is a little explanation from "Programming Perl."

"If you place one of the auto operators before the variable, it is known as a pre-incremented (pre-decremented) variable. Its value will be changed before it is referenced. If it is placed after the variable, it is known as a post-increment(post-decrement) variable and is changed after it is used."

Since you were referencing the same variable, I thought it would work to have the decrement operator after the variable. I guess not. Smile

You should be able to use

--$user_count;

though, which is about as short a command as you can get.


------------------
JPD





Quote Reply
Re: Count of users? In reply to
Well, perlop says:

Quote:
``++'' and ``--'' work as in C. That is, if placed before a variable, they increment or decrement the variable before
returning the value, and if placed after, increment or decrement the variable after returning the value.

I'm a bit fuzzy headed this morning, so I'm not sure what that means...

Smile

adam
Quote Reply
Re: Count of users? In reply to
Hi folks,

I'm not going to go into it now, because I'm very (very) drunk, but I can tell you that:

$var--;

and:

--$var;

...are quite different. From what I understand, the way to decrement a variable is:

$var--;

I shall do my best to study this in the intervening moments. Now, if you'll pardon moi, we have a grand prix commencing in a few short hours, and I've been told (quite reliably) that I require (at least) two hours sleep beforehand. Mammy's huh?

adam

(why am i here?)
Quote Reply
Re: Count of users? In reply to
Maybe an example will help. Again, from "Programming Perl":

Quote:
$a = 5;
$b = ++$a; # $b is assigned to the incremented value of $a, 6
$c = $a--; # $c is assigned 6, then $a is decremented to 5

Which is still unclear in the context of
$user_count = $user_count--;

But you can use either

$user_count--;

or

--$user_count;

Same result.

------------------
JPD