Re: parsing a line
- From: chas.owens@xxxxxxxxx (Chas Owens)
- Date: Thu, 28 Jun 2007 10:15:53 -0400
On 6/28/07, alok nath <aloknathlight@xxxxxxxxx> wrote:
snip
if( $_ =~ m/ID\s=\s"(.*?)"\sDirAbsolute/){snip
It does look fragile. A lot depends on how likely the real input
matches the example you gave. That regex will break if the input is
<Test Description = "Test 1" ID = "ID A1" DirAbsolute = "C:/perl"/>
Note the second space after the "ID =". Also, you can generalize the
code by using character classes:
if (my %rec = $s =~ /\s*([\w ]*\w)\s*=\s*"(.*?)"/g) {
my $id = exists $rec{ID} ? $rec{ID} : "not set";
my $dir = exists $rec{DirAbsolute} ? $rec{DirAbsolute} : "not set";
my $desc = exists $rec{'Test Description'} ? $rec{'Test
Description'} : "not set";
print "id $id dir $dir desc $desc\n";
}
.
- References:
- Re: parsing a line
- From: Alok Nath
- Re: parsing a line
- Prev by Date: Re: More loops
- Next by Date: missing curly - brain fried
- Previous by thread: Re: parsing a line
- Next by thread: don't understand working script
- Index(es):
Relevant Pages
|