Ed <[EMAIL PROTECTED]> asked:
[...]
> I'm reading from a file and constructing an array of arrays.
> Here's an example of what's in the file:
> net localgroup Field Aidan /ADD
[...]
> I want to sort the lines in the file by the 3rd column
> (Field, Internal, CM, DocAdmin)
If you're not particularly interested in the order the
lines appear, then I would suggest that you use a hash
with the localgroup name as a key instead.
> I'm reading the lines into an array and converting each line
> to an array so I can access the 3rd column. Once I do this I
> have a 2 dimensional array, but I can't de-reference the way
> I think it should work. (deja vu)
>
> my @lineArray;
> while(<F>)
> {
> # if the line is a net localgroup line add it to the array
> if( $_ =~ $s_criteria )
> {
> print "FOUND localgroup line:-> $_\n";
> split /\s/;
> push( @lineArray, @_ ); <---no it's an array of arrays.
This will append all the items in @_ to @lineArray.
You shoul've said "push( @lineArray, [EMAIL PROTECTED] );" instead.
[...]
> Can someone set me straight or provide an alternate method?
#!/usr/bin/perl
use strict;
use warnings;
my $filename = 'somedata.txt';
open( F, '<', $filename ) or die "Can't open '$filename': $!";
my %groupMembers;
while( my $line = <F> ){
if( my( $groupName, $userName ) = ( $line =~
m{^\s*net\+localgroup\s+(\S+)\s+(\S+)\s*/ADD} ) ){
push @{$groupMembers{$groupname}}, $userName;
}
}
foreach my $groupName (sort keys %groupMembers){
print "member of group $groupName: " . join(' ,', sort
@{$groupMembers{$groupname}}) . "\n";
}
__END__
HTH,
Thomas
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>