[19483] in Perl-Users-Digest
Perl-Users Digest, Issue: 1678 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 2 03:05:57 2001
Date: Sun, 2 Sep 2001 00:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <999414306-v10-i1678@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 2 Sep 2001 Volume: 10 Number: 1678
Today's topics:
array questions <kwokng@earthlink.net>
Re: array questions (E.Chang)
Godzilla DOS Environmental Variables Utility <godzilla@stomp.stomp.tokyo>
Re: Godzilla DOS Environmental Variables Utility (Tim Hammerquist)
Re: Godzilla DOS Environmental Variables Utility <godzilla@stomp.stomp.tokyo>
Re: Godzilla DOS Environmental Variables Utility (fvw)
How can I ... (Nkhouri)
Re: How can I ... (Martien Verbruggen)
POD2Doc? <dausha@visto.com>
Re: POD2Doc? <rob_13@excite.com>
Re: Setting DOS Variables (Was: Matt Wrights formmail a (timmy)
Re: Setting DOS Variables (Was: Matt Wrights formmail a <godzilla@stomp.stomp.tokyo>
Re: Simple RegExp Question <davidhilseenews@yahoo.com>
Re: Simple RegExp Question <davidhilseenews@yahoo.com>
Re: Simple RegExp Question (Sam)
Re: Simple RegExp Question <davidhilseenews@yahoo.com>
Re: Simple RegExp Question <krahnj@acm.org>
Re: Simple RegExp Question <godzilla@stomp.stomp.tokyo>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 02 Sep 2001 05:13:28 GMT
From: "Billy Ng" <kwokng@earthlink.net>
Subject: array questions
Message-Id: <Ydjk7.702$IP6.68371@newsread2.prod.itd.earthlink.net>
I have 2 questions regarding the array.
1) how can I put an array into an array? If I do push(@parent, @child), it
will add the @child's elements into @parent. But I each element in the
array is a individual array. Do I need the use hash instead?
2) how I pass the mixed type argurments in a subroutine? for example, I want
to call:
foo(@a, $i);
Thanks!
Billy
------------------------------
Date: Sun, 02 Sep 2001 05:35:21 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: array questions
Message-Id: <Xns911010F10B89Eechangnetstormnet@207.106.93.86>
"Billy Ng" <kwokng@earthlink.net> wrote in
<Ydjk7.702$IP6.68371@newsread2.prod.itd.earthlink.net>:
> I have 2 questions regarding the array.
>
> 1) how can I put an array into an array? If I do push(@parent,
> @child), it will add the @child's elements into @parent. But I
> each element in the array is a individual array. Do I need the use
> hash instead?
The elements of an array are always scalars. To create an "array of
arrays" you will need to use references to arrays as the elements
rather than the arrays themselves. Read the core documentation
sections perlreftut, perlref, and perllol. The documentation in
available with your Perl installation and also online at perldoc.com.
> 2) how I pass the mixed type argurments in a subroutine? for
> example, I want to call:
>
> foo(@a, $i);
Again, references provide a solution.
$aref = \@a;
and then
foo($aref, $i);
(or just foo(\@a, $i);)
In the subroutine code you would then use the reference to the array.
Because arguments to a function are flattened into a single list, in
the simple case with only one array you could just reverse the order of
the arguments and pick off the scalar from the argument list, but it's
not a general solution.
foo($i, @a)
...
sub foo {
($i2, @a2) = @_;
...}
--
EBC
------------------------------
Date: Sat, 01 Sep 2001 20:29:05 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Godzilla DOS Environmental Variables Utility
Message-Id: <3B91A780.4D20E931@stomp.stomp.tokyo>
For years it has been said it is impossible to set
parent DOS environmental variables via a Perl script.
This is no longer true.
After a month or more of researching this topic,
after testing many different methods, some successful,
some complete failures, I now have a method to easily
and efficiently set parent DOS environmental variables
thanks to Clay Ruth and a utility he wrote.
Extensive and exhaustive testing of various methods
reveals his simple binary executable is the best
choice for this task. His method is extremely fast.
This applies to Win9.x and Win.me systems.
I am making this utility written by Clay Ruth, an
associated readme.txt, which is attached with this
article, and a test script of my own, available as
a zip file, which is less than 12 kilobytes in size:
http://la.znet.com/~callgirl/perl-env.html
This inability to set sticky parent DOS environmental
variables is now an annoyance of the past.
Simply unzip and move envmastr.exe to the same directory
as your Perl script you are using to set DOS environmental
variables or, add a change directory command to my test
script enclosed in my zip file to observe how this works.
Piece of cake. Shirley you Perl 5 Cargo Cultists can figure this.
You are welcome.
Godzilla! Queen Of Perl Heretics.
--
ENVMASTR.EXE
------------
Copyright (C)1992-1999 by Clay Ruth
http://ww2.netnitco.net/users/cruth/claysutl.html
When you use the SET command while shelled out from an application, it sees
only the local environment of the shell. ENVMASTR lets you work in the
master environment that was created when the system was booted, and/or
any subordinate environments. This is especially useful when using RUNBAT$
to execute a batch whose environment manipulation is expected to stick to
the command environment from which RUNBAT$ was executed. The batch can
either make all environment changes through ENVMASTR, or make them locally
and then use ENVMASTR to copy the modified environment into the master.
A display-only option lets you view the content of any environment space,
complete with a report of the environment size, bytes used and bytes free.
Beginning with Version 3.0, ENVMASTR can display and edit environment blocks
in upper memory as well as conventional memory, and any instance of COMMAND
found in upper memory is promoted to "master" status (this ensures that the
master environment is properly identified when Windows 95 or later
high-loads COMMAND.COM).
Syntax: ENVMASTR [/d] [/c] [/n:progname] [/s] [/x] [/l] [varname=setting]
If no option switches are given, it applies varname=setting to the master
command environment only (i.e., the command processor loaded by CONFIG.SYS).
The option switches, which may be indicated by either a slash or a dash,
modify its operation as follows:
/d displays the environment(s) without changing anything (ignores varname).
/c copies the entire current local environment to target(s) (ignores varname).
/n names a specific target program's environment to be modified (any level).
/s targets all subordinate environments that have room.
/x excludes the master environment (implies /s).
/l allows lower-case characters in the variable name (default is forced CAPS).
Note: If the desired value begins with a space, enclose it in quotation marks.
For quotation marks within the setting, prefix each with a backslash.
The order of the option switches is not important, so long as all precede
the varname=setting (if any). The varname=setting is required except
when option /c or /d is used, in which case varname=setting is ignored.
The /c option should be used with caution, as you may be copying some
settings that you really don't want to have in the target environment,
especially when you use ENVMASTR from a DOS box under Windows. Windows
maintains some settings that should not be carried back to the master
environment from which Windows was launched. When this happens, the /l
option will allow you to get rid of the "windir" variable, which is in
lower case and cannot be removed by a SET command. When using /n to name
a specific target environment, the progname is typically the executable
file name without any extension.
For example, to change all COMMAND.COM environments regardless of how
many shell levels are present, without affecting any other programs,
use the following command, substituting your variable name and setting:
ENVMASTR /N:COMMAND varname=value
If you were copying the local command environment to all COMMAND.COM
shell levels, the command would be:
ENVMASTR /N:COMMAND /C
To copy the local environment to the master only, use ENVMASTR /C without
any /n specification.
To remove a variable name from the environment, use varname= (without a
setting), just as you do when using SET.
To view the usage of only the subordinate COMMAND.COM environment, without
seeing the master environment, use this command:
ENVMASTR /N:COMMAND /X /D
Note that this will show nothing if the current command environment IS the
master environment. To see only the master environment, just do this:
ENVMASTR /D
A list of target environments found, and the success or failure of the
requested setting in each, is sent to STDOUT for display or redirection.
It returns errorlevel 1 if a subordinate environment could not be changed,
and errorlevel 2 if the master environment could not be changed.
Errorlevel 3 indicates a syntax error (no setting attempted).
Errorlevel 1 or 2 occurs only in the event that the target environment
is too small to accommodate the requested change. There is no errorlevel
when a specified program environment is not present, nor when using /d.
ENVMASTR is very careful to ensure that the change can be accommodated
within the target environment. It also preserves command line argument
zero (i.e., the command line without parameters), which follows the
defined variables; this information is never copied from one environment
to another but is preserved in its original state. Argument zero will move
within its home environment, so that it always follows the variable list
in the correct relative position, and the change will be disallowed if
there is no room to append argument zero to the list.
------------------------------
Date: Sun, 02 Sep 2001 03:58:47 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: Godzilla DOS Environmental Variables Utility
Message-Id: <slrn9p3caa.7cb.tim@vegeta.ath.cx>
Me parece que Godzilla! <godzilla@stomp.stomp.tokyo> dijo:
> For years it has been said it is impossible to set
> parent DOS environmental variables via a Perl script.
_I_ never said it was impossible. The clpm concensus is that it's
impossible on Unix, but I was using a util in the MS-DOS 5.0
days that changed its parent's environment. It was either in a PC
Magazine collection, or on a disk from _The Software Labs_.
> This is no longer true.
Well, it was never true in the first place, was it?
[ snipped > 130 lines ]
--
Tools, of course, can be the subtlest of traps.
-- Daniel, The Sandman
------------------------------
Date: Sat, 01 Sep 2001 21:09:35 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Godzilla DOS Environmental Variables Utility
Message-Id: <3B91B0FF.AD2CCCFC@stomp.stomp.tokyo>
Tim Hammerquist aka The CLPM Troll wrote:
> Godzilla! wrote:
(snipped)
> > For years it has been said it is impossible to set
> > parent DOS environmental variables via a Perl script.
> _I_ never said it was impossible.
Hello! Are you wigging out? I did not say anything
about you nor even hint about you. I have no memory
of your even being involved in whatever discussion
you reference.
Normally I would surmise you are a paranoid speed freak.
However, I suspect you are an ordinary Window Wigger;
a person who runs to a window then peeks through closed
curtains at any hint of footsteps or a car passing by.
Relax kid, you are gonna blow a fifty amp fuse.
Godzilla!
------------------------------
Date: Sun, 02 Sep 2001 06:07:25 GMT
From: fvw+usenet@var.cx (fvw)
Subject: Re: Godzilla DOS Environmental Variables Utility
Message-Id: <999410848GAN.fvw@var.cx>
tim@vegeta.ath.cx (Tim Hammerquist) wrote:
>> it is impossible to set
>> parent DOS environmental variables via a Perl script.
>_I_ never said it was impossible. The clpm concensus is that it's
>impossible on Unix
Never say never, it's just tricky. But as long as you have ptrace or
/dev/mem (or even /proc/kmem) (and I'm sure other people can come up
with other even more fun solutions) it's doable.
--
Frank v Waveren Fingerprint: 0EDB 8787
fvw@[var.cx|dse.nl|stack.nl|chello.nl] ICQ#10074100 09B9 6EF5 6425 B855
Public key: http://www.var.cx/pubkey/fvw@var.cx-gpg 7179 3036 E136 B85D
------------------------------
Date: 1 Sep 2001 22:44:13 -0700
From: circuller@yahoo.com (Nkhouri)
Subject: How can I ...
Message-Id: <64ffc63e.0109012144.48a1e091@posting.google.com>
hello good ppl !
- how can i response back to client [ end-request ] explicitly while
keeping my cgi program contniues doing other stuff ?
- where i can find a good resource about memory management in perl ?
thx in advance .
------------------------------
Date: Sun, 2 Sep 2001 16:12:15 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: How can I ...
Message-Id: <slrn9p3jdv.3ga.mgjv@martien.heliotrope.home>
[
Subject: Re: How can I ...
Please, in the future, put a real subject in your subject line
]
On 1 Sep 2001 22:44:13 -0700,
Nkhouri <circuller@yahoo.com> wrote:
> hello good ppl !
>
> - how can i response back to client [ end-request ] explicitly while
> keeping my cgi program contniues doing other stuff ?
This question is asked quite regularly here, and the answer can easily
be found on groups.google.com.
You could fork a process and make sure that you close stdin and stdout
in the child, or something like that. Use google to find examples. I
believe the Perl Cookbook also has some info.
Also see perlipc, and fork() in perlop.
[Next time, please don't put two totally unrelated questions in one
post.]
> - where i can find a good resource about memory management in perl ?
Memory management in Perl is never necessary [1]. It does it all for
you. What specifically do you want to know?
Martien
[1] Not entirely strictly true, circular references can stop Perl's
automatic management.
--
Martien Verbruggen |
Interactive Media Division | Begin at the beginning and go on till
Commercial Dynamics Pty. Ltd. | you come to the end; then stop.
NSW, Australia |
------------------------------
Date: Sun, 02 Sep 2001 04:32:34 GMT
From: "Benjamin Wilson" <dausha@visto.com>
Subject: POD2Doc?
Message-Id: <CDik7.53577$hT4.13375667@news1.rdc1.md.home.com>
Hey! I'm wondering if there's a POD converter to an MS Word document.
Thanks in advance,
Ben
------------------------------
Date: Sun, 02 Sep 2001 06:43:41 GMT
From: "Rob - Rock13.com" <rob_13@excite.com>
Subject: Re: POD2Doc?
Message-Id: <Xns91101BBC7113Brock13com@64.8.1.227>
Benjamin Wilson
<news:CDik7.53577$hT4.13375667@news1.rdc1.md.home.com>:
> Hey! I'm wondering if there's a POD converter to an MS Word
> document.
Not that I know of, you might look at CPAN. There appears to be a
pod2rtf.
http://www.google.com/search?q=pod2rtf
I can't see the point in converting to a Word document--why create
something that bloated and proprietary out of something that is
simple.
--
Rob - http://rock13.com/
Web Stuff: http://rock13.com/webhelp/
------------------------------
Date: 1 Sep 2001 20:49:29 -0700
From: timmy@cpan.org (timmy)
Subject: Re: Setting DOS Variables (Was: Matt Wrights formmail alert)
Message-Id: <5c8bd0cc.0109011949.79f9d493@posting.google.com>
I was shocked that "Godzilla!" could write:
> I am a rogue programmer whom delights in the unusual.
I was simply surprised that Godzilla! would use such poor grammer
after insulting the hell out of all of us.
"I" (Godzilla!) is the subject.
"whom" modifies an _object_ of the sentence.
"am" is a form of the verb "to be", which takes no object.
It should've been "who."
------------------------------
Date: Sat, 01 Sep 2001 21:25:39 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Setting DOS Variables (Was: Matt Wrights formmail alert)
Message-Id: <3B91B4C3.74F2C38D@stomp.stomp.tokyo>
timmy aka The CLPM Troll idiotically blathered:
> I was shocked that "Godzilla!" could write:
"I am...."
Remove "that" from your sentence.
Remove your quote marks around a first person proper noun.
"I am shocked Godzilla! could write:"
> > I am a rogue programmer whom delights in the unusual.
> I was simply surprised that Godzilla! would use such poor grammer
> after insulting the hell out of all of us.
You are poorly skilled at temporal tense usage, clearly.
"I am simply..."
Typical of psuedo illiterates, you slaughter sentences
with this word "that."
It is spelled "grammar." G R A M M A R
Underscore each capitalize letter with your right
index fingertip. This will assist you greatly in
reading this word, "grammar."
"I am simply surprised Godzilla! would use such poor grammar."
Capitalize "Hell" as you would "Heaven."
I didn't insult you "after" the fact.
"...with her insulting the Hell out...."
My presumption is your brain is stuck on third person
past tense inactive. Hmm, inactive seems fitting for
your brain activity.
> "I" (Godzilla!) is the subject.
> "whom" modifies an _object_ of the sentence.
> "am" is a form of the verb "to be", which takes no object.
None of this is correct.
"...a rogue programmer...." is the subject.
Whom, although following, antecedent denotes
possession of an action by this programmer,
an action of delights.
Predicate Nominative and Copulative Verb
are your key words, although certainly
unknown new words to you, personally.
Research and read about correct usage of "whom."
You have only served to make a fool of yourself,
which is quite habitual for you.
> It should've been "who."
"It should be "who."
For a bozo such as yourself, it should read,
"Whose on first?"
Enroll in a Bonehead English class then return in
ten or so years. Your illiteracy is offensive.
Godzilla!
------------------------------
Date: Sun, 02 Sep 2001 02:40:27 GMT
From: "David Hilsee" <davidhilseenews@yahoo.com>
Subject: Re: Simple RegExp Question
Message-Id: <v_gk7.53142$hT4.13273240@news1.rdc1.md.home.com>
"Sam" <sam_5_5_5_0@REMOVEyahoo.com> wrote in message
news:sam_5_5_5_0-0109011943070001@dialup-721.deskmedia.com...
> I need a regular expression to help analize a file that contains
> statistics for game. The data contains a level name and a number, as
> follows (for example):
>
> Hawthorne 3 Zamboni
1
> Heimdall 1
>
> Note that there are two ways it could be on a line:
>
> -2 on a line
> -1 on a line
>
> Here's the script (part of it):
>
> while() {
> chomp($in = <>);
> if ($in =~ /<exp1>/) {
> $levels{$1}+=$2;
> $levels{$3}+=$3;
> } elsif ($in =~ /<exp2>/) {
> $levels{$1}+=$2;
> } elseif ($in =~ /^$/) {
> print "end of list";
> last;
> }
> }
>
> where <exp1> and <exp2> are the regular expressions. In the first, $1 and
> $3 are level names, and $2 and $4 are the numbers. In the second, $1 is
> the name and $2 is the number.
>
> Note that level names can contain pucuation, spaces, ect.
>
> Any help would be nice. Thanks.
>
> --
> Remove "REMOVE" for address to reply.
> I don't check that mailbox very often.
> Replies to the newsgroup are best.
The only thing I could gather from your description is that whitespace and
digits are the only ways to distinguish parts of the line. What I came up
with doesn't follow the same form as yours does, but I figure it might be
what you are looking for.
#!/usr/bin/perl -w
use strict;
my %levels;
while ( <DATA> )
{
# The first non-whitespace character starts the name.
# The name continues until a series of spaces followed by
# a series of digits is reached (the number)
my %temp_levels = /(\S.*?)\s+(\d+)/g;
while ( my ($k,$v) = each %temp_levels )
{
$levels{$k} += $v;
}
}
while ( my ($k,$v) = each %levels )
{
print "$k => $v\n";
}
__DATA__
Hawthorne 3 Zamboni
1
Heimdall 1
some stuff laksjdf 2 other things asdf 4
yea, that's it 42 once again 5
once again #2 98
once again 3
Heimdall 3
yea, that's it 54 other things asdf 32
David Hilsee
------------------------------
Date: Sun, 02 Sep 2001 02:45:44 GMT
From: "David Hilsee" <davidhilseenews@yahoo.com>
Subject: Re: Simple RegExp Question
Message-Id: <s3hk7.53182$hT4.13277823@news1.rdc1.md.home.com>
>
> __DATA__
> Hawthorne 3 Zamboni
> 1
Of course, this 1 should be on the same line as Zamboni.
David Hilsee
------------------------------
Date: Sat, 01 Sep 2001 21:58:32 -0500
From: sam_5_5_5_0@REMOVEyahoo.com (Sam)
Subject: Re: Simple RegExp Question
Message-Id: <sam_5_5_5_0-0109012158330001@dialup-740.deskmedia.com>
In article <v_gk7.53142$hT4.13273240@news1.rdc1.md.home.com>, "David
Hilsee" <davidhilseenews@yahoo.com> wrote:
> "Sam" <sam_5_5_5_0@REMOVEyahoo.com> wrote in message
> news:sam_5_5_5_0-0109011943070001@dialup-721.deskmedia.com...
> > I need a regular expression to help analize a file that contains
> > statistics for game. The data contains a level name and a number, as
> > follows (for example):
> >
> > Hawthorne 3 Zamboni
> 1
> > Heimdall 1
> >
> > Note that there are two ways it could be on a line:
> >
> > -2 on a line
> > -1 on a line
> >
> > Here's the script (part of it):
> >
> > while() {
> > chomp($in = <>);
> > if ($in =~ /<exp1>/) {
> > $levels{$1}+=$2;
> > $levels{$3}+=$3;
> > } elsif ($in =~ /<exp2>/) {
> > $levels{$1}+=$2;
> > } elseif ($in =~ /^$/) {
> > print "end of list";
> > last;
> > }
> > }
> >
> > where <exp1> and <exp2> are the regular expressions. In the first, $1 and
> > $3 are level names, and $2 and $4 are the numbers. In the second, $1 is
> > the name and $2 is the number.
> >
> > Note that level names can contain pucuation, spaces, ect.
> >
> > Any help would be nice. Thanks.
> >
> > --
> > Remove "REMOVE" for address to reply.
> > I don't check that mailbox very often.
> > Replies to the newsgroup are best.
>
> The only thing I could gather from your description is that whitespace and
> digits are the only ways to distinguish parts of the line. What I came up
> with doesn't follow the same form as yours does, but I figure it might be
> what you are looking for.
>
> #!/usr/bin/perl -w
> use strict;
>
> my %levels;
> while ( <DATA> )
> {
> # The first non-whitespace character starts the name.
> # The name continues until a series of spaces followed by
> # a series of digits is reached (the number)
> my %temp_levels = /(\S.*?)\s+(\d+)/g;
>
> while ( my ($k,$v) = each %temp_levels )
> {
> $levels{$k} += $v;
> }
> }
>
> while ( my ($k,$v) = each %levels )
> {
> print "$k => $v\n";
> }
>
> __DATA__
> Hawthorne 3 Zamboni
> 1
> Heimdall 1
> some stuff laksjdf 2 other things asdf 4
> yea, that's it 42 once again 5
> once again #2 98
> once again 3
> Heimdall 3
> yea, that's it 54 other things asdf 32
>
>
>
> David Hilsee
Oh, I forgot to mention that level names can have a space in them.
My idea involves searching for data that is NOT two spaces next to each
other (is that even possible?)
--
Remove "REMOVE" for address to reply.
I don't check that mailbox very often.
Replies to the newsgroup are best.
------------------------------
Date: Sun, 02 Sep 2001 03:04:34 GMT
From: "David Hilsee" <davidhilseenews@yahoo.com>
Subject: Re: Simple RegExp Question
Message-Id: <6lhk7.53267$hT4.13294054@news1.rdc1.md.home.com>
"Sam" <sam_5_5_5_0@REMOVEyahoo.com> wrote in message
news:sam_5_5_5_0-0109012158330001@dialup-740.deskmedia.com...
> In article <v_gk7.53142$hT4.13273240@news1.rdc1.md.home.com>, "David
> Hilsee" <davidhilseenews@yahoo.com> wrote:
>
> > "Sam" <sam_5_5_5_0@REMOVEyahoo.com> wrote in message
> > news:sam_5_5_5_0-0109011943070001@dialup-721.deskmedia.com...
> > > I need a regular expression to help analize a file that contains
> > > statistics for game. The data contains a level name and a number, as
> > > follows (for example):
> > >
> > > Hawthorne 3 Zamboni
> > 1
> > > Heimdall 1
> > >
> > > Note that there are two ways it could be on a line:
> > >
> > > -2 on a line
> > > -1 on a line
> > >
> > > Here's the script (part of it):
> > >
> > > while() {
> > > chomp($in = <>);
> > > if ($in =~ /<exp1>/) {
> > > $levels{$1}+=$2;
> > > $levels{$3}+=$3;
> > > } elsif ($in =~ /<exp2>/) {
> > > $levels{$1}+=$2;
> > > } elseif ($in =~ /^$/) {
> > > print "end of list";
> > > last;
> > > }
> > > }
> > >
> > > where <exp1> and <exp2> are the regular expressions. In the first, $1
and
> > > $3 are level names, and $2 and $4 are the numbers. In the second, $1
is
> > > the name and $2 is the number.
> > >
> > > Note that level names can contain pucuation, spaces, ect.
> > >
> > > Any help would be nice. Thanks.
> > >
> > > --
> > > Remove "REMOVE" for address to reply.
> > > I don't check that mailbox very often.
> > > Replies to the newsgroup are best.
> >
> > The only thing I could gather from your description is that whitespace
and
> > digits are the only ways to distinguish parts of the line. What I came
up
> > with doesn't follow the same form as yours does, but I figure it might
be
> > what you are looking for.
> >
> > #!/usr/bin/perl -w
> > use strict;
> >
> > my %levels;
> > while ( <DATA> )
> > {
> > # The first non-whitespace character starts the name.
> > # The name continues until a series of spaces followed by
> > # a series of digits is reached (the number)
> > my %temp_levels = /(\S.*?)\s+(\d+)/g;
> >
> > while ( my ($k,$v) = each %temp_levels )
> > {
> > $levels{$k} += $v;
> > }
> > }
> >
> > while ( my ($k,$v) = each %levels )
> > {
> > print "$k => $v\n";
> > }
> >
> > __DATA__
> > Hawthorne 3 Zamboni
> > 1
> > Heimdall 1
> > some stuff laksjdf 2 other things asdf 4
> > yea, that's it 42 once again 5
> > once again #2 98
> > once again 3
> > Heimdall 3
> > yea, that's it 54 other things asdf 32
> >
> >
> >
> > David Hilsee
>
> Oh, I forgot to mention that level names can have a space in them.
>
> My idea involves searching for data that is NOT two spaces next to each
> other (is that even possible?)
>
> --
> Remove "REMOVE" for address to reply.
> I don't check that mailbox very often.
> Replies to the newsgroup are best.
Did you even run what I wrote? Spaces are covered. You mentioned them in
your original post.
David Hilsee
------------------------------
Date: Sun, 02 Sep 2001 03:02:53 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Simple RegExp Question
Message-Id: <3B91A1C5.E74ABA50@acm.org>
Sam wrote:
>
> I need a regular expression to help analize a file that contains
> statistics for game. The data contains a level name and a number, as
> follows (for example):
>
> Hawthorne 3 Zamboni 1
> Heimdall 1
It looks like these are fixed length records of 36 characters so I am
going to assume so.
> Note that there are two ways it could be on a line:
>
> -2 on a line
> -1 on a line
>
> Here's the script (part of it):
>
> [snip]
>
> Note that level names can contain pucuation, spaces, ect.
>
> Any help would be nice. Thanks.
#!/usr/bin/perl -w
use strict;
my %levels;
while ( <DATA> ) {
for ( /(?:^|\s)(\S.{35})(?:$|\s)/g ) {
/^(.+\S)\s+(\d+)$/ and $levels{ $1 } += $2;
}
}
for ( keys %levels ) {
print "$_: $levels{$_}\n";
}
__DATA__
Hawthorne 3
Zamboni 1
Heimdall 1
This is, a test. 1 test 2 3 4 5 473 This is, a test. 1 test 2 3 4
5 527
Heimdall 1
Hawthorne 3
Zamboni 1
Heimdall 1
$ sam.pl
Hawthorne: 6
Heimdall: 3
This is, a test. 1 test 2 3 4 5: 1000
Zamboni: 2
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 01 Sep 2001 20:46:20 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Simple RegExp Question
Message-Id: <3B91AB8C.ECAC7ED6@stomp.stomp.tokyo>
Sam wrote:
(snipped)
> I need a regular expression to help analize a file that contains
> statistics for game. The data contains a level name and a number, as
> follows (for example):
> Hawthorne 3 Zamboni 1
> Heimdall 1
Rather than provide code examples, which others have
done quite well, I will make a sincere suggestion.
My suggestion is your data base is an absolute mess
leading to a requirement to write code is extremely
inefficient and equally slow, for both writing and
reading your data base.
Godzilla Rocks!:10
Hawthorne:3
Heimdall:1
The Troll:0
Zamboni:1
Above is an example of a highly logical database which
will allow writing of exceptionally fast and efficient
code for both writing and reading your data base.
With this type of logical and well planned data base,
Perl code only needs to split each read line into two
variables for manipulation. For a small data base, you
can slurp it and array sort by alphabetical order for
a nice neat data base.
Give what I have said this some thought. There is no
doubt dismissing typical Perl 5 Cargo Cult methods
and adopting old fashion Perl methods, a Perl program
written for a logical data base such as I display,
will be short, quick and very efficient; it will run
circles around this method you currently use.
Godzilla!
------------------------------
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 1678
***************************************