in reply to Trying to make a search
That should read $line and not ${line}.print "${line}";
Now I've fixed your code (you can see my fixes below) to make it functional, but it still isn't very "perl" looking and has some needless code.
Now here is a much more "perl-looking" implementation:#!/usr/bin/perl my $ans; my $currentline; my @data; print "Letter? "; $letter = <STDIN>; chomp $letter; open (DATA, "books.txt"); @data = <DATA>; $currentline = 0; foreach $data(@data) { $line = $data[$currentline]; # there are brackets around $cu +rrentline if ($line =~ /^$letter/i) { print $line; } $currentline++ }
#!/usr/bin/perl -w use strict; print "Letter? "; my $letter = <STDIN>; chomp $letter; open (DATA, "books.txt") or die "error opening file $!"; my $line; foreach $line(<DATA>) { if ($line =~ /^$letter/i) { print $line; } } close DATA;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Trying to make a search
by ishamael (Beadle) on Jun 04, 2000 at 02:02 UTC | |
|
Re: Trying to make a search
by link (Novice) on Jun 04, 2000 at 01:12 UTC | |
by Alokito (Novice) on Jun 05, 2000 at 10:19 UTC | |
|
RE: Re: Trying to make a search
by Anonymous Monk on Jun 04, 2000 at 08:13 UTC |