bh_perl has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
This is my program :-
#!/usr/bin/perl use Getopt::Std; use Cwd; use vars qw /%opt/; my $options = 'h:i:l:v:'; my %fldinfo; my @entries = (); my $dir = getcwd; getopts("$options", \%opt) or usage(); sub usage { print "Usage: $0 -[h] -i <input_file>\n"; if ($opt{h}) { print " -h : help\n"; print " -i : xml input file \n"; print " -l : list of field will be changes\n"; print " -v : assigned the change values\n"; } } sub change_specified_field { my $fvalue = $opt{v}; my ($ff, $fv) = (split(/=/,$opt{v}))[0,1]; $ff = lc($ff); $fv =~ s/(\S{2})/$1 /g; $fv =~ s/\s$//g; open(TMP, "+> $dir/$opt{i}.tmp"); open(DATA, "$opt{i}"); while (my $data = <DATA>) { chomp($data); $data = lc($data); foreach (split(/CallDataRecord/,$data)) { if ($_ =~ /$ff/) { print TMP "$1>$fv<$3\n" if /(.*)>(.*)< +(.*)/; } else { printf TMP "$_\n"; } } } close(DATA); close(TMP); system("mv $dir/$opt{i}.tmp $dir/$opt{i}"); } main { if ($opt{h}) { usage(); } if ($opt{i} && $opt{v}) { change_specified_field(); } exit(); }
My program will be read the input data and split it by "calldatarecord". The problem is how could i captured only specified input data records of the input data.
As example, this is some example of the input data :-
------------------------------------------------- <calldatarecord> <timeforstartofcharge>08 17 09</timeforstartofcharge> <timeforstopofcharge>08 17 15</timeforstopofcharge> <chargeableduration>00 00 0A 0D</chargeableduration> </calldatarecord> <calldatarecord> <timeforstartofcharge>08 16 17</timeforstartofcharge> <timeforstopofcharge>08 17 16</timeforstopofcharge> <chargeableduration>00 00 0A 0D</chargeableduration> </calldatarecord> --------------------------------------------------------
Then, 1. how could and print the second record only ? 2. how could i print the "chargeableduration" values of the second record ?
could somebody help me ?
Thenk you,
Edited (davorg): removed code tags from non-code sections
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how could i captured selected data of the input ?
by davido (Cardinal) on Nov 09, 2006 at 03:12 UTC | |
by aufflick (Deacon) on Nov 09, 2006 at 05:54 UTC | |
|
Re: how could i captured selected data of the input ?
by dimar (Curate) on Nov 09, 2006 at 14:06 UTC |