Thanks Bill.  Your suggestion eliminated the error I had at line 34.
When I execute the program I get the following errors (which I did not
get prior to inserting the three lines of code below) into the program.

use File::glob ':globally'; 
while (defined($filename = <'c:/Batch Files/*.sec'>)) {             
print "$filename\n";

Errors:

(Error 1) Use of uninitialized value in string eq at
Chapter1Excercisespg29.pl line 12, <STDIN> line 1 after program prompts
"What is your name?" and I enter a valid name.
Use of uninitialized value in string ne at Chapter1Excercisespg29.pl
line 18, <STDIN> line 2

(Error 2) The program does not accept a valid entry for the secret word.
It returns "Wrong, try again.  What is the secretword?"

(Error 3) File::glob portion of the program does not return barney.sec
and fred.sec which are contained in the directory specified in the
program.

Code:

#!c:/perl/bin/perl.exe
init_words();
print "What is your name?";
$name = <STDIN>;
chomp ($name);
$original_name=$name; # save for greeting
if ($name =~ /^erik\b/i) { # back to the other way :-)
    print "Hello, Erik!  How good of you to be here!\n";
} else {
    print "Hello, $original_name!\n"; # ordinary greeting
    $secretword=$words{$name}; # get the secret word
    if ($secretword eq " ") {# oops, not found
        $secretword = "groucho"; # sure, why a duck?
        } 
    print "What is the secret word?";
    $guess = <STDIN>;
    chomp ($guess);
    while ($guess ne $secretword) {
      print "Wrong, try again.  What is the secretword?";
      $guess = <STDIN>;
      chomp ($guess);
    while (! good_word($name,$guess)) {
      print "Wrong, try again. What is the secret word?";
      $guess=<STDIN>;
      chomp ($guess);
  }
 } 
}
## subroutines from here down
   sub init_words {
         use File::glob ':globally';
         while (defined($filename = <'c:/Batch Files/*.sec'>)) {

         print "$filename\n";
       open (WORDSLIST, $filename) ||
              die "can't open $filename:$!";
       if (-M WORDSLIST <= 7.0) {
         while (defined ($name = <WORDSLIST>)) {
           chomp ($name);
           $word = <WORDSLIST>;
         while (defined ($word = <WORDSLIST>)) {
           chomp ($word);
           $words{$name} = $word;
          }
       }
       close (WORDSLIST) || die "couldn't close $filename: $!";
       }
   sub good_word {
       my($somename,$someguess)=@_; # name the parameters
       $somename =~s/\W.*//; # get rid of everything afer first word
       $somename =~tr/A-Z/a-z/; # lowercase everything
       if ($somename eq "erik") {# should not need to guess
           return 1; #return value is true
   }elsif (($words{$somename}||"groucho") eq $someguess) {
    return 1; # it passed, report back to the caller
   }else {
           return 0; # return value is false
   }
}       

   sub log_failure {
       my($somename,$someguess) = @_; # name the parameters
       open(log, ">>failures.log") || die "failures.log: $!";
       print log "bad news: $somename guessed $someguess\n";
       close (log) || die "can't close failures.log: $!";
   }
 }
}

Machine Specifics:

Windows 2000 server, Perl 5.6.1, build 630


Any insight that would shed light on what I am doing wrong is greatly
appreciated.


Thank you and best regards,


Charles

Original Post:

> Hi everyone and Easter Greetings, 
>  
> I am very new to Perl and was attempting to work through an example
using 
> File::Glob feature in Perl (documented in Learning Perl on Win32
Systems) to 
> identify files with a .sec extension on my hard drive.  The location
of the 
> files (fred.sec and barney.sec) are on my hard drive at the c:/Batch
Files/ 
> directory.  When I execute the program (Chapter1Excercisespg29.pl), I
get 
> the following output which is different than what I expected.   
>  
> c:/Batch 
> can't open c:/Batch: there is no such file or directory at 
> Chapter1Excercisespg29.pl at line 34.   
>  
> I thought the program would identify fred.sec, then barney.sec and
then exit 
> when no further matches could be found.   
>  
> I also attempted to use the syntax specified in the documentation
using an 
> array instead of a scalar with little success.   
>  
> use File::Glob ':globally'; 
> my @sources = <*.{sec}>; 
>  
> Any thoughts, revisions or assistance as to what I am doing wrong
would be 
> greatly appreciated.   

>          use File::glob ':globally'; 
>          while (defined($filename = <c:/Batch Files/*.sec>)) {

>          print "$filename\n"; 

Try quoting it since you have a space in your path:
        <'c:/Batch Files/*.sec'>

-- 
   ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
  (_/   /  )    // //       DBE Collectibles
[EMAIL PROTECTED]">Mailto:[EMAIL PROTECTED]
   / ) /--<  o // //      http://dbecoll.tripod.com/ (Free site for
Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic
http://www.todbe.com/

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to