Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi PerlMonks Members!

First of all, this is the best perl site i have found on the net. I´m just a beginner perl coder. Any Problems/questions i had during programming scripts were solved by this site, and i got more expirienced too!
Go on like this!

I got anything coded by now, but with following i got a problem. Already tried several ways i found but always failed.

I just need to code a very little search/paste matches script.

open one database file, get each line, search for a match at current line, if yes, put line that matched in some variable, continue on next line...

the lines look like this

name|url|description #where '|' seperates them.

i think a part of code would look like


$file = 'database';
open(INF,$file);
@ary = <INF>;
foreach $item(@ary){

now search $item for matched text
if->succed { do something } else { go get next line}

}
close(INF);


It would be REALLY great if someone could help me!
Many thanks & greeting from Germany,

Stefan

Replies are listed 'Best First'.
Re: Open File / Search-match
by weini (Friar) on Jan 29, 2002 at 16:29 UTC
    Hi Stefan, being a Perl beginner (and a german) myself, my suggestions are:

    If you like perlmonks, register and log in - it's fun!

    I guess the right group for your question would be "Seekers for Perl Wisdom" and not "Discussion".

    Concerning your problem:

    use strict; # always do so (first thing I learned) my $file = 'database'; my @result; open(INF,$file) || die "Can't open $file: $!\n"; while (<INF>) { # while walking through file if(/???/) { # if you match your searchstring # you have to replace ??? by a regex push @result,$_; # write current line to array } }
    ... may point in the right direction

    HTH

    weini