in reply to Pattern Matching - a Tricky one
A solution using seek may be better, but I came up with this for finding the customer2 data:
#!/usr/local/bin/perl use strict; use warnings; while ( <DATA> ) { next if ($_ !~ /bakjob(\d)_details/); print "bakjob$1:\n"; my $found = 0; while ($found < 2) { my $line = <DATA>; if ($line =~ /customer2/) { $found++; my @customer2_data = split(/=/, $line); print "$found- $customer2_data[1]"; } } } END; __DATA__ bakjob1_details = { credit = { customer1= 2000.0, customer2 = -1500.0 customer3 = 0.0, }, debit = { customer1= 50000.0, customer2 = -2000.0, customer3 = 0.0, } }, bakjob2_details = { credit = { customer1= 1000.0, customer2 = 200.0, customer3 = 500.0, }, debit = { customer1= 600.0, customer2 = 659.0, customer3 = 887.0, } }
Prints:
% testing.pl bakjob1: 1- -1500.0 2- -2000.0, bakjob2: 1- 200.0, 2- 659.0,
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Pattern Matching - a Tricky one
by linuxer (Curate) on Jan 02, 2009 at 15:55 UTC | |
by kdj (Friar) on Jan 02, 2009 at 16:32 UTC |
In Section
Seekers of Perl Wisdom