in reply to Regex problem i think?

Hello StalkinYerMa, and welcome to the Monastery!

From the contents of the strings in @strings, it looks like you want to use regex metacharacters. If so, the line:

if($info =~ /\Q$string\E/)

is not what you want, as \Q turns metacharacters back into ordinary characters. The commented-out line:

if($info =~ m{^$string$})

is better, but it may be too restrictive if you want to match part of an input line only. If you use simply:

if ($info =~ /$string/)

what happens? If this still isn’t what you want, you will need to supply sample input (from the contents of $file_in, which is never defined, BTW), together with the output you are getting and the output you expect/want to get.

A couple of unrelated points:

  1. $count = $count+1; may be written more concisely as ++$count;.

  2. It would be more efficient to chomp($info); in the outer foreach loop.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Regex problem i think?
by Anonymous Monk on Sep 10, 2014 at 11:28 UTC

    Ive tried every version of what you told me and it dosent seem to match, the file im using is a csv file that is full of system information. the files first line is:

    9/9/2013,1:42:00 PM,gupdate,Information,None,0,N/A,DANIEL-3332D452,The + description for Event ID ( 0 ) in Source ( gupdate ) cannot be found +. The local computer may not have the necessary registry information +or message DLL files to display messages from a remote computer. You +may be able to use the /AUXSOURCE= flag to retrieve this description; + see Help and Support for details. The following information is part +of the event: Service stopped.
    the biggest problem im having is the regex seems to break it. right after i call the regex it never goes into the loop to check. I appreciate the quick responses. Yes count should have been up one loop, i start moving things around when it dosent work

      If your data is in a CSV file then you will be much better off extracting the data using a dedicated CSV module. For example, Text::CSV_XS by Tux is highly recommended. You should extract the relevant field(s) first, and only then apply one or more regexes to those fields to extract the data you want.

      We’re going to need more information before we can give further help. The best way to provide us with that information is to follow the advice in How do I post a question effectively?

      Include (inside <code>...</code> or <c>...</c> tags) a minimal script that reproduces your problem and sample data (input).

      — together with the output you actually get and the output you want.

      P.S. It’s chomp that’s in the wrong part of the loop, not $count.

      Hope that helps,

      Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

        I want to say sorry to make you guys look at this, i learned alot, It wasent working because my teacher wanted to play a sick prank and give me a file that had no matches in it. Thank you for the advise, the code worked fine!