C
Colin B.
Hey all;
After years of avoiding perl in favour of ksh+sed+awk+grep+etc., I'm
finally digging into it. So far everything I've mucked with, I've managed
to get working after a certain amount of self-abuse, with the exception of
two things.
1) I'm pulling data lists from the OS, and parsing them in perl.
The minimum required code to illustrate my problem is this:
$group = shift(@ARGV) || die;
@nislist = split(/[:,]/,`nismatch $group group.org_dir`);
chomp @nislist;
print scalar @nislist, "\n";
And the data for two different groups is:
group1:*:109:
group2:*:20:user1
The problem is that despite reading that split will discard blank trailing
fields, I get four fields from BOTH of the above groups. There are no
spaces at the end of the first group, so I'm assuming that the fourth field
in group1 is a newline. That also leads me to believe that chomp $str where
$str="\n" results in $str="", but not $str=<undef>. Is this correct?
So I came up with a workaround:
my $nislist = `nismatch $group group.org_dir`;
chomp $nislist;
@nislist = split(/[:,]/,$nislist);
Is there anything less ugly than this? I would have liked to do something
like:
chomp (@nislist = split...);
but it complains and doesn't work.
Thanks,
Colin
After years of avoiding perl in favour of ksh+sed+awk+grep+etc., I'm
finally digging into it. So far everything I've mucked with, I've managed
to get working after a certain amount of self-abuse, with the exception of
two things.
1) I'm pulling data lists from the OS, and parsing them in perl.
The minimum required code to illustrate my problem is this:
$group = shift(@ARGV) || die;
@nislist = split(/[:,]/,`nismatch $group group.org_dir`);
chomp @nislist;
print scalar @nislist, "\n";
And the data for two different groups is:
group1:*:109:
group2:*:20:user1
The problem is that despite reading that split will discard blank trailing
fields, I get four fields from BOTH of the above groups. There are no
spaces at the end of the first group, so I'm assuming that the fourth field
in group1 is a newline. That also leads me to believe that chomp $str where
$str="\n" results in $str="", but not $str=<undef>. Is this correct?
So I came up with a workaround:
my $nislist = `nismatch $group group.org_dir`;
chomp $nislist;
@nislist = split(/[:,]/,$nislist);
Is there anything less ugly than this? I would have liked to do something
like:
chomp (@nislist = split...);
but it complains and doesn't work.
Thanks,
Colin