Hi I am new to perl and am having a problem with a filter i am trying to set up using arrays. I have a file which contains a list of values either alphanumeric or numeric. i have put all these elements into a variable to use against the original log file. It seems to work when its hard coded into the script but not when its set to the variable. Hope you can help. Below is the snippet of code thats causing problems and how it is initiated.
$filename = "/var/tmp/log.out"; open(FILE, $filename) || &error(); @file = <FILE>; close(FILE); $filter = "/var/tmp/messages_filter"; open(FILE, $filter) || &error(); @filefilter = <FILE>; close(FILE); START_HTML $lines_in_filter = @filefilter; if($lines_in_filter != 0){ foreach $filterline (@filefilter){ chomp($filterline); if ($grepstring ne "" ){ $joiner = "&&";} $grepstring = "$grepstring $joiner (!/$filterline/)"; } } else{ print "<TR><TD>File is empty</TD></TR>"; } #print "$grepstring"; #print "(!/243001/) && (!/454097/) && (!/858035/) && (!/872937/) && (! +/427199/)"; @file1 = grep($grepstring, @file); #@file1 = grep((!/243001/) && (!/454097/) && (!/858035/) && (!/872937/ +) && (!/427199/), @file); print "@file1";
The numbers listed are what are in the file, ie 243001 454097 etc... the two print lines that are commented out i put in to try and debug it and the output from the $grepstring is the same as the original output. The problem that i am having is that the
"@file1 = grep($grepstring, @file);" doesnt seem to work like the original line shown below it in the code. Please can anyone help me or point me in a better direction to try. Hope this makes sense. Thanks for your time.

In reply to Variable problem inside an array by bittoni

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.