in reply to Split/Match Question
However there are a lot of pitfalls with this approach. Not the least of which is that the user layout of these HTML pages can change from one day to the next. Some of these HTML parser modules are more robust in terms of being able to handle something that "didn't quite look like it did before" and there are a zillion ways that can happen. These "one-off" things like below tend to be very single purpose rather than general purpose. So there are some trade-offs that evolve things that we haven't even begun to discuss here.
Anyway, I think you have a number of excellent approaches in this thread and one of them or a derivative of it will work find for you.
#!/usr/bin/perl -w use strict; my $doc =<<FORM; <div><label>Emp ID:</label> AASDFG <br><label>Mobile Num:</label> 9999 +999999 <br><label>location:</label> India <br><label>Inservice:</labe +l>Yes </div> FORM my @pairs = ($doc =~ m~<label>\s*(.*?)\s*</label>\s*(.*?)\s*<~g); while (@pairs) { my ($field, $value) = splice(@pairs,0,2); printf "%-15s %s\n", $field, $value; } __END__ Emp ID: AASDFG Mobile Num: 9999999999 location: India Inservice: Yes
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Split/Match Question
by afoken (Chancellor) on May 16, 2010 at 20:51 UTC | |
by JavaFan (Canon) on May 16, 2010 at 22:18 UTC | |
by afoken (Chancellor) on May 16, 2010 at 22:40 UTC | |
by Marshall (Canon) on May 16, 2010 at 22:18 UTC |