IWETHEY v. 0.3.0 | TODO
1,095 registered users | 1 active user | 1 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Idiot Perl Question
I'm sure I'm doing something super-stupid, but here goes:

#!/usr/bin/perl -w\n\nuse Win32::NetAdmin qw(LocalGroupGetMembers);\nuse Win32;\n\n\nmy $domain = "SERCO_GUIS";\nmy $pdc = "\\\\GUIS_FIL_SERVER";\nmy %groups;\n\nwhile (<>) {\n  chomp;\n  my $currentgroup = $_;\n  print "$currentgroup\\n";\n  my @currentgroupmembers;\n  if (!LocalGroupGetMembers($pdc, $currentgroup, \\@currentgroupmembers)) {\n    print "$^E\\n"; # print error code\n  }\n  $groups{$currentgroup} = @currentgroupmembers;\n}\n\nforeach $group(keys %groups) {\n  print "$group: @ { $groups{$group} }\\n";\n}


It prints out the number of elements in each group, rather than the actual members.

I can see two possible points of failure here: either the "$groups{$currentgroup} = @currentgroupmembers;" assignment, or my expansion of the hash at the end.

Clues?


Peter
[link|http://www.debian.org|Shill For Hire]
[link|http://www.kuro5hin.org|There is no K5 Cabal]
[link|http://guildenstern.dyndns.org|Blog]
New Your first guess was right
In scalar context, Perl arrays give you the number of elements in the array. Either of the following should fix it:\r\n
\r\n  my $currentgroupmembers = [];\r\n  if (!LocalGroupGetMembers($pdc, $currentgroup, $currentgroupmembers)) {\r\n    print "$^E\\n"; # print error code\r\n  }\r\n  $groups{$currentgroup} = $currentgroupmembers;\r\n
\r\nor\r\n
\r\n  $groups{$currentgroup} = \\@currentgroupmembers;\r\n
\r\nAn incidental style nit. I find that long names like that become clearer if you put _ between the words. So currentgroupmembers becomes current_group_members.

\r\n\r\nCheers,
\r\nBen
"good ideas and bad code build communities, the other three combinations do not"\r\n- [link|http://archives.real-time.com/pipermail/cocoon-devel/2000-October/003023.html|Stefano Mazzocchi]
New Muchas grazie
And don't even ask why I'm enumerating Windows domain local groups in Perl.


Peter
[link|http://www.debian.org|Shill For Hire]
[link|http://www.kuro5hin.org|There is no K5 Cabal]
[link|http://guildenstern.dyndns.org|Blog]
New This job is a sore point I guess?
"good ideas and bad code build communities, the other three combinations do not"
- [link|http://archives.real-time.com/pipermail/cocoon-devel/2000-October/003023.html|Stefano Mazzocchi]
New He *said* don't ask, didn't he? :-P
===

Implicitly condoning stupidity since 2001.
New But I didn't ask...
at least not the question that he asked me not to ask. :-P

Cheers,
Ben
"good ideas and bad code build communities, the other three combinations do not"
- [link|http://archives.real-time.com/pipermail/cocoon-devel/2000-October/003023.html|Stefano Mazzocchi]
New Let's just say it's not a pretty sight...
It is a head scratcher, I even got some straw thrown my way during the discussion of it.

Purty Ugly.
--
[link|mailto:greg@gregfolkert.net|greg],
[link|http://www.iwethey.org/ed_curry|REMEMBER ED CURRY!] @ iwethey

Blaphemer!
     Idiot Perl Question - (pwhysall) - (6)
         Your first guess was right - (ben_tilly) - (5)
             Muchas grazie - (pwhysall) - (4)
                 This job is a sore point I guess? -NT - (ben_tilly) - (3)
                     He *said* don't ask, didn't he? :-P -NT - (drewk) - (1)
                         But I didn't ask... - (ben_tilly)
                     Let's just say it's not a pretty sight... - (folkert)

It's like a nuclear blast in the basement.
76 ms