[Za-pm] Problem with array.
kmf at pop.co.za
kmf at pop.co.za
Mon Jun 23 05:21:41 CDT 2003
Thanks I'll try
btw my I pasted the code direct from xterm to the webclient ...
The formatting looked fine when I mailed it guess not :)
Karl
--- Spike
<spikeh at mweb.co.za> wrote:
> #!/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
More information about the Za-pm
mailing list