I have the following data in @return from my @return = `command \\\\$Server\\$user`; I would like to put it in a hash.
So the first line would be $hash{User_Name} = userid
How would I go about doing this? I have tried this, but not all the key names are built the same (some with spaces others without)...
foreach (@return) { chomp; my @t = split; print "\n++$t[0] == $_[-1]"; }
In this case you appear to have fixed width data which is oh so fun compared to delimited data, you can generally parse it fairly easily with 'unpack'.
perldoc -f pack
I also need to get the group memberships at the bottom all into one hash key each ( ie Global = "*GroupA *GroupB *GroupC"
In this case you are going to have to be a little more crafty, generally you can have a check to see if you are currently parsing a key that has multiple values, in which case you parse until you hit the next key, or hit a line that doesn't start with white space (since all of the keys should be left aligned). I suspect your multiple value keys will also all start at a specific location, which means you could just check for a value at that location on each pass.
,----- [ Contents of @return ]
| User Name userid
| Full Name fname lname
| Description string
| User's Comment | User Type Admin
| Enhanced Authority | Account Type Global
| Workstations | | Home Directory d: \\server\share$
| User Profile | Logon Script kix32 /d kixtart.kix
| Flags NO_PWD_EXPIRE
| Account Expires Never
| | Password age in days 632
| Password last set 6/16/20YY 1:31 PM
| Bad PWD count 0
| | Num logons (this machine) 39
| Last logon 2/24/20YY 2:00 PM
| Logon hours All
| | | Global group memberships *Domain Users *GroupA | *Domain Admins *GroupB | *GroupC *GroupD | *GroupE | Local group memberships *RConsole Users *Users | *Administrators
`-----
Thanks!
What have you tried, where did you fail? Hints will be provided but this isn't a free script service........
http://danconia.org
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>