Re: my first attempt at a perl script (syntax error)

2000-07-24 Thread Vivek Khera

> "SC" == Sam Carleton <[EMAIL PROTECTED]> writes:

SC> Alex Farber wrote:
>> maybe you should read some introductionary Perl
>> books, like http://www.effectiveperl.com/toc.html or
>> http://www.ebb.org/PickingUpPerl/pickingUpPerl.html

SC> Maybe I have read things like "Programming Perl" from O'Reilly and
SC> "Writting Apache Modules in Perl and C", am tired of reading page after
SC> page and want to do some real coding.  Maybe I thought that folks in the
SC> mod_perl mailing list would be understanding of someone who has spent
SC> many years in another language and needs a little help overcoming some
SC> syntax issues.

If you're having syntax issues then you *really* need to refer to the
docs.  You don't need to read the whole damned book; just look up the
function with which you have problems in the index or online docs.  It
is not that hard to see the syntax of open() and compare it to what
you have to see why it fails.


And the mod_perl list is *NOT* for intro to perl questions.  It is
about mod_perl, not generic perl.

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Vivek Khera, Ph.D.Khera Communications, Inc.
Internet: [EMAIL PROTECTED]   Rockville, MD   +1-301-545-6996
GPG & MIME spoken herehttp://www.khera.org/~vivek/



Re: my first attempt at a perl script (syntax error)

2000-07-22 Thread Rob Tanner



--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($) {
 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 "$ (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 "$ 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]



Re: my first attempt at a perl script (syntax error)

2000-07-22 Thread Sam Carleton

Sam Carleton wrote:
> 
> Alex Farber wrote:
> >
> > A good place to ask is news:comp.lang.perl.misc (after you've
> > read http://www.perl.com/pub/doc/manual/html/pod/perlfaq.html )
> 
> Maybe I have read things like "Programming Perl" from O'Reilly and
> "Writting Apache Modules in Perl and C", am tired of reading page after
> page and want to do some real coding.  Maybe I thought that folks in the
> mod_perl mailing list would be understanding of someone who has spent
> many years in another language and needs a little help overcoming some
> syntax issues.
> 
> One thing is for sure, I did not expect to get a responce such as your,
> one that says: "Go  yourself, if you don't know the language we sure
> as  aren't going to help your ___!!!"
> 
> Live and learn, I guess...

There where a number of people that did reply privately, I cheched my
mod_perl folder first.  I would like to thank eveyone that did reply
kinding to my question.  My question's where answered.  Thank you, I
knew that most participants of the mailing list where willing to help
even when the subject was a bit off topic.  Again, thank you all for the
help!

Sam



Re: my first attempt at a perl script (syntax error)

2000-07-22 Thread Sam Carleton

Alex Farber wrote:
> 
> Hi Sam,
> 
> Sam Carleton wrote:
> > 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.
> 
> maybe you should read some introductionary Perl
> books, like http://www.effectiveperl.com/toc.html or
> http://www.ebb.org/PickingUpPerl/pickingUpPerl.html
> 
> A good place to ask is news:comp.lang.perl.misc (after you've
> read http://www.perl.com/pub/doc/manual/html/pod/perlfaq.html )

Maybe I have read things like "Programming Perl" from O'Reilly and
"Writting Apache Modules in Perl and C", am tired of reading page after
page and want to do some real coding.  Maybe I thought that folks in the
mod_perl mailing list would be understanding of someone who has spent
many years in another language and needs a little help overcoming some
syntax issues.

One thing is for sure, I did not expect to get a responce such as your,
one that says: "Go  yourself, if you don't know the language we sure
as  aren't going to help your ___!!!"  

Live and learn, I guess...

Sam



Re: my first attempt at a perl script (syntax error)

2000-07-22 Thread Alex Farber

Hi Sam,

Sam Carleton wrote:
> 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.

maybe you should read some introductionary Perl 
books, like http://www.effectiveperl.com/toc.html or
http://www.ebb.org/PickingUpPerl/pickingUpPerl.html

A good place to ask is news:comp.lang.perl.misc (after you've 
read http://www.perl.com/pub/doc/manual/html/pod/perlfaq.html )

Regards
Alex

--
http://www.kawo2.rwth-aachen.de/~alex/