VladP:

I see you've already got some good guidance on solving your problem, but I'm still drinking my morning coffee, so I thought I'd chime in with a couple things that may be helpful, even if they're not directly related to your question.

Files

Two things about your file handling:

So as regarding file I/O, I'd suggest you do it more like this:

open my $FILE, "<", $input or die "cannot open $input: $!\n"; while (my $tag = <$FILE>) { . . . } close $FILE;

As you can see, it's not much more work, but later you'll get the dividends.

Regular Expressions

You mentioned to choroba that you're not a regex expert, and that's fair. But I'd suggest you dedicate a couple hours to getting a firm handle on the basics. I'd suggest starting by reading perldoc perlrequick to start off, and following it up with the regular expression tutorial (perldoc perlretut).

Once you're a bit more comfortable, then perldoc perlre and make sure you totally understand sections "The Basics", "Modifiers", "Quantifiers", "Escape Sequences", "Character Classes", "Capture Groups", and "Combining RE Pieces". You don't need to learn all of the other sections, as there's quite a bit there. But the these sections cover all the most important bits to give you proficiency in regular expressions.

You should skim over the other sections, too, but not with the aim of understanding it all at one go. (There's simply too much there to pick up quickly.) Instead, you want to "prime your brain" with a few ideas. That way, when you come across a task that might need an advanced topic, you may remember that there's an advanced regex feature that may be suitable.

Be sure to not just read the documentation, though, write some code to play with the features to be sure you get a good handle on them. Regular expressions are one of the centerpieces of Perl and having a good grasp on them will simplify *many* future tasks.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: read/write delete duplicates/sort PROBLEM! - Use of uninitialized value in sprintf by roboticus
in thread read/write delete duplicates/sort PROBLEM! - Use of uninitialized value in sprintf by VladP

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.