Perl Text Manipulation

I'm in need of help for a project that I'm working on. I believe Perl would be the best way of handling the string manipulation, however, I've barely used perl, and I'm used to BASH scripting. Another note is, this project is in a Windows environment, so I can use Perl, but I do not have shell based utilities available to me, unfortunately.

I have a batch job run that runs tiffinfo on several tiff images, and I get the following output:

TYPE:
filename.tif:
TIFF Directory at offset 0x10eb4
  Image Width: 1728 
  Image Length: 2376
  Resolution: 200, 200 pixels/inch
  Bits/Sample: 1
  Compression Scheme: CCITT Group 4
  Photometric Interpretation: min-is-white
  FillOrder: lsb-to-msb
  Document Name: "Standard Input"
  Image Description: "converted PBM file"
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Rows/Strip: 2376
  Planar Configuration: single image plane

This is just for one tiff image. If I had 4 tiff images, for example, my output would be the following:

TYPE:
filename.tif:
TIFF Directory at offset 0x10eb4
  Image Width: 1728 
  Image Length: 2376
  Resolution: 200, 200 pixels/inch
  Bits/Sample: 1
  Compression Scheme: CCITT Group 4
  Photometric Interpretation: min-is-white
  FillOrder: lsb-to-msb
  Document Name: "Standard Input"
  Image Description: "converted PBM file"
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Rows/Strip: 2376
  Planar Configuration: single image plane
TYPE:
filename2.tif:
TIFF Directory at offset 0x4aac
  Image Width: 1728 
  Image Length: 2376
  Resolution: 200, 200 pixels/inch
  Bits/Sample: 1
  Compression Scheme: CCITT Group 4
  Photometric Interpretation: min-is-white
  FillOrder: lsb-to-msb
  Document Name: "Standard Input"
  Image Description: "converted PBM file"
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Rows/Strip: 2376
  Planar Configuration: single image plane
TYPE:
filename3.tif:
TIFF Directory at offset 0x8
  Subfile Type: (0 = 0x0)
  Image Width: 124 
  Image Length: 124
  Resolution: 31, 31 pixels/inch
  Bits/Sample: 8
  Compression Scheme: None
  Photometric Interpretation: RGB color
  Software: "�"
  Samples/Pixel: 3
  Rows/Strip: 55
  Planar Configuration: single image plane
TYPE:
filename4.tif:
TIFF Directory at offset 0x8
  Subfile Type: (0 = 0x0)
  Image Width: 1419 
  Image Length: 1001
  Resolution: 300, 300 pixels/inch
  Bits/Sample: 8
  Compression Scheme: LZW
  Photometric Interpretation: RGB color
  Samples/Pixel: 3
  Rows/Strip: 1
  Planar Configuration: single image plane
  Photoshop Data: <present>, 410 bytes
  Predictor: horizontal differencing 2 (0x2)

What I'm wanting is, for some perl code to be written to manipulate each "block" of text a certain way. I guess we could call a "block" each section between each TYPE: section. Here's how I'm needing each block formatted:

The value of Compression Scheme:, Resolution:, Photometric Interpretation:, Image Width:, Image Length: all need to be separated by colons, right after the filename (after TYPE:). For example the final output (if you were only manipulating 1 block) would be:

TYPE:
filename.tif:CCITT Group 4:200, 200 pixels/inch:min-is-white:1728:2376:
TIFF Directory at offset 0x10eb4
  Bits/Sample: 1
  FillOrder: lsb-to-msb
  Document Name: "Standard Input"
  Image Description: "converted PBM file"
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Rows/Strip: 2376
  Planar Configuration: single image plane

If there are any Perl gurus out there, I'm looking to discuss how to get this completed. Please let me know and any help is appriciated.

---------- Post updated at 08:33 AM ---------- Previous update was at 08:33 AM ----------

Note sure why the text looks so bad, I used bbcode and formatted it correctly, double and tripple checked open/close tags.

Maybe something like this ?

