[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] a regex question



I'm having problems with a little regex thing here. What I'm trying to do is read from a data file and out put in a certain way. If the data file looks something like...

#####
#  TEXT/ttxt --> SimpleText
#  TEXT/MOSS --> Netscape
#                                          #
#  ttro/ttxt --> SimpleText read only
#                                          #
#  W6BN/MSWD --> MS Word 6.0/95
#                                          #
#  W8BN/MSWD --> MS Word 97-8
#                                          #
#  GIFf/ogle --> PictureViewer GIF
#####

I want the output to be something like...

#####
#  TEXT     ttro     W6BN     W8BN  #
#  GIFf                             #
#####

The code snippit I currently have is...

open(DATA, "<cnvtOS data");
print "\n\t\t#####\n";
while ($line = <DATA>) {
     $sub_string = substr($line,3,4);
     if ($line =~ /^#  ....\//) {
          $a_mime_type = $sub_string;
     }
     if ($sub_string ne $a_mime_type) {
          print "$a_mime_type\n";
     }
}
print "\n\t\t#####\n";
__END__

Which prints each unique $sub_string on a new line. By replacing the "\n" with '     ' I can get them on one line. But all my attempts to line-wrap after, say, four of them have failed. Cound someone lead me in the right direction?

--Nick

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org