[22749] in Perl-Users-Digest
Perl-Users Digest, Issue: 4970 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 10 21:05:42 2003
Date: Sat, 10 May 2003 18: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)
Perl-Users Digest Sat, 10 May 2003 Volume: 10 Number: 4970
Today's topics:
Re: alarm and readline (A Perl 5.8.0 bug or a feature?) <nospam-abuse@ilyaz.org>
Re: ignore first line of input file <abigail@abigail.nl>
Re: Logic(al nightmare!) (Tad McClellan)
Re: Logic(al nightmare!) (Tad McClellan)
Re: Logic(al nightmare!) <usenet@dwall.fastmail.fm>
Re: More on flock().... <urael@zrgebcbyvf.arg.nh>
Re: More on flock().... <abigail@abigail.nl>
Need (script based?) Management Program or Pointer (Dave)
Re: Need (script based?) Management Program or Pointer (Tad McClellan)
Re: perl -pe "s/<er>/<er>\n"/g": memory efficient versi (Michael Wang)
Powerful One-liner (Caj Zell)
Re: Powerful One-liner <dmcbride@naboo.to.org.no.spam.for.me>
Re: Powerful One-liner <abuse@mweb.co.za>
Re: Powerful One-liner <News@LearnQuick.Com>
Re: Powerful One-liner <krahnj@acm.org>
Re: regex to extract number <mbudash@sonic.net>
Re: RegExp Question <abigail@abigail.nl>
Re: Splitting, Sorting, then Rebuilding an Array <sammie@greatergreen.com>
Re: Splitting, Sorting, then Rebuilding an Array <sammie@greatergreen.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 10 May 2003 19:45:48 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: alarm and readline (A Perl 5.8.0 bug or a feature?)
Message-Id: <b9jktc$t3r$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Jiri
<spambox@centrum.cz>], who wrote in article <b9j3q6$jl2eh$1@ID-134981.news.dfncis.de>:
> Right, let me try to answer the question myself, as it my help other
> people with a similar problem. The problem really seems to be with Perl
> 5.8.0. In Perl 5.6.1, the tick subroutine in the code
> $SIG{ALRM} = "tick";
> alarm(1);
>
> sub tick {
> print "tick\n";
> alarm(1);
> }
>
>
> while ( defined ($_ = $term->readline($prompt)) ) {
[....]
> gets called every second, even though Perl is waiting for an input line.
> For some reason, the alarm function is not executed in Perl 5.8.0 (at
> least on Slackware Linux 8.1--9.0).
How do you know? In your code there is no check for whether it was
called. At least set $|.
The difference may be that PerlIO does not try to emulate
line-buffering on TTYs... (Does it?)
Ilya
------------------------------
Date: 10 May 2003 23:47:16 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: ignore first line of input file
Message-Id: <slrnbbr3s3.2vd.abigail@alexandra.abigail.nl>
John W. Krahn (krahnj@acm.org) wrote on MMMDXXXVIII September MCMXCIII in
<URL:news:3EBBEE63.D998728@acm.org>:
&& kderaedt wrote:
&& >
&& > This is probably a dummy question. What is the easiest way to ignore
&& > the first line of a input file.
&&
&& Probably the easiest way is to test the input line number variable.
&&
&& > Used code:
&& > # Global configuration parameters
&& > my $INPUTFILE = "wsp.out";
&& > my $OUTPUTFILE = "wsp.new";
&& > my $MSISDN_START = 2;
&& >
&& > # File handeling
&& > open (IN, "< $INPUTFILE") or die "Couldn't open $INPUTFILE for reading:
&& > $!\n";
&& > open (OUT, "> $OUTPUTFILE") or die "Couldn't open $OUTPUTFILE for writing:
&& > $!\n";
&& >
&& > while(<IN>) {
&&
&& next if $. == 1;
&&
&& > }
The disadvantage is that you are doing work for each line you see,
even after you skipped the first one. I prefer to write:
$_ = <IN>;
while (<IN>) {
...
}
Abigail
--
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'
------------------------------
Date: Sat, 10 May 2003 09:27:06 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Logic(al nightmare!)
Message-Id: <slrnbbq31q.4j6.tadmc@magna.augustmail.com>
Brad Walton <sammie@greatergreen.com> wrote:
>
> What is top-post?
http://www.catb.org/~esr/jargon/html/entry/top-post.html
> "Tad McClellan" <tadmc@augustmail.com> wrote in message
> news:slrnbbn5b6.2d4.tadmc@magna.augustmail.com...
>> Brad Walton <sammie@greatergreen.com> wrote:
>>
>>
>> Please do not top-post.
>> > Yeah, I know the variable for the DB is looong,
>>
>> I did not say anything about long variables...
I'm guessing that you read news using a proportional font.
That will mess up "underlining", so you should use a fixed-width
font in your newsreader.
I did not underline a variable, I underlined this part:
or "
...
>> > tie @DB, 'Tie::File', $dormantstatdb or "cannot open $dormantstatdb: $!
>>
>>
>> > if you see anything wrong there let me know.
... because it probably should have been this instead:
or die "
>> There is a bug in the code quoted above.
>>
>> You should always enable warnings when developing Perl code,
>> it would have pointed out that bug for you...
And Perl would have told you about this mistake if you had asked
it to tell you about common mistakes (by enabling warnings).
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 10 May 2003 09:58:08 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Logic(al nightmare!)
Message-Id: <slrnbbq4s0.4j6.tadmc@magna.augustmail.com>
[ TOFU repaired ]
Brad Walton <sammie@greatergreen.com> wrote:
> "Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message
> news:Xns93763C421DF76sdn.comcast@216.166.71.239...
>> "Brad Walton" <sammie@greatergreen.com> wrote in
>> news:jeHua.541841$Zo.115854@sccrnsc03:
>> > tie @DB, 'Tie::File', $dormantstatdb or "cannot open
>> $dormantstatdb:
>> > $!
You might consider either configuring your news reader to NOT wrap
lines, or write your code so that line wrapping does not occur.
It is hard to read code when your newsreader has garbled it for you.
tie @DB, 'Tie::File', $dormantstatdb or
die "cannot open $dormantstatdb: $!";
>> Tad was referring to the fact that the
>> right-side of your "or" expression is ... just a string. Perhaps you
>> meant to "die" there?
> Ahh... no I took out the die on purpose.
You inserted a bug when you did so.
The usual approach to writing code is to *remove* bugs rather
than insert them. <grin>
> I will try the strict method and
> see what happens.
Most excellent!
The effort spent on making your code "strict clean" will be repaid
many times over by catching common mistakes for you.
> I am confused about setting flags.
There is no "setting of flags" anywhere in this thread that I've seen.
So now I am confused also. :-)
> I run on a Windows
> platform, and the normal flag procedures I see in the numerous Perl books
> that I own do not cover Windows method of flags. I am also using the
> ActiveState build of Perl.
"calling a function" is not the same as "setting a flag".
I think you are speaking of calling the die() function?
If so, your platform does not make any difference, die() works
on silly OSes too.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 10 May 2003 16:56:17 GMT
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Logic(al nightmare!)
Message-Id: <Xns9377839BBC011dkwwashere@204.127.199.17>
"Brad Walton" <sammie@greatergreen.com> wrote:
> I do have a follow-up question: Some of those variables do work in
> other subroutines, and while it was not intentional, having them
> global made passing them from subroutines very easy.
Undoubtedly. But once a program starts getting larger, it gets harder
and hard to keep track of global variables and they can introduce hard-
to-find bugs.
> Is there a way to pass a: my ($variable or @array) beyond its
> subroutine? Will: return($variable or @array); work?
> And does that in turn need to be passed to the next subroutine with:
> &sub_routine($variable or @array)?
Yes, use return() to return values from a subroutine. The gory details
are documented in perlsub. See 'perldoc perlsub'.
Passing arrays is slightly more complicated, because the incoming (and
outgoing) parameter list is flattened. Rather than try to explain it
all here (I don't want to type that much, and I'd probably oversimplify
something), I'll just refer you to perlsub.
I don't mean to suggest that global variables are *always* bad and
should not be used. Configuration values are often stored in global
variables, for example. I'll defer to others with more knowledge and
experience for further examples of when and why global variables are
useful.
--
David Wall - usenet@dwall.fastmail.fm
"Oook."
------------------------------
Date: Sun, 11 May 2003 01:38:52 +0930
From: Henry <urael@zrgebcbyvf.arg.nh>
Subject: Re: More on flock()....
Message-Id: <urael-AE95C0.01385011052003@nswpull.telstra.net>
In article <slrnbbm8vv.1mh.tadmc@magna.augustmail.com>,
tadmc@augustmail.com (Tad McClellan) wrote:
> >> open F, "+<", "file" or die $!;
> >> if (flock F, LOCK_EX|LOCK_NB) {
> >> # got the lock so write into file
...
>> with writes going to the end of the file?
>
> No. Writes go wherever the handle's file pointer is pointing to.
Hmmm... Then what is the following from the "open" entry in perlfunc
all about?
> You can put a '+' in front of the '>' or '<' to indicate that you want both
> read and write access to the file; thus '+<' is almost always preferred for
> read/write updates--the '+>' mode would clobber the file first. You can't
> usually use either read-write mode for updating textfiles, since they have
> variable length records.
Are writes _inserted_ at the current pointer position, or do they
_overwrite_ the contents (starting) at the current pointer position?
Henry.
------------------------------
Date: 10 May 2003 23:50:18 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: More on flock()....
Message-Id: <slrnbbr41q.2vd.abigail@alexandra.abigail.nl>
Henry (urael@zrgebcbyvf.arg.nh) wrote on MMMDXXXIX September MCMXCIII in
<URL:news:urael-AE95C0.01385011052003@nswpull.telstra.net>:
||
|| Are writes _inserted_ at the current pointer position, or do they
|| _overwrite_ the contents (starting) at the current pointer position?
They are overwritten. Files are just a stream of bytes in the file
system, and disks are rigid structures. You can't easily insert something
in a file.
Abigail
--
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'
------------------------------
Date: 10 May 2003 08:08:00 -0700
From: millhouse@mountaincable.net (Dave)
Subject: Need (script based?) Management Program or Pointer
Message-Id: <cc2d0fc3.0305100708.4cdcc098@posting.google.com>
Hi everyone. I need a download manager for my web. I'm not very
script-savvy, so I'm guessing I need a Perl scripted program (web
server is Unix based)that does the following: customer clicks link on
web page, email is generated with a passkey(unique)and page link.
Customer clicks link in email, supplies passkey to page form and their
customer ID; they get to download once. This passkey must no longer
work and program should store customer ID. Program should be
automated...I don't want to have to approve or disable accounts.
Please don't recommend Siteinteractive Download Manager. I have
reviewed this and sent them email with questions and am waiting reply.
Also, no need to recommend D Master from imchat.com. It's easy to
generate multiple passkeys with that one (at least it is with the
demo). I'm hoping someone out there can recommend another program or
build one for me. Or, if this is not the proper group to post to,
please advise where I should be asking.
Thanks, Dave
------------------------------
Date: Sat, 10 May 2003 10:18:13 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Need (script based?) Management Program or Pointer
Message-Id: <slrnbbq61l.4kr.tadmc@magna.augustmail.com>
Dave <millhouse@mountaincable.net> wrote:
> I need a download manager for my web. I'm not very
> script-savvy, so I'm guessing I need a Perl scripted program
> I'm hoping someone out there can recommend another program or
> build one for me. Or, if this is not the proper group to post to,
^^^^^^^^^^^^^^^^
> please advise where I should be asking.
^^^^^^^^^^^^^^^^^^^^^^^^
http://jobs.perl.org/ or any newsgroup with "jobs" in its name.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 10 May 2003 19:24:11 GMT
From: mwang@unixlabplus.com (Michael Wang)
Subject: Re: perl -pe "s/<er>/<er>\n"/g": memory efficient version?
Message-Id: <vlcva.386$vx2.42656@news.uswest.net>
In article <3ebcb5c6$0$14317$7a628cd7@news.club-internet.fr>,
Laurent Vogel <lvl@club-internet.fr> wrote:
>
>"Michael Wang" <mwang@unixlabplus.com> a écrit dans le message de news:
>zQ%ua.194$yr1.73745@news.uswest.net...
>> I have a file which has 1 super long line that contains
>>
>> some thing<er>something else<er>and more stuff<er>...
>>
>> perl -pe "s/<er>/<er>\n"/g"
>>
>> works for small files, but for large files, it runs out of
>> memory.
>>
>> Any solution using standard Unix utility is welcome.
>
>use tr to replace any > by a newline, then post-process with sed.
I have ">" in between <er>'s.
--
Michael Wang * http://www.unixlabplus.com/ * mwang@unixlabplus.com
------------------------------
Date: 10 May 2003 08:33:43 -0700
From: cajzell@hotmail.com (Caj Zell)
Subject: Powerful One-liner
Message-Id: <c9eae90e.0305100733.130b6f94@posting.google.com>
Hello!
I had an argument with my co-workers over Perl vs. C. It originated in
a colleague wanting to have a file with an arbitrary number of binary
'0':s in it and I wrote something like,
perl -e 'open FILE,">zeroes";$a=pack("C",0);foreach $i (0..100){print
FILE $a}'
After that, another colleague expressed his opinion along the lines of
"that's just as easy in C" (the idea incorporated pipeing command line
code to gcc, execute it, etc.) and an infected argument followed. My
questions now are
1. Is it possible to make the above much more concise? (I won't be
surprised I tell you, since I consider myself a poor, but
enthusiastic, perl adept.)
2. What is the most powerful, show-off, argument-breaking one-liner
that would require a lot more typing in "C"?
Caj Zell
------------------------------
Date: Sat, 10 May 2003 16:16:39 GMT
From: Darin McBride <dmcbride@naboo.to.org.no.spam.for.me>
Subject: Re: Powerful One-liner
Message-Id: <HB9va.145492$ya.4439625@news1.calgary.shaw.ca>
Caj Zell wrote:
> Hello!
>
> I had an argument with my co-workers over Perl vs. C. It originated in
> a colleague wanting to have a file with an arbitrary number of binary
> '0':s in it and I wrote something like,
>
> perl -e 'open FILE,">zeroes";$a=pack("C",0);foreach $i (0..100){print
> FILE $a}'
perl -e 'print "\0" x 100' > zeroes
> After that, another colleague expressed his opinion along the lines of
> "that's just as easy in C" (the idea incorporated pipeing command line
> code to gcc, execute it, etc.) and an infected argument followed. My
> questions now are
>
> 1. Is it possible to make the above much more concise? (I won't be
> surprised I tell you, since I consider myself a poor, but
> enthusiastic, perl adept.)
Yes. :-)
> 2. What is the most powerful, show-off, argument-breaking one-liner
> that would require a lot more typing in "C"?
perl -MCPAN -e shell
One of the most wonderful things about perl is that large amounts of your
work is probably already done for you. Just install it and go :-)
------------------------------
Date: Sat, 10 May 2003 20:06:15 +0200
From: "Nico Coetzee" <abuse@mweb.co.za>
Subject: Re: Powerful One-liner
Message-Id: <pan.2003.05.10.18.06.11.204740@mweb.co.za>
Here is a couple of solutions for nr. 2 of your question:
a) Who is defined as normal users ( uid > 500 ) on the system (unix).
Parse the output of the cat command:
cat /etc/passwd | perl -e 'while(<>){ /^(\w+):x:(\d+):/; if ( $2 > 500 ) { print "$1\n"; }}'
b) Print the environment variables:
perl -e 'foreach $key ( keys %ENV ) { print "$key=$ENV{$key}\n"; }'
c) Print number of empty lines in a text file:
cat program.pl | perl -e '$c=0;while((<>)&&(<>!=~/^\W$/)){$c++;}print "$c\n";'
d) How many lines in a text file contains the TAB character:
cat parser.pl | perl -e '$c=0;while(<>){ if ( /\t/ ) {$c++;}}print "$c\n";'
All of the above have been tested on Mandrake Linux 9.1
Cheers
PS: Some of the above can actually also be done with gawk(1).
On Sat, 10 May 2003 08:33:43 -0700, Caj Zell wrote:
> Hello!
>
> I had an argument with my co-workers over Perl vs. C. It originated in
> a colleague wanting to have a file with an arbitrary number of binary
> '0':s in it and I wrote something like,
>
> perl -e 'open FILE,">zeroes";$a=pack("C",0);foreach $i (0..100){print
> FILE $a}'
>
> After that, another colleague expressed his opinion along the lines of
> "that's just as easy in C" (the idea incorporated pipeing command line
> code to gcc, execute it, etc.) and an infected argument followed. My
> questions now are
>
> 1. Is it possible to make the above much more concise? (I won't be
> surprised I tell you, since I consider myself a poor, but
> enthusiastic, perl adept.)
>
> 2. What is the most powerful, show-off, argument-breaking one-liner
> that would require a lot more typing in "C"?
>
>
> Caj Zell
--
Nico Coetzee
http://www.itfirms.co.za/
http://za.pm.org/
http://forums.databasejournal.com/
To the systems programmer, users and applications serve only to provide a
test load.
------------------------------
Date: Sat, 10 May 2003 21:09:22 GMT
From: "Herb Martin" <News@LearnQuick.Com>
Subject: Re: Powerful One-liner
Message-Id: <6Udva.63334$8e7.3016816@twister.austin.rr.com>
I sort of like this one line batch file (mine runs on Win2000):
perl -MLWP::Simple -e "getprint qw(%1);"
(It's only a batch file so that you can retrieve ANY reasonable
web page this way. )
So you can always just type a page URL in place of %1 manually.
Herb Martin
Try ADDS for great Weather too:
http://adds.aviationweather.noaa.gov/projects/adds
------------------------------
Date: Sat, 10 May 2003 21:48:56 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Powerful One-liner
Message-Id: <3EBD739F.3D0B36F6@acm.org>
Nico Coetzee wrote:
>
> Here is a couple of solutions for nr. 2 of your question:
>
> a) Who is defined as normal users ( uid > 500 ) on the system (unix).
> Parse the output of the cat command:
>
> cat /etc/passwd | perl -e 'while(<>){ /^(\w+):x:(\d+):/; if ( $2 > 500 ) { print "$1\n"; }}'
UUOC. In fact you can use Perl's built-in getpw* functions.
perl -le'$a[2] > 500 and print $a[2] while @a = getpwent'
> b) Print the environment variables:
>
> perl -e 'foreach $key ( keys %ENV ) { print "$key=$ENV{$key}\n"; }'
man env
> c) Print number of empty lines in a text file:
>
> cat program.pl | perl -e '$c=0;while((<>)&&(<>!=~/^\W$/)){$c++;}print "$c\n";'
UUOC. It also doesn't count empty lines correctly. You do realise that
the expression (<>!=~/^\W$/) evaluates to ( <> != ~ /^\W$/ )? You do
realise that (<>)&&(<> reads two lines every time through the loop?
perl -lne'$c += /^\s*$/}{print $c' program.pl
> d) How many lines in a text file contains the TAB character:
>
> cat parser.pl | perl -e '$c=0;while(<>){ if ( /\t/ ) {$c++;}}print "$c\n";'
UUOC.
perl -lne'$c += /\t/}{print $c' parser.pl
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 10 May 2003 21:49:04 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: regex to extract number
Message-Id: <mbudash-2A9DEE.14490410052003@typhoon.sonic.net>
In article <MPG.19256511fad37eb39897c3@news.mts.net>,
Barry Kimelman <barryk2@SPAM-KILLER.mts.net> wrote:
> [This followup was posted to comp.lang.perl.misc]
>
> In article <1052431740.161075@minime.linuxiceberg.com>, Chris Fowler
> (cfowler@linuxiceberg.com) says...
> > Maybe someone can help me here. I have the following line I'm receving by
> > a
> > remote syslog server
> >
> >
> > <38>login[72]: login exiting
> >
> > I want to break it into 2 parts.
> >
> > 1) The numbe part.
> > 2) The message after '>'
> >
> > Can someone give me a regex that will extract that info?
> >
> > Thanks,
> > Chris
> >
>
> $buffer = "<38>login[72]: login exiting";
>
> $buffer =~ m/^(<\d+>)(.*)$/;
>
> $first_part = $1;
> $message = $2;
better written as:
if ($buffer =~ m/^(<\d+>)(.*)$/) {
$first_part = $1;
$message = $2;
}
else {
# didn't match!
}
--
Michael Budash
------------------------------
Date: 10 May 2003 23:58:47 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: RegExp Question
Message-Id: <slrnbbr4hm.2vd.abigail@alexandra.abigail.nl>
Gunnar Hjalmarsson (noreply@gunnar.cc) wrote on MMMDXXXVIII September
MCMXCIII in <URL:news:b9ha1b$jh628$1@ID-184292.news.dfncis.de>:
:: Anthony Saffer wrote:
:: > Let's say I have an entry in a log file like this:
:: >
:: > 1/13/03 "Joe Somebody"<joe@somewhere.com>
:: >
:: > How would I extract ONLY the email address from this line?
::
:: $line = '1/13/03 "Joe Somebody"<joe@somewhere.com>';
:: ($address) = $line =~ /<([^>]+)>/;
Well 'joe@somewhere.com' is just one of several "email addresses"
found in the string '1/13/03 "Joe Somebody"<joe@somewhere.com>'.
'"Joe Somebody"<joe@somewhere.com>' is another, and so is 'e@som'.
Abigail
--
map{${+chr}=chr}map{$_=>$_^ord$"}$=+$]..3*$=/2;
print "$J$u$s$t $a$n$o$t$h$e$r $P$e$r$l $H$a$c$k$e$r\n";
------------------------------
Date: Sat, 10 May 2003 21:59:24 GMT
From: "Brad Walton" <sammie@greatergreen.com>
Subject: Re: Splitting, Sorting, then Rebuilding an Array
Message-Id: <0Deva.798010$3D1.445957@sccrnsc01>
> s/^(.*?\t)(.*?\t)/$1\U$2/ for @formateddata = @archivedata;
This worked great. I am going to have to study it to understand the logic :)
Thanks! I understand what you were implying and will be able to simplify
many processes. I do have on other process that is a little different:
sub update_player_archive {
#Grab session variables
my
($sess,$cals,$plid,$mapid,$tcur,$tcon,$scor,$stat,$eak,$esak,$etk,$eck,$eatk
,$eaaak,$ewk,$esp,$fak,
$fsak,$ftk,$fck,$fatk,$faaak,$fwg,$fsp,$fb,$hb,$hab,$fr,$hr,$fbmb,$hbmb,$ipa
d,$ctry) = split /\t/, $adddata;
my
($osess,$ocals,$oplid,$omapid,$otcur,$otcon,$oscor,$ostat,$oeak,$oesak,$oetk
,$oeck,$oeatk,$oeaaak,
$oewk,$oesp,$ofak,$ofsak,$oftk,$ofck,$ofatk,$ofaaak,$ofwg,$ofsp,$ofb,$ohb,$o
hab,$ofr,$ohr,$ofbmb,
$ohbmb,$oipad,$octry) = split /\t/, $updatedata;
#Increment archive data with new data
my $nsess = $sess;
my $ncals = $ocals;
my $nplid = $plid;
my $nmapid = $mapid;
my $ntcur = $tcur;
my $ntcon = $tcon;
my $nscor = ($oscor + $scor);
my $nstat = $stat;
my $neak = ($oeak + $eak);
my $nesak = ($oesak + $esak);
my $netk = ($oetk + $etk);
my $neck = ($oeck + $eck);
my $neatk = ($oeatk + $eatk);
my $neaaak = ($oeaaak + $eaaak);
my $newk = ($oewk + $ewk);
my $nesp = ($oesp + $esp);
my $nfak = ($ofak + $fak);
my $nfsak = ($ofsak + $fsak);
my $nftk = ($oftk + $ftk);
my $nfck = ($ofck + $fck);
my $nfatk = ($ofatk + $fatk);
my $nfaaak = ($ofaaak + $faaak);
my $nfwg = ($ofwg + $fwg);
my $nfsp = ($ofsp + $fsp);
my $nfb = ($ofb + $fb);
my $nhb = ($ohb + $hb);
my $nhab = ($ohab + $hab);
my $nfr = ($ofr + $fr);
my $nhr = ($ohr + $hr);
my $nfbmb = ($ofbmb + $fbmb);
my $nhbmb = ($ohbmb + $hbmb);
unless (!$ipad) {
my $nipad = $ipad;
}
else {
my $nipad = $oipad;
}
unless (!$ctry) {
my $nctry = $ctry;
}
else {
my $nctry = $ctry;
}
#Put new variables back into one variable
my ($nipad,$nctry);
$updatearchive =
"$nsess\t$ncals\t$nplid\t$nmapid\t$ntcur\t$ntcon\t$nscor\t$nstat\t$neak\t$ne
sak\t$netk\t$neck\t$neatk\t$neaaak\t$newk\t$nesp\t$nfak\t$nfsak\t$nftk\t$nfc
k\t$nfatk\t$nfaaak\t$nfwg\t$nfsp\t$nfb\t$nhb\t$nhab\t$nfr\t$nhr\t$nfbmb\t$nh
bmb\t$nipad\t$nctry";
return ($updatearchive);
}
$updatearchive is a global variable which goes back to the database
subroutine. However, this is quite long, and probably could be written much
easier?
Thanks,
Brad
------------------------------
Date: Sun, 11 May 2003 00:34:38 GMT
From: "Brad Walton" <sammie@greatergreen.com>
Subject: Re: Splitting, Sorting, then Rebuilding an Array
Message-Id: <yUgva.804201$L1.229464@sccrnsc02>
> $updatearchive is a global variable which goes back to the database
> subroutine. However, this is quite long, and probably could be written
much
> easier?
I condensed to:
sub update_player_archive {
#Grab session variables
my @newsession;
my @currentsess = split /\t/, $adddata;
my @oldsess = split /\t/, $updatedata;
#Increment archive data with new data
@newsess[0] = @currentsess[0];
@newsess[1] = @oldsess[1];
@newsess[2] = @currentsess[2];
@newsess[3] = @currentsess[3];
@newsess[4] = @currentsess[4];
@newsess[5] = @currentsess[5];
@newsess[6] = (@oldsess[6] + @currentsess[6]);
@newsess[7] = @currentsess[7];
for ($n = 8; $n < 32; $n++) {
@newsess[$n] = (@oldsess[$n] + @currentsess[$n]);
}
for ($n = 32; $n < 34; $n++) {
unless (!@currentsess[$n]) {
@newsess[$n] = @currentsess[$n];
}
else {
@newsess[$n] = @oldsess[$n];
}
#Format info for return to archive
#?? $updatearchive = (\t,@newsess);
return;
}
Still not sure how to make $updatearchive = @newsess with tabs in betweeen
each variable...
Brad
------------------------------
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 4970
***************************************