biswanath_c has asked for the wisdom of the Perl Monks concerning the following question:


Hi,

Can someone tell mw aht's wrong with this code ? I just followed the documentation and other perl code snippets that i got from websites:


use Win32::NetAdmin qw(LoggedOnUsers);

my %users;

Win32::NetAdmin->LoggedOnUsers('cr2rchiis26e', \%users);

@keys = keys %users;

@values = values %users;

while(@keys)

{

print pop(@keys), '=', pop(@values), "\n";

}


I am getting the following error:

Usage: Win32::NetAdmin::LoggedOnUsers(server, $userRef)


Thanks

Replies are listed 'Best First'.
Re: Question in Win32::LoggedOnUsers
by pc88mxer (Vicar) on Jul 02, 2008 at 13:52 UTC
    You are using -> instead of ::, i.e.:
    # try: Win32::NetAdmin::LoggedOnUsers('cr2rchiis26e', \%users); # instead of: Win32::NetAdmin->LoggedOnUsers('cr2rchiis26e', \%users);
Re: Question in Win32::LoggedOnUsers
by jethro (Monsignor) on Jul 02, 2008 at 15:13 UTC
    Just a quick comment on your while loop. It works, but if all you want to do is step through the elements of a hash, the foreach loop is better suited (and more efficient) for the task:

    foreach my $user (keys %users) { print $user,'=', $users{$user},"\n"; }
    Note you don't need the arrays @keys and @values anymore.

      Thanks a lot guys!

      The suggestions worked for me!