[22620] in Perl-Users-Digest
Perl-Users Digest, Issue: 4841 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 14 03:05:51 2003
Date: Mon, 14 Apr 2003 00:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 14 Apr 2003 Volume: 10 Number: 4841
Today's topics:
Re: Determine type of file ascii or bin <flavell@mail.cern.ch>
Re: Determine type of file ascii or bin (Walter Roberson)
Re: Determine type of file ascii or bin <kasp@epatra.com>
first time @ form fillers <sav_me_to_nospam@hotmail.com>
Re: Help with script to parse a log file and run a comm <mgjv@tradingpost.com.au>
Re: help with using Net-Telnet module.. <bob@nowhere.com>
Re: Network socket - binary data. <gb2312@attbi.com>
Re: Network socket - binary data. <News@LearnQuick.Com>
newline split <sav_me_to_nospam@hotmail.com>
Re: newline split <sav_me_to_nospam@hotmail.com>
Re: newline split <wksmith@optonline.net>
PERL Resources and Tools... the expanded version! <newsgroups@goodboysdo.net>
perlbug and diffs <fxn@hashref.com>
Re: PHP Code to PERL conversion... (Vijoy Varghese)
Re: PHP Code to PERL conversion... <tassilo.parseval@rwth-aachen.de>
Re: Return value from perl module (Tad McClellan)
Re: Shortcut <krahnj@acm.org>
Re: Shortcut <uri@stemsystems.com>
Thread-safe resolver? <ryan@sasknow.com>
variables in modules <Jamie_Bohr@Agilent.com>
Re: variables in modules <jkeen@concentric.net>
Re: What is wrong? <mgjv@tradingpost.com.au>
Re: What is wrong? (Jay Tilton)
Why do I get an error <mail@annuna.com>
Re: Why do I get an error <uri@stemsystems.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 13 Apr 2003 23:35:50 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Determine type of file ascii or bin
Message-Id: <Pine.LNX.4.53.0304132334390.10379@lxplus081.cern.ch>
On Sun, Apr 13, Joe Mc Cool inscribed on the eternal scroll:
> For ftp just assume binary all the time !
I suppose you wouldn't consider learning a bit about your topic before
offering advice on it?
------------------------------
Date: 14 Apr 2003 05:51:17 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: Determine type of file ascii or bin
Message-Id: <b7di8l$1v4$1@canopus.cc.umanitoba.ca>
In article <b7carp$87j$1$8302bc10@news.demon.co.uk>,
Ras <Ras@majere.demon.co.uk> wrote:
:Need a pointer...
:What's the easiest way to determine if a file is binary or ASCII ? this
:would change the way you read and write. {i think}
:i need to move a file and i wont always know what type of file. i have
:noticed sending asci files as bin via ftp can cause wonderful results
There is NO reliable way to determine whether a file is binary
or ASCII. What you might be thinking of as an ASCII file
might be a binary file that *happens* to look like an ASCII file.
You have to know whether the file was *intended* to be a binary
file or ASCII file.
Someone suggested using the -T function. -T and -B are
heuristics and can easily be wrong:
The "-T" and "-B" switches work as follows. The first block or so
of the file is examined for odd characters such as strange control
codes or characters with the high bit set. If too many strange
characters (>30%) are found, it's a "-B" file, otherwise it's a
"-T" file. Also, any file containing null in the first block is
considered a binary file.
So if your file -happens- to look like text in the first block,
it might not be marked as -B even though it should be.
Someone suggested always ftp'ing in binary mode, and other people
jumped on them, complaining about line termination issues or
just generally insulting them. I, though, would point out
that simple tests such as -T/-B do not take into account
the possibility of text files that are ISO8859-*. Even if
the only extension characters beyond ASCII that are used
are the Euro symbol or the pound currency symbol, you can
easily end up with "text" characters that have their high-bit
set... particularily if one prepared the file in Word or
WordPerfect and "smart quotes" got put in.
These days, "text files" include UTF-8, UTF-16, and UTF-32,
some of which require bytes with the high bit set to do much
of anything.
If you are transfering files between systems that have different
ideas about line termination and that is causing problems, then
chances are that you are transfering files between systems with
different ideas about character set encodings. You thus should
not be merely testing about whether a file is "ASCII" or not, you
should also be worrying about the file encoding, file creator's
intent, and so on.
And yes, I -have- encountered files that -looked- exactly like text but
turned out to be binary. One of them was a license file, and the
license would not work until I went back and ensured I used binary
end-to-end.
--
vi -- think of it as practice for the ROGUE Olympics!
------------------------------
Date: Mon, 14 Apr 2003 11:48:49 +0530
From: "Kasp" <kasp@epatra.com>
Subject: Re: Determine type of file ascii or bin
Message-Id: <b7djuu$u1h$1@newsreader.mailgate.org>
If you are making something specific to Unix try magic.
See the man pages for help on magic - "man magic"
--
Perl is designed to give you several ways to do anything, so
consider picking the most readable one.
-- Larry Wall
------------------------------
Date: Mon, 14 Apr 2003 17:04:40 +1000
From: "Psyk" <sav_me_to_nospam@hotmail.com>
Subject: first time @ form fillers
Message-Id: <b7dmi8$qm8$1@perki.connect.com.au>
Which module would be best to make a form filler for this page in regards to
the sms features here?
http://www.cse.unsw.edu.au/~s2250107/
------------------------------
Date: Mon, 14 Apr 2003 00:34:52 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Help with script to parse a log file and run a command.
Message-Id: <slrnb9k0hc.4ba.mgjv@verbruggen.comdyn.com.au>
On 11 Apr 2003 05:49:41 -0700,
MichaelS <spivackm@calib.com> wrote:
> Hi All,
>
> I am trying to write a shell script to parse through a mysql error log
> and if it find's a specific error, one to do with replication, that it
> will run a command to shutdown the current mysql server.
\begin{offtopic}
Have you had a look at swatch? It seems to be the thing that does what
you are trying to do.
http://swatch.sourceforge.net/
\end{offtopic}
Martien
--
|
Martien Verbruggen | Freudian slip: when you say one thing but
Trading Post Australia | mean your mother.
|
------------------------------
Date: Sun, 13 Apr 2003 18:54:20 -0500
From: bob <bob@nowhere.com>
Subject: Re: help with using Net-Telnet module..
Message-Id: <3e99f2aa$1_1@127.0.0.1>
He's reading from network equipment. The Win32 modules have nothing to
do with that, unles the network equipment was Windows.
On Sun, 13 Apr 2003 09:28:23 -0500, supportgeek wrote:
> since you were using vbscript, it can be safely assumed that your
> working on a windows based network. Look into the Win32 modules.
> www.rothconsulting.com
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
------------------------------
Date: Mon, 14 Apr 2003 02:25:22 GMT
From: gb2312 <gb2312@attbi.com>
Subject: Re: Network socket - binary data.
Message-Id: <l_oma.121999$ug3.243629@rwcrnsc51.ops.asp.att.net>
I believe you can use read/write or sysread/syswrite with sockets, which
should handle binary very well.
--
Bin
Ras wrote:
> I have found lots of examples of how to pass ASCII data via IO sockets, and
> its essentially the same as a chat server or webserver...
>
> what i am having a hard time finding data on is how to pass binary data
> (many examples state they don't work with binary data, but don't give an
> alternative.)
>
> i am trying to move data from one system to another without using FTP.
>
> thanks for anyhelp (and you should print any help on this, as even
> commercial books lack this basic example)
>
> Ford
>
>
>
------------------------------
Date: Mon, 14 Apr 2003 06:04:24 GMT
From: "Herb Martin" <News@LearnQuick.Com>
Subject: Re: Network socket - binary data.
Message-Id: <Ibsma.67427$vI3.2348888@twister.austin.rr.com>
Look up one of the UDP samples like the DNS
resolvers or servers. These have to unpack (hint)
request data and pack (hint) answer data into
packets.
--
Herb Martin
Try ADDS for great Weather too:
http://adds.aviationweather.noaa.gov/projects/adds
------------------------------
Date: Mon, 14 Apr 2003 11:36:40 +1000
From: "Psyk" <sav_me_to_nospam@hotmail.com>
Subject: newline split
Message-Id: <b7d3b8$e50$1@perki.connect.com.au>
How do I split this on foreach new line, i dont think it works.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/usr/bin/perl
$data_file="../filetoparse";
open(DAT, $data_file) || die("Could not open file!");
@raw_data=<DAT>;
close(DAT);
print "Content-type: text/html\n\n";
print "<HTML><BODY>";
foreach $operation (@raw_data)
{
chop($operation);
($newline)=split(/\n/ ,@operation);
print $operation;
print "<BR>\n";
}
print "</BODY></HTML>";
------------------------------
Date: Mon, 14 Apr 2003 12:14:39 +1000
From: "Psyk" <sav_me_to_nospam@hotmail.com>
Subject: Re: newline split
Message-Id: <b7d5ig$fjo$1@perki.connect.com.au>
I figured it out. is there a better way of doing this
~~~~~~~~~~~~~
#!/usr/bin/perl -w
$data_file="../filetoparse";
open(DAT, $data_file) || die("Could not open file!");
@raw_data=<DAT>;
close(DAT);
print "Content-type: text/html\n\n";
print "<HTML><BODY>";
foreach $operation (@raw_data)
{
chop($operation);
$newline=split(/\n/ ,@operation);
@moo[$num] = $operation;
$num++;
}
print $moo[2]; # or whatever line desired.
print "</BODY></HTML>";
"Psyk" <sav_me_to_nospam@hotmail.com> wrote in message
news:b7d3b8$e50$1@perki.connect.com.au...
> How do I split this on foreach new line, i dont think it works.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> #!/usr/bin/perl
>
> $data_file="../filetoparse";
>
> open(DAT, $data_file) || die("Could not open file!");
> @raw_data=<DAT>;
> close(DAT);
>
> print "Content-type: text/html\n\n";
> print "<HTML><BODY>";
>
> foreach $operation (@raw_data)
> {
> chop($operation);
> ($newline)=split(/\n/ ,@operation);
> print $operation;
> print "<BR>\n";
>
> }
> print "</BODY></HTML>";
>
>
------------------------------
Date: Mon, 14 Apr 2003 02:46:01 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: newline split
Message-Id: <Jhpma.59077$Xd1.21891610@news4.srv.hcvlny.cv.net>
"Psyk" <sav_me_to_nospam@hotmail.com> wrote in message
news:b7d3b8$e50$1@perki.connect.com.au...
> How do I split this on foreach new line, i dont think it works.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> #!/usr/bin/perl
>
> $data_file="../filetoparse";
>
> open(DAT, $data_file) || die("Could not open file!");
> @raw_data=<DAT>;
There probably is no advantage of reading the entire file into memory as
long as you are going to process it one line at a time.
> close(DAT);
The array @raw_data probably does not contain what you think. There is
one element for every newline in the file.
>
> print "Content-type: text/html\n\n";
> print "<HTML><BODY>";
>
> foreach $operation (@raw_data)
> {
> chop($operation);
This will remove the only newline from every element.
> ($newline)=split(/\n/ ,@operation);
stricture would have warned you about the typo. This statement cannot
do anything useful because there are no newlines to split on.
> print $operation;
> print "<BR>\n";
>
> }
> print "</BODY></HTML>";
>
>
If you intend to replace every newline with an HTML <BR> and a newline,
use the substitution operator.
perl -pie's!/n!/<BR>\n!' file_to_parse (untested)
Otherwise, you must parse the HTML. This is not a trivial task. I am
sure that other responders will recommend modules that will help.
Good Luck,
Bill
------------------------------
Date: Mon, 14 Apr 2003 02:43:41 GMT
From: "gbd" <newsgroups@goodboysdo.net>
Subject: PERL Resources and Tools... the expanded version!
Message-Id: <xfpma.23793$4P1.2122023@newsread2.prod.itd.earthlink.net>
http://www.goodboysdo.net/WEBRES/index.htm
I researched these sites and here it is. ASP, DHTML, Java, JavaScript,
Perl, PHP, XML and other links to, what I would describe as, credible webdev
sites. Yes, unfortunately, there are many sites that have popups, want to
find out who you are to spam you and other issues that you want to avoid,
but these sites I researched are pretty good and credible. Take a look,
suggest a site if you want, but please remember that I am targeting a
certain type/level of credibility in these sites I have chosen. Now for
those of you who think it is not enough, I have placed an image called dmoz
(toe.gif?) on the left side (lower down the left side) of the screen of the
pages covering specific languages... click it for PERL links galore!!!
Enjoy and thanks,
g
PS: For newbies, read "Learning Perl" 3rd Edition!
------------------------------
Date: Sun, 13 Apr 2003 22:11:01 +0000 (UTC)
From: Xavier Noria <fxn@hashref.com>
Subject: perlbug and diffs
Message-Id: <b7cn9l$k3h$1@news.ya.com>
Is there a way to attach a patch to a bug report generated and sent by
perlbug?
-- fxn
------------------------------
Date: 13 Apr 2003 20:56:40 -0700
From: viijv@thedifferenZ.com (Vijoy Varghese)
Subject: Re: PHP Code to PERL conversion...
Message-Id: <4c08aaff.0304131956.7d115665@posting.google.com>
Hi Gunnar,
Who said i didnt made any try? i was behind this stuff for some 2 days
and i am not that bad at perl. The point is that i am not that good
with php. So i cant make out what that code do. I tried to understand
what each line of that code do buy feeding demo data to each... and it
was fine to a particular level, but i got stuck when i reached the '^'
character.
$k_ipad = $key ^ str_repeat(chr(0x36), 64);
It was just translating a string into some other 'code_string'. And
with my 2 years experience in perl, i dont remember any code in perl
which does that job. So i just gaveup and came here. And this is what
i got... :-)
George thankz for your support.
You know how i fixed that problem? i edited that php function and made
it something more unsecure.
i am now using this code
function md5_hmac($data, $key)
{
global $pwseed;
$password = crypt($data, substr($data,2,2));
return $password;
}
instead of
function md5_hmac($data, $key)
{
if (strlen($key) > 64)
$key = pack('H*', md5($key));
$key = str_pad($key, 64, chr(0x00));
$k_ipad = $key ^ str_repeat(chr(0x36), 64);
$k_opad = $key ^ str_repeat(chr(0x5c), 64);
return md5($k_opad . pack('H*', md5($k_ipad . $data)));
}
just because, i couldnt find a proper perl translation of the original
one :-(
have a nice time...
Regards
Vijoy~
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<b7921e$cd748$1@ID-184292.news.dfncis.de>...
> Vijoy Varghese wrote:
> > Can some one translate this to perl?
> > ...
> > I want this stuff for free
>
> George wrote:
> > I got some very free nice help in this group, and I was surprised
> > by these "complaints" about Vijoy's request. If I had the knowledge
> > I certainly would have translated that small code segment, a simple
> > enough task for the knowledgeable. Its not like Vijoy asked for a
> > complete CGI application to be written.
>
> I have also got some valuable help in this group. Nevertheless, I find
> the responses you quoted very reasonable.
>
> When somebody is struggling with, but fails in solving, some Perl
> problem, this group is a good place to seek help. But asking for free
> programming help, when it's obvious that the poster hasn't made any
> own effort - this poster had apparently not even considered to learn
> *any* Perl - it's unreasonable. Totally unreasonable.
>
> / Gunnar
------------------------------
Date: 14 Apr 2003 05:27:02 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: PHP Code to PERL conversion...
Message-Id: <b7dgr6$46e$1@nets3.rz.RWTH-Aachen.DE>
[ Please don't top-post ]
Also sprach Vijoy Varghese:
> Who said i didnt made any try? i was behind this stuff for some 2 days
> and i am not that bad at perl. The point is that i am not that good
> with php. So i cant make out what that code do. I tried to understand
> what each line of that code do buy feeding demo data to each... and it
> was fine to a particular level, but i got stuck when i reached the '^'
> character.
>
> $k_ipad = $key ^ str_repeat(chr(0x36), 64);
> It was just translating a string into some other 'code_string'. And
> with my 2 years experience in perl, i dont remember any code in perl
> which does that job. So i just gaveup and came here. And this is what
> i got... :-)
The code in Perl that does this job is '^' so this was a part that
didn't need any translation at all. The above line in Perl would
probably look like
my $k_ipad = $key ^ (chr(0x36) x 64);
given that I interpreted the purpose of str_repeat() correctly.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Sun, 13 Apr 2003 22:04:15 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Return value from perl module
Message-Id: <slrnb9k99f.hbd.tadmc@magna.augustmail.com>
Sha Sha <shasha1980@hotmail.com> wrote:
> Let's hear it for typos.
How long did it take for you to find the typo?
How long would it have taken if you had turned on strictures?
If you leave strictures off (even in little test programs),
you are pretty much guaranteed to waste time sooner or later...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 13 Apr 2003 23:04:17 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Shortcut
Message-Id: <3E99ECD6.695F50FF@acm.org>
Joe Creaney wrote:
>
> Bob Walton wrote:
> > Joe Creaney wrote:
> >
> >> what is the shortcut for swapping likew this this I can't seem to find
> >> it.
> >>
> >> $c = $a;
> >> $a = $b;
> >> $b = $c;
> >
> > ($c,$a,$b)=($a,$b,$c);
> >
> > except that will preserve the original contents of $c, where your code
> > above will lose it.
>
> No I want to swap a and b I don't care about c it is just a holder.
>
> ($a) = ($b) will swap values?
No, you want:
( $a, $b ) = ( $b, $a );
John
--
use Perl;
program
fulfillment
------------------------------
Date: Mon, 14 Apr 2003 00:44:56 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Shortcut
Message-Id: <x7ptnpewl3.fsf@mail.sysarch.com>
>>>>> "A" == Abigail <abigail@abigail.nl> writes:
A> Uri Guttman (uri@stemsystems.com) wrote on MMMDXII September MCMXCIII in
A> <URL:news:x7znmudvkg.fsf@mail.sysarch.com>:
A> :) >>>>> "C" == Cybergrafx <cybergrafx@hotmail.com> writes:
A> :)
A> :) C> Maybe you're trying to recall this:-
A> :)
A> :) C> $a ^= $b;
A> :) C> $b ^= $a;
A> :) C> $a ^= $b;
A> :)
A> :) not too good if those are strings of different lengths. the shorter will
A> :) get padded with null bytes and the results will all have the same length
A> :) which isn't the same as a clean swap.
A> And even worse if the scalars are references.
hmm, refs in numeric context do return an int (pointer address) but you
can't assign a modified ref so you lose the refness. :)
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Sun, 13 Apr 2003 22:44:39 -0600
From: Ryan Thompson <ryan@sasknow.com>
Subject: Thread-safe resolver?
Message-Id: <20030413191615.M53704-100000@ren.sasknow.com>
Hi All,
I'm using iThreads in 5.8.0 on FreeBSD 4.7 for what is (basically) a
producer-consumer problem. Several producer threads are created to
look up DNS information from many hosts, the results of which are
passed to a single consumer thread and merged for output.
The threads are working wonderfully. However, Net::DNS is not ;-)
(Memory leaks and core dumps when threaded). So, as a horrible hack,
I've been forced to exec host(1) and grab its exit value. Yes, it's
slow. Yes, it's still many times faster than doing the lookups
synchronously. :-)
I've scoured CPAN, the web, and several group archives, but haven't
been able to find a solution. Any suggestions? Or will I have to roll
my own?
Thanks,
- Ryan
--
Ryan Thompson <ryan@sasknow.com>
SaskNow Technologies - http://www.sasknow.com
901-1st Avenue North - Saskatoon, SK - S7K 1Y4
Tel: 306-664-3600 Fax: 306-244-7037 Saskatoon
Toll-Free: 877-727-5669 (877-SASKNOW) North America
------------------------------
Date: Sun, 13 Apr 2003 16:46:27 -0600
From: "Jamie Bohr" <Jamie_Bohr@Agilent.com>
Subject: variables in modules
Message-Id: <1050273965.241758@goodnews.cos.agilent.com>
I am tring to find out what variables are set in a Perl module and what the
variables are set too. So far I have hit some brick walls. dumpvar.pl does
not return array values. For example I have the following Perl module named
test.pm in a modules directory:
######################
package test_config;
use strict;
use vars qw($VERSION %test @test);
require Exporter;
# set the version for version checking
$VERSION = 2.00;
%test = ("key" => "value");
@test = (1,2,3,4);
###########################
If I run the following at a command prompt:
perl -e '
use modules::test;
require "dumpvar.pl";
dumpvar("test_config");'
I get:
@test = (
)
%test = (
)
$VERSION = 2
I expected to get more, like the values of @test and %test. Please tell me
there is a better way.
Thank you in advance,
Jamie
------------------------------
Date: 14 Apr 2003 00:17:00 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: variables in modules
Message-Id: <b7culs$sq7@dispatch.concentric.net>
"Jamie Bohr" <Jamie_Bohr@Agilent.com> wrote in message
news:1050273965.241758@goodnews.cos.agilent.com...
> I am tring to find out what variables are set in a Perl module and what
the
> variables are set too. So far I have hit some brick walls. dumpvar.pl
does
> not return array values. For example I have the following Perl module
named
> test.pm in a modules directory:
>
> ######################
> package test_config;
>
> use strict;
> use vars qw($VERSION %test @test);
>
> require Exporter;
>
> # set the version for version checking
> $VERSION = 2.00;
>
> %test = ("key" => "value");
>
> @test = (1,2,3,4);
> ###########################
>
> If I run the following at a command prompt:
>
> perl -e '
> use modules::test;
> require "dumpvar.pl";
> dumpvar("test_config");'
>
> I get:
>
> @test = (
> )
> %test = (
> )
> $VERSION = 2
>
> I expected to get more, like the values of @test and %test. Please tell
me
> there is a better way.
>
Start by studying the documentation for the Exporter module.
'perldoc Exporter'
------------------------------
Date: Mon, 14 Apr 2003 01:01:45 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: What is wrong?
Message-Id: <slrnb9k23o.4ba.mgjv@verbruggen.comdyn.com.au>
On Sun, 13 Apr 2003 15:19:03 -0500,
Joe Creaney <mail@annuna.com> wrote:
> Here is a snippet of a program I am writing and trying to debug. It is
> a simple role-playing game. I am using objects and packages. Right now
> the compiler is giving my syntax errors in my package declaration
> statements as marked. I am very sure that they are not wrong but I
> would like some advice for finding where the errors relay are.
And why did you decide that it was not worth your trouble to cut and
paste the exact error message here?
Please read the posting guidelines for this group:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
> generate {
Did you mean
sub generate {
> my ($player, $mx, $my) = @_;
> my $v;
> my @mm;
> my $hp;
> my @num;
> my $lp = 0;
> my $rm;
> my $x;
Why don't you declare variables where you need them, instead of at the
top of your block?
You also have serious problems with your code formatting. Next time
you post, please make sure your code is at least readable to humans.
Also, make sure you always compile with warnings on. Perl will point
out problems that way that you can fix yourself instead of asking us
to do the compiler's job.
> # 0 name,1 Hit dice (Level),2 Hit Points,3 Max dammage,4 Armor Class,5
> Expewrience value
Syntax error.
> @mm = @ml[$rm];
What are you trying to do here?
@mm = ($ml[$rm]); # ?
> for ($x=0; $mm[1]; $x++) {
$mm[1] will not have any value, since you specifically assigned only
one value to @mm just before this loop.
> package Map; <-----Error
Syntax error. Unterminated <>
> #!/usr/bin/perl -w
Why is this line here? It's just a comment.
> new {
Did you mean
sub new {
?
> my @map1 = (
> [ qw (# # # # # # # # # # # # # # # # #)],
This gives loads and loads of (silly) warnings about attempting to put
comments in qw(). You don't have warnings on, do you? If you
temporarily want to switch them off here, use
no warnings;
in this block.
> my $map = {
> map => @map1
What is this supposed to do? Did you mean
map => [@map1],
or
map => \@map1,
> };
> bless $map;
You're using the one argument form of bless. This is not a good idea.
> package Main; <----Error
Syntax error. Unterminated <>
Did you mean main instead of Main anyway?
> #!/usr/bin/perl -w
useless line, again.
I think that the errors you're complaining about are to do with the
fact that you are trying to create subroutines, but are going about it
the wrong way.
Martien
--
|
Martien Verbruggen | Unix is user friendly. It's just selective
Trading Post Australia | about its friends.
|
------------------------------
Date: Mon, 14 Apr 2003 04:29:09 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: What is wrong?
Message-Id: <3e9a385b.384769761@news.erols.com>
Joe Creaney <mail@annuna.com> wrote:
: the compiler is giving my syntax errors in my package declaration
: statements as marked. I am very sure that they are not wrong but I
: would like some advice for finding where the errors relay are.
When it's not obvious, look at the statement immediately before the
line where perl says there is an error.
: generate {
[snip]
: }
sub generate { ... }
: package Map; <-----Error
: #!/usr/bin/perl -w
Another shebang? What for?
: new {
[snip]
: }
sub new { ... }
: package Main; <----Error
: #!/usr/bin/perl -w
And another shebang. Are you perhaps confused on what its purpose is?
------------------------------
Date: Sun, 13 Apr 2003 18:56:43 -0500
From: Joe Creaney <mail@annuna.com>
Subject: Why do I get an error
Message-Id: <3E99F93B.10000@annuna.com>
Joe Creaney wrote:
> Here is a snippet of a program I am writing and trying to debug. It is
> a simple role-playing game. I am using objects and packages. Right now
> the compiler is giving my syntax errors in my package declaration
> statements as marked. I am very sure that they are not wrong but I
> would like some advice for finding where the errors relay are.
>
>
>
>
> generate {
>
> my ($player, $mx, $my) = @_;
> my $v;
> my @mm;
> my $hp;
> my @num;
> my $lp = 0;
> my $rm;
> my $x;
>
> my @ml = (
> [ "Rat",1,0,2,9,10 ],
> [ "Kobold",1,0,4,9,10 ],
> [ "Orc",1,0,6,8,15 ],
> [ "Skelliton",1,0,4,9,10 ],
> [ "Gobblin",1,0,7,4,10 ],
> [ "Hobgobblin",2,0,6,6,15 ],
> [ "Wolf",2,0,6,5,20 ],
> [ "Ogre",3,0,7,5,25 ],
> [ "Troll",3,0,8,4,25 ],
> [ "Giant",3,0,3,4,8,30 ],
> [ "Dragon!",4,0,10,1,100 ],
> );
>
> # 0 name,1 Hit dice (Level),2 Hit Points,3 Max dammage,4 Armor Class,5
> Expewrience value
>
> $rm = int(rand(4)) + $player->{lv};
> if ($rm > 10 )
> {$rm = 10; }
>
> @mm = @ml[$rm];
>
> for ($x=0; $mm[1]; $x++) {
> $hp += int(rand(6))+1;
> }
>
> print "You see a $mm[0] \n";
>
> $mm[2] = $hp;
> while ($num[$lp]->name ne " "){
> if ($num[$lp]->{name} eq " ") {
> $num[$lp] = new (@mm, $mx, $my );
> $lp++;
> }
> }
> $v = $num[$lp];
> return $v, $player;
>
> }
>
> package Map; <-----Error
> #!/usr/bin/perl -w
>
>
> new {
> my @map1 = (
> [ qw (# # # # # # # # # # # # # # # # #)],
> [ qw (# . . . . # . . . . # . # # . # #)],
> [ qw (# # # # . # . # # . # . # . . . #)],
> [ qw (# . . . . . . . # . # . # . # . #)],
> [ qw (# . . # # . # # # . . . # . # . #)],
> [ qw (# . . # . . . # # . # . # . # # #)],
> [ qw (# # . # # # . . . . # . . . . . #)],
> [ qw (# # . . # . . # # # # # # # # . #)],
> [ qw (# # # # # # # # # # # # # # # X #)],
> );
> my $map = {
> map => @map1
> };
> bless $map;
> return $map;
> }
>
>
> package Main; <----Error
> #!/usr/bin/perl -w
> use strict;
>
> my $name;
>
------------------------------
Date: Mon, 14 Apr 2003 00:45:58 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Why do I get an error
Message-Id: <x7n0itewjd.fsf@mail.sysarch.com>
because you followed up your own post with no new content.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
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.
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 4841
***************************************