--On 07/22/00 17:33:59 -0400 Sam Carleton <[EMAIL PROTECTED]> wrote:

> I have begun writting my first mod_perl module.  I figured that I would
> get the logic working perl first, considering I am new at the language
> in general.  Well, low and behold, I have a few syntax error which I
> don't know how to resolve.  One issue is how to declare a local
> variable, and the other is a problem with my open statement.  Can
> someone take a look and help me out?  Here is the code:
>
>
> #! /usr/bin/perl
>
> use strict;
>
> sub process {
>         local $str = @_;
 Nope! -> ^^^^^
          my $str = @_;

The use of strict requires you to use lexically scoped variables, which is 
what 'my' does.  'local' simply declares a global variable to have locally 
scoped values.  Using 'local' is referred to as dynamic scoping and has 
different consequences when, say, you call another subroutine from within 
the enclosing brackets that define the local scope.  The difference is a 
paragraph and not a sentence, and so I invite you to read page 184 of the 
camel book, 2nd edition (BTW, the 3rd edition is now out -- yeah!!!).

>         return $str;
> }
>
>
> my $filename="testinput.txt";
> my $fh;
>
> unless( open $fh, $filename) {
>         print STDERR "Cannot open file [$filename]\n";
> }
>
> while($<fh>) {
 Nope!  ^^^^^
 use   <$fh>

Except, if you want to use a variable as a filehandle, you need to either 
use the FileHandle method, or let the variable be a reference to a 
typeglob.  For example:

  open FILE, $filename
    or die "Can't open $filename: $!\n";

  my $fh = \*FILE;

or

  use FileHandle;
  $fh = FileHandle->new;
  $fh->open($filename);

>         chomp;
>         print process($_);
> }
>
> 1;
> __END__
>
> This is the error I am getting:
>
> Global symbol "$str" requires explicit package name at ./test.pl line 6.
> Bareword found where operator expected at ./test.pl line 18, near "$<fh"
>         (Missing operator before fh?)
> Bareword "fh" not allowed while "strict subs" in use at ./test.pl line
> 18.
> syntax error at ./test.pl line 18, near "$<fh"
> syntax error at ./test.pl line 21, near "}"
> Execution of ./test.pl aborted due to compilation errors.

-- Rob


       _ _ _ _           _    _ _ _ _ _
      /\_\_\_\_\        /\_\ /\_\_\_\_\_\
     /\/_/_/_/_/       /\/_/ \/_/_/_/_/_/  QUIDQUID LATINE DICTUM SIT,
    /\/_/__\/_/ __    /\/_/    /\/_/          PROFUNDUM VIDITUR
   /\/_/_/_/_/ /\_\  /\/_/    /\/_/
  /\/_/ \/_/  /\/_/_/\/_/    /\/_/         (Whatever is said in Latin
  \/_/  \/_/  \/_/_/_/_/     \/_/              appears profound)

  Rob Tanner
  McMinnville, Oregon
  [EMAIL PROTECTED]

Reply via email to