[24147] in Perl-Users-Digest
Perl-Users Digest, Issue: 6341 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 30 14:10:41 2004
Date: Tue, 30 Mar 2004 11:10:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 30 Mar 2004 Volume: 10 Number: 6341
Today's topics:
Re: Syntax error (Martin L.)
Re: Syntax error <mjpliv@eastlink.ca>
Re: Syntax error <mjpliv@eastlink.ca>
Re: Syntax error <ittyspam@yahoo.com>
Re: Syntax error <nobull@mail.com>
Re: Syntax error <mjpliv@eastlink.ca>
Re: Syntax error <sbryce@scottbryce.com>
Re: Syntax error <ittyspam@yahoo.com>
Re: Syntax error <noreply@gunnar.cc>
Re: Trap errors inside MSDOS batch file <nobull@mail.com>
Re: Variable substitution in variable name (Anno Siegel)
Re: Variable substitution in variable name <noreply@gunnar.cc>
Re: Why dosn't this work? <mail@annuna.com>
Re: Why dosn't this work? <ittyspam@yahoo.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 30 Mar 2004 08:10:44 -0800
From: mjpliv@eastlink.ca (Martin L.)
Subject: Re: Syntax error
Message-Id: <36fd063b.0403300810.5df82398@posting.google.com>
> [snip]
Brian McCauley <nobull@mail.com> wrote in message news:<u965cm8sl9.fsf@wcl-l.bham.ac.uk>...
> "Martin Livingston" <mjpliv@hfx.eastlink.ca> writes:
>
> > I have been looking at this for about 6 hours
>
> > I am a newbie so its probably something very simple.
>
> First a but of general advice...
>
> You should always declare all variables as lexically scoped in the
> smallest applicable lexical scope unless you have a positive is a
> reason to do otherwise. BTW: this is not perculliar to Perl, it
Thanks for the response, it turned out to be case of me spelling the
"if" command with a capital "I" (as well as a typo in a variable
name). Thats probably why it didn't like the associated curly
brackets. I would have looked at that for days and not seen that one.
With regards to your advice, I am not familiar with the term
"lexically" but I am guessing that it refers to declaring my variables
as I first use them rather than a list at the beginning of the script.
If that is the accepted convention then I will start doing so. I am
learning from a book that did't cover that. It also showed the
external subroutines without the "use strict" line and I assumed it
was not needed. I do "use strict" in all of my normal perl scripts. I
added both the "use strict" and "use warnings" line, corrected my two
typo's uploaded it back to my server. I got an error to the effect
that could not locate files required to use warnings so I removed the
"use warnings" line and everything runs just fine.
I have downloaded a copy of ConText to use instead of NOTEPAD to write
this stuff and will try in the future to indent lines to make things a
little easier to read.
Martin L.
------------------------------
Date: Tue, 30 Mar 2004 16:24:38 GMT
From: "Martin L." <mjpliv@eastlink.ca>
Subject: Re: Syntax error
Message-Id: <abhac.12890$kc2.280908@nnrp1.uunet.ca>
ko wrote:
>
> Not sure exactly why you got those errors, did a copy/paste and got
> different ones. Did you copy/paste in your post, or type it?
>
> So I didn't go through the whole script, but a cursory inspection
> revealed a couple of problems. Hopefully the corrections will help
> get you started. After corrected it passed syntax checks (-c switch),
> assuming 'use strict' and 'use warnings'. Maybe that's the reason you
> got the different error messages - you should always start your
> scripts with:
>
> use strict;
> use warnings;
>
> [snip code]
>
>
> The way you have the code formatted is very hard to read. Issue a
> 'perldoc perlstyle' from your shell for some guidelines to make your
> scripts easier to read/maintain.
>
> HTH - keith
Thanks for the response!
Nice catch on the capital "I"- I would have looked for that one a long
time before seeing it. (and the other typo).
Book I am learning from does not show the "use strict" or "use
warnings" lines in external .lib files. Normally i would use the "use
strict" in all my scripts. I added both to the problem script,
corrected the typo's and I got an error to the effect that it could not
find the files required for "use warnings". I removed it and everything
runs fine now. Thanks for the input.
Do you have a URL for a site that discusses perl formating norms to
make my script more readable. I have yet to be able to get my resident
copy of perl to spit out anything.
Thanks
Martin L.
------------------------------
Date: Tue, 30 Mar 2004 16:24:38 GMT
From: "Martin L." <mjpliv@eastlink.ca>
Subject: Re: Syntax error
Message-Id: <abhac.12891$kc2.280908@nnrp1.uunet.ca>
Bernard El-Hagin wrote:
> "Martin Livingston" <mjpliv@hfx.eastlink.ca> wrote:
>
> [...]
>
> > If ($parts[1] eq 'th') {
> ^^
>
>
> That should be "if" not "If".
That was in fact one of the problems, and hard to see too - Thanks
------------------------------
Date: Tue, 30 Mar 2004 11:38:52 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Syntax error
Message-Id: <20040330113807.Y19862@dishwasher.cs.rpi.edu>
On Tue, 30 Mar 2004, Martin L. wrote:
> Do you have a URL for a site that discusses perl formating norms to
> make my script more readable. I have yet to be able to get my resident
> copy of perl to spit out anything.
Run the command
perldoc perlstyle
from your shell or command line. That will give you a good beginning for
how your scripts should look.
Paul Lalli
------------------------------
Date: 30 Mar 2004 17:45:11 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Syntax error
Message-Id: <u9y8pi7088.fsf@wcl-l.bham.ac.uk>
mjpliv@eastlink.ca (Martin L.) writes:
> Brian McCauley <nobull@mail.com> wrote in message news:<u965cm8sl9.fsf@wcl-l.bham.ac.uk>...
> > "Martin Livingston" <mjpliv@hfx.eastlink.ca> writes:
> >
> > > I have been looking at this for about 6 hours
> >
> > > I am a newbie so its probably something very simple.
>
> Thanks for the response, it turned out to be case of me spelling the
> "if" command with a capital "I" (as well as a typo in a variable
> name). Thats probably why it didn't like the associated curly
> brackets. I would have looked at that for days and not seen that
> one.
That does not tally with the errors you posted before. I just ran a
syntax check on your original post and got:
syntax error at - line 47, near ") {"
syntax error at - line 77, near "}"
That's different line numbers and diferent "near" tokens.
> > First a but of general advice...
> >
> > You should always declare all variables as lexically scoped in the
> > smallest applicable lexical scope unless you have a positive is a
> > reason to do otherwise. BTW: this is not perculliar to Perl, it
> With regards to your advice, I am not familiar with the term
> "lexically"
Lexically scoped variables are ones declared using my().
> I am guessing that it refers to declaring my variables
> as I first use them rather than a list at the beginning of the script.
> If that is the accepted convention then I will start doing so. I am
> learning from a book that did't cover that. It also showed the
> external subroutines without the "use strict" line and I assumed it
> was not needed.
Use strict is lexically scoped. There's that word again - it simply
means it has effect until to the end of the current source code block
- i.e. the close of the most reacently opened code-block curlies or
the end of the source file.
Anyhow perhaps you should replace your book with one that addresses
Perl5 (other than as an afterthought). Any tutorial that shows
Perl4-style libraries as the principal way of handling external
subroutines was clearly (originally) written with Perl4 in mind.
> I do "use strict" in all of my normal perl scripts. I
> added both the "use strict" and "use warnings" line, corrected my two
> typo's uploaded it back to my server.
This is C21. We don't submit batch jobs on punch cards. You should at
least syntax-check and preferrably test on a local installation of
Perl.
> I got an error to the effect that could not locate files required to
> use warnings so I removed the "use warnings" line and everything
> runs just fine.
IIRC the current Perl version is 5.8.3. Many people still have 5.6.1
but there can be no excuse to be using anything ealier. (use
"warnings" first appeared in 5.6).
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 30 Mar 2004 17:50:47 GMT
From: "Martin L." <mjpliv@eastlink.ca>
Subject: Re: Syntax error
Message-Id: <Xriac.12914$kc2.281761@nnrp1.uunet.ca>
Paul Lalli wrote:
> On Tue, 30 Mar 2004, Martin L. wrote:
>
> > Do you have a URL for a site that discusses perl formating norms to
> > make my script more readable. I have yet to be able to get my
> > resident copy of perl to spit out anything.
>
> Run the command
> perldoc perlstyle
> from your shell or command line. That will give you a good beginning
> for how your scripts should look.
>
> Paul Lalli
Please don't laugh but what is a shell and what function offers me a
command line? I have been uploading to my hosting server who offers a
perl checker. Its terrible being a newbie and I am glad i don't write
perl for living - i'd starve to death! I did install perl on my local
PC and it is configured in my boot sequence (I see it happening)
everytime I turn it on. Perhaps if I told you that, other than HTML, I
haven't written anything since Fortran IV about 35 years ago and that
was using key punch cards!!!!!!
------------------------------
Date: Tue, 30 Mar 2004 10:47:26 -0700
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Syntax error
Message-Id: <106jdbskkp18j6a@corp.supernews.com>
Martin L. wrote:
> Please don't laugh but what is a shell
If you are asking that question, you must be using Windows. Think DOS.
> and what function offers me a command line?
If you are on Windows, a DOS window.
> I have been uploading to my hosting server who offers a
> perl checker.
It really is a lot easier to test locally. Install Apache server on your
local machine and configure it to run CGI scripts locally.
------------------------------
Date: Tue, 30 Mar 2004 13:05:22 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Syntax error
Message-Id: <20040330130345.H19862@dishwasher.cs.rpi.edu>
On Tue, 30 Mar 2004, Martin L. wrote:
> Paul Lalli wrote:
>
> > On Tue, 30 Mar 2004, Martin L. wrote:
> >
> > > Do you have a URL for a site that discusses perl formating norms to
> > > make my script more readable. I have yet to be able to get my
> > > resident copy of perl to spit out anything.
> >
> > Run the command
> > perldoc perlstyle
> > from your shell or command line. That will give you a good beginning
> > for how your scripts should look.
> >
> > Paul Lalli
>
> Please don't laugh but what is a shell and what function offers me a
> command line? I have been uploading to my hosting server who offers a
> perl checker. Its terrible being a newbie and I am glad i don't write
> perl for living - i'd starve to death! I did install perl on my local
> PC and it is configured in my boot sequence (I see it happening)
> everytime I turn it on. Perhaps if I told you that, other than HTML, I
> haven't written anything since Fortran IV about 35 years ago and that
> was using key punch cards!!!!!!
I'm assuming at this point that you're running Windows, correct? That
being the case, go to the Start Menu, and click "Run". In the box that
follows, type 'cmd' (no quotes) and hit enter. The black window that pops
up now is your command line window, roughly equivalent to the Unix concept
of a shell.
It is in this command line window that you should type the command
perldoc perlstyle
Hope this helps
Paul Lalli
------------------------------
Date: Tue, 30 Mar 2004 20:59:38 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Syntax error
Message-Id: <c4cg5q$2duke0$1@ID-184292.news.uni-berlin.de>
Brian McCauley wrote:
> IIRC the current Perl version is 5.8.3. Many people still have
> 5.6.1 but there can be no excuse to be using anything ealier. (use
> "warnings" first appeared in 5.6).
Excuse or not, in reality earlier versions are still in use. One
example: The Perl version available from SourceForge's web server is
5.005_03.
The programs I've made available to 'the world' require no later Perl
version than 5.005. So I'm still using -w or $^W, and don't declare
variables using 'our'.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 30 Mar 2004 18:02:26 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Trap errors inside MSDOS batch file
Message-Id: <u9ptau6zfh.fsf@wcl-l.bham.ac.uk>
"News" <Thalaiappan.Sundaramoorthy@sbsc.siemens.co.uk> writes:
> I would like to know, how to trap errors while running perl script from
> MSDOS batch file.
Exactly the same way you would for any other program. (Your question
has nothing whatever to do with Perl).
> Actually I am planning to run multiple perl scripts (Script1.pl ,
> Script2.pl... ) in a batch file.
Using a whealbarrow to carry your excavator to the dig.
> Below is the logical requirement.
>
> perl Script1.pl "argument 1"
> if it is success ##need some command for this
> perl Script2.pl "arg 1"
> else
> exit.
> Now I need some method to findout whether first Script execution is success
> or not. Here success means, there is no error message generated while
> running the script.
Do you really have to do that? Would it not be simpler to just rely
on the exit status?
Dunno how you can do that. Do you really need to use MSDOS shell
(COMMAND)? Can you not use a better one. Even the NT Windows shell
(CMD) would be better. In NT command shell you can do things
conditionally using "IF" based on the exit code of a command (for
details RTFM on "IF" in CMD). I don't know if the same syntax works
in MSDOS.
If you can't rely on the exit status then I'd suggest you get a real
shell or sumply use Perl.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 30 Mar 2004 16:09:05 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Variable substitution in variable name
Message-Id: <c4c631$ssc$1@mamenchi.zrz.TU-Berlin.DE>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> mshetty wrote:
> > Have the following code where I want to reduce the lines of
> > code:
[...]
> Instead of all the if-elsif-else statements, you could do something like:
>
> if ($name =~ /\.(\w+)$/) {
> $total{$1}++;
> push @{ $files{$1} }, $name;
> }
The %total hash is not needed any more. The count can be read off the
arrays:
my $total = @{ $files{ $key}}
Anno
------------------------------
Date: Tue, 30 Mar 2004 18:27:34 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Variable substitution in variable name
Message-Id: <c4c78h$2h678o$1@ID-184292.news.uni-berlin.de>
Web Surfer wrote:
> You could use a hash.
Agreed.
> my %totals = ( "cpp" => 0 , "h" => 0 , "c" => 0 );
> # of course you will need to code the entries for ALL possible
> # filename extensions
No. Please read the rest of the thread before posting your advice.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 30 Mar 2004 17:05:52 GMT
From: Joe <mail@annuna.com>
Subject: Re: Why dosn't this work?
Message-Id: <QNhac.8401$lt2.3281@newsread1.news.pas.earthlink.net>
ctcgag@hotmail.com wrote:
> Joe <mail@annuna.com> wrote:
>
>>I am trying to write an object oriente program simmilar to one that I
>>did in C++. This is bare bones strpped down for debugging.
>
>
> Didn't you post this last week and ignore all attempts to help you then?
>
>
>
>>my $space;
>
>
> Don't do that here.
>
> Where's the package statement?
>
>
>
>>#spaces of the grid
>>
>>sub new{
>>
>>$space = {
>> char => "@",
>> tile => $_[0]
>> };
>>print $space->{tile}; <-- This prints /* OK */
>>bless $space, 'Space';
>>return $space;
>>}
>
>
> Please make your comments look like comments.
> In Perl, they start with #, not <--
>
> When does it print /* OK */? As far as I can tell, "new" never gets
> invoked.
Yes it does, that is my constructor. My functions get invoked in my main
program. <-- arn't comments, they are where my problems and questions
are. I was just being graphic showing exactly why I am baffeled at why
I get the output I do.
>
>
>>sub fchsym {
>>print "$space->{tile} \n"; <-- This won't print, why?
>>print "$space->{char} \n"; <-- This does print.
>>
>>return $space->{tile};
>> }
>
>
> When does this print or not print, as the case may be? It doesn't appear
> that fchsym ever gets invoked.
>
> Xho
>
I did look at them although I didn't respond. I have been working with
this problem for a while and testing different things. My main problem
is that>>sub fchsym {
>>print "$space->{tile} \n"
Is not printing anything. Other datamembers of the object print and
this data gets into the object, showing the output in the constructor.
The data gets into the object, it prints data from one datamember but
won't print from another.
------------------------------
Date: Tue, 30 Mar 2004 12:19:42 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Why dosn't this work?
Message-Id: <20040330121754.W19862@dishwasher.cs.rpi.edu>
On Tue, 30 Mar 2004, Joe wrote:
> >>#spaces of the grid
> >>
> >>sub new{
> >>
> >>$space = {
> >> char => "@",
> >> tile => $_[0]
> >> };
> >>print $space->{tile}; <-- This prints /* OK */
> >>bless $space, 'Space';
> >>return $space;
> >>}
> >
> >
> > Please make your comments look like comments.
> > In Perl, they start with #, not <--
> >
> > When does it print /* OK */? As far as I can tell, "new" never gets
> > invoked.
> Yes it does, that is my constructor. My functions get invoked in my main
> program. <-- arn't comments, they are where my problems and questions
> are. I was just being graphic showing exactly why I am baffeled at why
> I get the output I do.
The point is that since you didn't *show* us your main program, we have no
way of knowing what's happening when you're trying to call these
functions. You haven't given anyone enough information to help you solve
your problem. Please read the posting guidelines for this group, which
say that you should post a small *but complete* program demonstrating the
problem. You haven't given us a complete program from which to work.
Paul Lalli
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 6341
***************************************