[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Perl book..



Check line 9.... should be:
	$position = index($input,' ');   instead of
	$position = index($input,'');

HTH
Dick

>While browsing thourgh your book which I downloaded today,
>I tried an example script.  I copied it and had it run.  it goes
>like this.
>
>print('please type something: ');
>$input=<STDIN>;
>chomp($input);
>print ("You typed: $input\n");
>
>$len = length($input);
>print("Your input is $len characters long.\n");
>
>$position = index($input,'');
>if ($position <0) {
>print ("There are no blanks in your input.\n");
>} else {
>print ("There is a blank at position $position.\n");
>}
>if ($position <0) {
>$substr= $input;
>} else {
>$substr = substr($input,0, $position);
>}
>print ("the first word you typed was $substr.\n");
>
>if ($input =~ //) {
>print ("There is a blank in your input.\n");
>} else {
>print ("There are no blanks in your input.\n");
>}
>
>When I ran the script, I got the following answer.
>
>please type something: Chris, that was a nice book you wrote. Thanks
>
>You typed: Chris, that was a nice book you wrote. Thanks
>Your input is 45 characters long.
>There is a blank at position 0.
>the first word you typed was .
>There is a blank in your input.
>
>The first word "Chris" did not show up. Can you be of some help
>and correct my mistake.
>
>Amit
>
>
>
>***** Want to unsubscribe from this list?
>***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch




***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch