[Za-pm] Problem with array.
Spike
spikeh at mweb.co.za
Mon Jun 23 04:49:54 CDT 2003
#!/usr/bin/perl -w
# put -w on same line as #!perl
$a="Are they good or evil?";
@good=qw(Neo Trinity Morpheus);
@builder=qw(Oracle Architect);
@bad=qw(Smith Agents Agent Twins);
print ("Enter the name to see if you can trust them \n");
# brackets are not needed here - but it will still work.
print "Enter the name to see if you can trust them \n";
print ("$a \n");
print ("What is Your Name? \n");
$name=<STDIN>;
chomp $name;
#if ($name=@good){ # This won't work as you are assigning
# the array @good to the var $name,
# not what you want, you want to test
# if the $name is in @good so use grep
print "Your are here to change everyone. \n"
if ( grep("$name", @good) ) {
print "Your are here to change everyone. \n" ; # you missed the semi-colon
}
else {
print "I might kb=know you but you ar not good\n";
# }; don't need semi-colon after a block
}
... etc.
PS don't forget that '=' assigns a value and (for numbers) '==' tests for
equality (for strings it's 'eq')
Spike Hodge
UNIX Programmer
M-Web Technology
021 596 8496
082 901 5265
Click here and make M-Web your homepage
http://homepage.mweb.co.za
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/za-pm/attachments/20030623/6f86e4c7/attachment.htm
More information about the Za-pm
mailing list