On Jul 5, Tim Musson said:
>I want to split to @Group only if the 3rd element of @Line has data.
>It works, but I get an error (Use of uninitialized value in split)
>using -w, strict, and diagnostics. Should I be doing this differently?
>
>while (<>) { chomp;
> my @Line = split(/,/);
>
> my @Group = split(/_/, $Line[2]) if ($Line[2]); # err msg here for uid3
>
> print "\n", $Line[0], $Line[1], " $Group[-1]"; # testing
>}
It is inadvisable to do:
my SOMETHING if CONDITION;
because you cause Perl to do some weird things which I'd rather not get
into.
while (<>) {
chomp;
my @line = split /,/;
my @group = (@line == 3) ? split(/_/, $line[2]) : ();
print "$line[0] $line[1] $group[-1]\n";
}
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** Manning Publications, Co, is publishing my Perl Regex book **