Link to home
Start Free TrialLog in
Avatar of vage78
vage78Flag for Greece

asked on

I want to search through an asci file

I'm a new programmer in Perl. I have a ascii file with 20000 records. How i can make searches inside this file with one or two fields. Which are the steps?
May i have a simple example of this type of program.
Thank you
Avatar of PC_User321
PC_User321

Is each line of the file divided into fields?
If so, what is used to separate the fields?

Here is an example where the fields are separated with a '|' character.
Assume you want the first field to be "Person" and the third field to be "Every month":

$Record0Search = "Person";
$Record2Search = "Every month";

open(FILE, "data.txt");
while ($Line = <FILE>) {
   @Fields = split '\|', $Line;
   print $Line if (($Fields[0] eq $Record0Search) && ($Fields[2] eq $Record2Search));
}

ASKER CERTIFIED SOLUTION
Avatar of PC_User321
PC_User321

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vage78

ASKER

Thank you very much.I will try.My file is very big. Is this a problem? (20000 records) or everything is ok.
May i use also indexes.
Thanks a lot
>> My file is very big. Is this a problem?  No

>> May i use also indexes?
Please explain what you mean.