HI, I am trying to find in several files certain lines and print then to one file. These lines all have one common feature, all have word VERSION or Version on them. Character * or ; or # can be also placed before the word, also one of previous characters or nothing plus 1 or 4 or 8 spaces like
" VERSION: 0.11 12-Jul-2002 HWe"
I would like to find elegant string matching solution to find all these lines, now I am using something like
...... my $vers_1 = "VERSION : "; my $vers1 = "VERSION"; my vers3="#Version"; $vers5="*Version"; . .. if($rivi =~ /^$vers_1/ || $rivi =~ /^$vers1/ || $rivi =~ /^$vers3/ ...... { $rivi=~ tr/:/ /d; # To remove ":" marks $rivi=~ tr/;//d; # To remove ";" marks $teksti = $teksti.$rivi; open (T,">>desc.txt"); print T $teksti; close T; $teksti=""; } ........
Most problems cause those lines that have 4 or 8 spaces before the searched word as in my example. Problem number two is how to remove all but the version number (here 0.11) from that line, I get off all but HWe stays occasionally in the line--> 0.11 HWe. Also sometimes when name is written like Firstname LAstname or /Firstname LAstname after date, only Firstname is removed. My combinations in code are:
.... $m0=""; $rivi=~ s/\d+-\w+-\d+/$m0/i; # for /Name type of date $rivi=~ s/$cv\w+/$m0/; # NEW trial for /Name type of date $rivi=~ s/\s+\w+\s+\w+/$m0/; $rivi=~ s/\s+\w+\s+\w+/$m0/; .....
Has anyone any ideas? I have gained a lot by reading Perl Monks FAQs during my first 7 months of using Perl BR Hewarn

In reply to Matching characters by hewarn

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.