are you a cs major? do you understand what your prof wrote? you should understand it and try to solve it yourself, otherwise the later perl scripts your prof tells you to write will only get harder..
what your prof wrote assumes the same user ID only occurs in consecutive blocks. if it occurs in different blocks, then each user id will be printed out on different liens.
here is my solution, haven't tested it but it should work..
if ($id == $a[0]){
if ($a[1] != '\-') { // skip the dashes
$q = $q . "; $a[1]";
$i++;
}
}
else{
$j++;
if ($i != 0) { // does not print if 0 occurences of id (ie all dashes)
print OUT "$id\t$q\t$i\n";
}
$id = $a[0];
if ($a[1] == '\-') {
$q = "";
$i = 0;
}
else {
$q = $a[1];
$i = 1;
}
}
|