[tpm] find, manipulate, then output

Antonio Sun antoniosun at lavabit.com
Mon May 28 06:59:15 PDT 2012


Hi,

I want to work on the strings that I find in the input, then output the
processed content.
I'm wondering what's the elegant way to do it.

IIRC, it can be done with something like this

perl -ne 'print $2 . ", ". $1. "\n" while(/.../)'

But I really can't work out the rest now.
Please help.

Here is an example that you can work on. Given the following input,
I want to output, "<last-name>, <first-name>" on each line.
I.e., the output would be:

Franklin, Benjamin
Melville, Herman

Thanks

   <bookstore>
     <book genre="autobiography">
       <title>The Autobiography of Benjamin Franklin</title>
       <author>
         <first-name>Benjamin</first-name>
         <last-name>
   Franklin</last-name>
       </author>
       <price>8.99</price>
     </book>
     <book genre="novel">
       <title>The Confidence Man</title>
       <author>
         <first-name>
   Herman
         </first-name>
         <last-name>Melville</last-name>
       </author>
       <price>11.99</price>
     </book>
. . .
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20120528/aecc83da/attachment.html>


More information about the toronto-pm mailing list