/dev/trash has asked for the wisdom of the Perl Monks concerning the following question:
I have a text file, that I am trying to parse. Each "record" starts with filename.jpg: followed by a blank line or filename.jpg: followed by multiple lines of data. What I want to do is take the info that is associated with a filename and keep it in a variable to work with later.
This is what I have so far:
The part that I am stuck with is after finding the *.jpg filename I want to check to see if the next line is a blank or has data. This is an example of the text file.#!/usr/bin/perl use warnings; use strict; my $fh; open($fh, "</home/me/bulk.txt") or die "Can't open: $!"; while (my $line = <$fh>) # was $line { if ($line=~/(jpg:\Z)/) { print "\n"; print $1; if ($line=~/(\w)/) { print "\n"; print $line; print "\n"; } } }
rib.jpg: May.jpg: Camera-Specific Properties: Equipment Make: OLYMPUS OPTICAL CO.,LTD Camera Model: C860L,D360L Camera Software: OLYMPUS CAMEDIA Master Maximum Lens Aperture: f/2.8 Image-Specific Properties: Image Orientation: Top, Left-Hand Horizontal Resolution: 72 dpi Vertical Resolution: 72 dpi Image Created: 2001:04:13 23:59:14 Exposure Time: 1/11 sec F-Number: f/2.8 Exposure Program: Normal Program ISO Speed Rating: 500 Exposure Bias: 1/2 EV Metering Mode: Pattern Light Source: Fluorescent Flash: Flash Focal Length: 5.50 mm Color Space Information: sRGB Image Width: 228 Image Height: 380 Compression Setting: SQ Macro Mode: Normal oher.jpg:
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Parsing Multiple Lines.
by Zaxo (Archbishop) on May 24, 2004 at 01:11 UTC | |
by /dev/trash (Curate) on May 24, 2004 at 01:48 UTC | |
by Happy-the-monk (Canon) on May 24, 2004 at 08:49 UTC | |
by /dev/trash (Curate) on May 24, 2004 at 17:36 UTC | |
by Happy-the-monk (Canon) on May 24, 2004 at 17:39 UTC | |
| |
Re: Parsing Multiple Lines.
by NetWallah (Canon) on May 24, 2004 at 03:59 UTC | |
by Zaxo (Archbishop) on May 24, 2004 at 05:21 UTC | |
by Somni (Friar) on May 24, 2004 at 05:16 UTC |
Back to
Seekers of Perl Wisdom