newBee schreef:

> print "Please enter term: \n";
> while(chomp($userInput = <STDIN>)) {
>     last if(/^q$/i);
>     @lineArray = split '\W+', $userInput;
>     foreach $word(@lineArray){
>         if($DEBUG){print "<$word>\n";}
>     }
> }

You (1) forget to check defined (which is implicit with "while
(<STDIN)"), you (2) chomp far too early, you (3) do your regex on $_
where you mean $userInput, etc.

Check the different outputs of:
  perl -MO=Deparse -e' while(chomp($userInput = <STDIN>)) {}'
  perl -MO=Deparse -e' while($userInput = <STDIN>) {}'



#!/usr/bin/perl
  use strict;
  use warnings;

  my $DEBUG = 1;

  while ( my $input = <STDIN> ) {
      print "\nPlease enter term:\n";
      s/^\s+//, s/\s+$// for $input; # not really necessary
      last if $input =~ /^q$/i;
      $DEBUG and print "<$_>\n" for $input =~ m/(\w+)/g;
  }
__END__

-- 
Affijn, Ruud

"Gewoon is een tijger."


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to