What results are you getting, and what results do you expect? Perhaps also a description of what you code is doing may help you help yourself find the error....

sub get { # Is this assignment necessary? $data_file = $file ; # 2 argument form of open(), non-lexical file handle, # and using stronger binding "||" instead of "or". # Could be better as: # open(my $dat, "<", $data_file) or die(...); open(DAT, $data_file) || die("Could not open file!"); @raw_data=<DAT>; # Careful here, will also catch "11 of", "21 of", ... $search="1 of"; foreach $line (@raw_data){ if ($line =~ /$search/){ # You are counting the number of times you match, # not the number after the match. Also, it does # not look like this is ever initialized. $count++ ; } } print "Packs returned: $count\n"; }

If I understand your post correctly, you want instead to match the (watch for the hint here) number after your search string.

If your intent is actually to count the number of times that you see your search string, you can do that more efficiently* using scalar and grep.

* - for some definition of "more efficient".

--MidLifeXis


In reply to Re: Search PCL file by MidLifeXis
in thread Search PCL file by mike1977

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.