Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
laziness, impatience, and hubris
 
PerlMonks  

Open File / Search-match

by Anonymous Monk
on Jan 29, 2002 at 09:12 UTC ( [id://142315]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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 11: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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://142315]
Approved by root
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.