C:\>
C:\> REM your data file is saved as "tiff_output.txt"
C:\> REM I don't show it here in order to save space
C:\> REM display the contents of the Perl program
C:\>
C:\> type tiff_process.pl
#!perl -w
# pass the filename as first argument; set the variable $infile to it
$infile = $ARGV[0];
# open the file
open (IN, $infile) or die "Can't open $infile: $!";
# loop through it
while (<IN>) {
  chomp;
  # if we've reached the "record-delimiter i.e. TYPE:" or EOF
  if (/^TYPE:/ or eof) {
    # check if array "@line" is defined; if so, print it after
    # appending the additional information after filetype i.e. 2nd element
    if (@line) {
      $line[1] .= "$cs:$r:$pi:$iw:$il:";
      foreach (@line) {print $_,"\n"}
      # Important - reset the array
      @line = ();
    }
  } else {
    # check for compression scheme, resolution, photometric interpretation,
    # image width and image length, and set the variables $cs, $r, $pi, $iw, $il
    if (/^\s*Compression Scheme:\s*(.*?)$/) {$cs = $1}
    elsif (/^\s*Resolution:\s*(.*?)$/) {$r = $1}
    elsif (/^\s*Photometric Interpretation:\s*(.*?)$/) {$pi = $1}
    elsif (/^\s*Image Width:\s*(.*?)\s*$/) {$iw = $1}
    elsif (/^\s*Image Length:\s*(.*?)$/) {$il = $1}
  }
  # add the current line to the array @line
  push @line, $_;
}
# clean up after we're done
close (IN) or die "Can't close $infile: $!";
C:\>
C:\>
C:\> REM execute the Perl program
C:\>
C:\> perl tiff_process.pl tiff_output.txt
TYPE:
filename.tif:CCITT Group 4:200, 200 pixels/inch:min-is-white:1728:2376:
TIFF Directory at offset 0x10eb4
  Image Width: 1728
  Image Length: 2376
  Resolution: 200, 200 pixels/inch
  Bits/Sample: 1
  Compression Scheme: CCITT Group 4
  Photometric Interpretation: min-is-white
  FillOrder: lsb-to-msb
  Document Name: "Standard Input"
  Image Description: "converted PBM file"
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Rows/Strip: 2376
  Planar Configuration: single image plane
TYPE:
filename2.tif:CCITT Group 4:200, 200 pixels/inch:min-is-white:1728:2376:
TIFF Directory at offset 0x4aac
  Image Width: 1728
  Image Length: 2376
  Resolution: 200, 200 pixels/inch
  Bits/Sample: 1
  Compression Scheme: CCITT Group 4
  Photometric Interpretation: min-is-white
  FillOrder: lsb-to-msb
  Document Name: "Standard Input"
  Image Description: "converted PBM file"
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Rows/Strip: 2376
  Planar Configuration: single image plane
TYPE:
filename3.tif:None:31, 31 pixels/inch:RGB color:124:124:
TIFF Directory at offset 0x8
  Subfile Type: (0 = 0x0)
  Image Width: 124
  Image Length: 124
  Resolution: 31, 31 pixels/inch
  Bits/Sample: 8
  Compression Scheme: None
  Photometric Interpretation: RGB color
  Software: ""
  Samples/Pixel: 3
  Rows/Strip: 55
  Planar Configuration: single image plane
TYPE:
filename4.tif:LZW:300, 300 pixels/inch:RGB color:1419:1001:
TIFF Directory at offset 0x8
  Subfile Type: (0 = 0x0)
  Image Width: 1419
  Image Length: 1001
  Resolution: 300, 300 pixels/inch
  Bits/Sample: 8
  Compression Scheme: LZW
  Photometric Interpretation: RGB color
  Samples/Pixel: 3
  Rows/Strip: 1
  Planar Configuration: single image plane
  Photoshop Data: <present>, 410 bytes
C:\>
C:\>

HTH,
tyler_durden