Two more ideas you could try...

1) Using a hash to store the data:
#!/usr/bin/perl use strict; my $data=(); open(IN,"xxxx.in"); while(<IN>){ /<(\w+)>(.*)<\/\1>/; $data{$1} = $2; } close(IN); print "Volume: $data{volume}\n"; print "Issue: $data{issue}\n"; print "Year: $data{year}\n";
2) Similar to the above but skipping the hash to make things a bit tighter:
#!/usr/bin/perl use strict; open(IN,"xxxx.in"); while(<IN>) { /<(\w+)>(.*)<\/\1>/; print ucfirst($1).": $2\n"; } close(IN);

The \1 is a back reference to whatever got matched in the first set of <>'s. You don't strictly need it as /<(\w+)>(.*)</ works just as well but it gives it all a nice sense of symmetry :D

The ucfirst is just there to make the tags neat but naturally you could just write the tags like that in the first place if you desired.

Both solutions work dynamically so you can change your tag names or add / remove tags without needing to modify your code. They should just as easily handle:

<volume>4</volume> <issue>12</issue> <year>2003</year> <pages>200</pages> <author>A N Other</author>
... which will produce:
Volume: 4 Issue: 12 Year: 2003 Pages: 200 Author: A N Other

In reply to Re: problem with variables by gothic_mallard
in thread problem with variables by texuser74

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.