Re: What am I doing wrong?!

From: Jürgen Exner (jurgenex_at_hotmail.com)
Date: 10/29/03


Date: Wed, 29 Oct 2003 16:47:31 GMT

Tony Walker wrote:
> OK, what I'm doing is a basic search of a logfile for specific
> strings. At present I have this working fine by manually creating an
> array and foreaching it..
> However, I now want to read these strings from a file and perform the
> same actions as before but I'm hitting a problem. I slurp the file
> into and array and it only ever finds ONE of the strings in the file,
> not the other!!
>
> Any help much appreciated..
>
> Tony
>
> p.s this is my first attempt at perl so it may not look great...
> ##
> #!/opt/perl/bin/perl
> open (ER,"ALL_errors") or die "$!";
> my @entry = <ER>;

I wager you forgot to chomp() here.

> open (LOG,"all.log") or die "$!";
> while (<LOG>){
> my $CUR=$_;
> for (my $i=0;$i<=$#entry;$i++) {

Och, that's C, not Perl:
    for (my $i=0..@entry)

Or use just
    for (@entry)

> my $LINE = @entry[$i];
> if ($CUR =~/$LINE/){

and then here
    if ($CUR =~/$_/){
instead fo the two lines above

> print $CUR;
> }
> }
> }
> ####



Relevant Pages

  • Re: Searching a sorted array of strings
    ... So my example stands, it is what I said it is, searching a sorted ... array of strings in Perl. ... Hash is easy in Perl doesn't make it an array of strings. ...
    (comp.lang.perl.misc)
  • Re: Perl and Unix/Linux Tutorials
    ... > Linuxadmin stuff.? ... I'm hoping to use Perl for just that, ... we'll look at printing an array and see how arrays are represented in Perl source code. ... > This example shows an empty array, an array of numbers and an array of strings. ...
    (perl.beginners)
  • FAQ 4.42 How can I tell whether a certain element is contained in a list or array?
    ... How can I tell whether a certain element is contained in a list or array? ... If the values in question are integers instead of strings, ... It's written in C for speed, and its Perl equivalant ... The perlfaq-workers, a group of volunteers, maintain the perlfaq. ...
    (comp.lang.perl.misc)
  • FAQ 4.42 How can I tell whether a certain element is contained in a list or array?
    ... How can I tell whether a certain element is contained in a list or array? ... If the values in question are integers instead of strings, ... It's written in C for speed, and its Perl equivalant ... The perlfaq-workers, a group of volunteers, maintain the perlfaq. ...
    (comp.lang.perl.misc)
  • FAQ 4.42 How can I tell whether a certain element is contained in a list or array?
    ... How can I tell whether a certain element is contained in a list or array? ... If the values in question are integers instead of strings, ... It's written in C for speed, and its Perl equivalant ... The perlfaq-workers, a group of volunteers, maintain the perlfaq. ...
    (comp.lang.perl.misc)