in reply to Searching input file
Maybe this works, although somehow you didn't tell what your problem is...
#!perl -w use strict; print "Author to search for:"; my $search = <STDIN>; chomp($search); my $totalprice = 0; my $found = 0; my @info = (); my ($title, $autor, $genre, $price); open (INPUT, "books.txt") or die "Error: $!"; # always check for error +s while (<INPUT>){ chomp $_; ($title, $autor, $genre, $price) = split (/:/,$_); if ($search eq $autor) { # eq for stringcompare, == for numerical $totalprice += $price; push (@info, [ $title, $genre, $price]); $found++; } } print "$found books by $autor were found...\n"; print "They are:\n"; print "\tBook Title\t\t\tGenre\tPrice"; foreach my $info (@info){ print join("\t", @$info), "\n"; } print "\tTotal price of these books by $search is $totalprice"; close INPUT;
Best regards,
perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Searching input file
by jlongino (Parson) on Feb 28, 2002 at 04:38 UTC |