Lightning flashed, thunder crashed and Mark Martin <[EMAIL PROTECTED]> whisper
ed:
| What I have is this:
|
| if ($variable == 02){
| print OUT1 "$variable";
| $lines1 ++;
| } elsif($variable == 03){
| print OUT1 "$variable\n";
| $lines2 ++;
| } elsif($variable == "08"){
| print OUT1 "$variable\n";
| $lines2 ++;
| } elsif($variable == 79){
| print OUT3 "$variable\n";
| $lines3 ++;
| } elsif($variable == 93){
| print OUT3 "$variable\n";
| $lines3 ++;
| } elsif($variable == 99){
| print OUT3 "$variable\n";
| $lines3 ++;
| }
|
| So I need to shorten that to if (variable == "02" OR "03" OR "08"){ .....etc
|
| I think what I need is something called a case. but I can't find the syntax
| anywhere.
Perl doesn't have a case statement. I'm confused a little by what you want
to do. You say you want to shorten it to "02" or "03" or "08", but the
body of the loop is different for those. It is the same for the 79, 93,
and 99, though. You are also mixing numeric ( == ) with strings. What
exactly are you trying to do, there are several options depending.
You might be interested in using hashes or arrays to hold your counters and
output file handles. Then you could reduce the whole if thing to two lines.
For example, something like:
%FH = ( 02 => "OUT1",
03 => "OUT1",
09 => "OUT1",
79 => "OUT3",
93 => "OUT3",
99 => "OUT3"
);
%count = ( 02 => 1,
03 => 2,
08 => 2,
79 => 2,
93 => 3,
99 => 3
);
print { $FH{$variable} } "$variable\n";
$lines[$count{$variable}]++;
-spp