CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
<STDIN> not matching contents in an array

 



dsaliba
Novice

May 28, 2013, 3:23 AM

Post #1 of 3 (162 views)
<STDIN> not matching contents in an array Can't Post

I have a file which consists of three names: daniel, elaine and victoria. If I search for daniel I get "you are not on the list". Could someone kindly point out where my mistake is? Thank you.

#!/usr/bin/perl

#open file
open(FILE, "names") or die("Unable to open file");

# read file into an array
@data = <FILE>;

# close file
close(FILE);

#print "@data";

print "Enter name\n";
$entry = <STDIN>;
chomp $entry;

if (grep {$_ eq $entry} @data)
{
print "You are on the list $entry";
}
else
{
print "Your are not on the list";
}

Code



      
    


BillKSmith
Veteran

May 28, 2013, 4:45 AM

Post #2 of 3 (154 views)
Re: [dsaliba] <STDIN> not matching contents in an array [In reply to] Can't Post

There is a newline at the end of every name.

Code
chomp @data;

Good Luck,
Bill


dsaliba
Novice

May 28, 2013, 5:12 AM

Post #3 of 3 (153 views)
Re: [BillKSmith] <STDIN> not matching contents in an array [In reply to] Can't Post


Thank you Bill

In Reply To

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives