guha has asked for the wisdom of the Perl Monks concerning the following question:
I have been playing around with a RE that is supposed to extract the value of a tag.
The program below already does the right thing, but I have an undefined feeling that it could be done with some kind of alternation aka |. But I can't get it to do what I want. I have been reading the docs but either the info is too thin or my head is too thick.
So I was wondering if someone can show me how alternation can/should be used.
TIA#!perl -w use strict; while( <DATA> ) { chomp; my ( $data ) = m/TAG:\"([^\"]+)\"/ ? $1 : m/TAG:([^\"\s]+)/ ? $1 : + 'not_def'; print "$_ => $data\n"; } __DATA__ TAG:"test of data" TAG:test_of_data TAG:test of data TAG: test TAG:test of data" TAG:"test of data TAG:test-2_3.we
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Alternation in pattern matches
by ambrus (Abbot) on Feb 18, 2004 at 20:56 UTC | |
|
Re: Alternation in pattern matches
by dws (Chancellor) on Feb 18, 2004 at 21:49 UTC | |
by guha (Priest) on Feb 19, 2004 at 09:12 UTC | |
|
Re: Alternation in pattern matches
by Abigail-II (Bishop) on Feb 18, 2004 at 21:39 UTC | |
by ysth (Canon) on Feb 19, 2004 at 01:40 UTC | |
by ambrus (Abbot) on Feb 19, 2004 at 15:36 UTC | |
by ysth (Canon) on Feb 19, 2004 at 17:29 UTC | |
by ambrus (Abbot) on Feb 19, 2004 at 17:39 UTC |