Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi ,
I am new to perl and have to write some code for Monday deadline. Could you please help with how to match pattern which looks like this

<Row AutoFitHeight="0"> <Cell><Data ss:Type="String">DATA1</Data></Cell> <Cell><Data s:Type="String">DATA2</Data></Cell> <Cell><Data ss:Type="String">DATA3</Data></Cell> <Cell><Data ss:Type="String">DATA4</Data></Cell> <Cell><Data ss:Type="String">DATA5</Data></Cell> <Cell><Data ss:Type="String">DATA6</Data></Cell> <Cell><Data ss:Type="String">DATA6</Data></Cell> <Cell><Data ss:Type="String">DATA7</Data></Cell> </Row>

Now the columns of DATA values keep changing. So thats the reason I am having a hard time to come up with a pattern that matches the above. But the only thing thats common is the begining of the syntac ie <Row AutoFitHeight and the ending of the syntax ie

</Row>

Code tags added by GrandFather

Replies are listed 'Best First'.
Re: pattern match
by GrandFather (Saint) on Jan 30, 2006 at 02:34 UTC

    XML::twig is probably your best bet for doing this sort of stuff with XML or XHTML.

    If you have trouble getting going with XML::twig tell us in a little more detail just what you want to be able to do. My guess is that you actually want to extract some of that data, but you don't actually say that. The following may get you started:

    use strict; use warnings; use XML::Twig; my $t= XML::Twig->new (twig_roots => {'Data' => \&extract}); $t->parse (do {local $/; (<DATA>)}); sub extract { my ($t, $data) = @_; $data->print; print "\n"; } __DATA__ <Row AutoFitHeight="0"> <Cell><Data ss:Type="String">DATA1</Data></Cell> <Cell><Data ss:Type="String">DATA2</Data></Cell> <Cell><Data ss:Type="String">DATA3</Data></Cell> <Cell><Data ss:Type="String">DATA4</Data></Cell> <Cell><Data ss:Type="String">DATA5</Data></Cell> <Cell><Data ss:Type="String">DATA6</Data></Cell> <Cell><Data ss:Type="String">DATA6</Data></Cell> <Cell><Data ss:Type="String">DATA7</Data></Cell> </Row>

    Prints:

    <Data ss:Type="String">DATA1</Data> <Data ss:Type="String">DATA2</Data> <Data ss:Type="String">DATA3</Data> <Data ss:Type="String">DATA4</Data> <Data ss:Type="String">DATA5</Data> <Data ss:Type="String">DATA6</Data> <Data ss:Type="String">DATA6</Data> <Data ss:Type="String">DATA7</Data>

    DWIM is Perl's answer to Gödel
Re: pattern match
by McDarren (Abbot) on Jan 30, 2006 at 02:31 UTC
    So where exactly are you getting stuck with this?
    What have you tried so far?

    This seems like almost the same question that was asked here. Did you also ask that question?
    If the replies didn't help, then please say so rather than starting a complete new thread.