[13648] in Perl-Users-Digest
Perl-Users Digest, Issue: 1058 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 15 14:16:34 1999
Date: Fri, 15 Oct 1999 11:16:22 -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: <940011381-v9-i1058@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 15 Oct 1999 Volume: 9 Number: 1058
Today's topics:
Disable output buffering rancorr@hotmail.com
Re: Disable output buffering (Andrew Johnson)
Re: Disable output buffering (Brett W. McCoy)
Displaying 2 digits in time (Russell Parker)
Re: Displaying 2 digits in time (Michael Budash)
Re: Displaying 2 digits in time c_j_marshall@my-deja.com
Re: Displaying 2 digits in time <NukeEmUp@ThePentagon.com>
Re: Displaying 2 digits in time <gellyfish@gellyfish.com>
Re: Displaying 2 digits in time (Abigail)
Re: Do you now an affordable Perl editor for Windows NT <et@telus.net>
Does perlcc work on windows NT? bradley_dc_smith@my-deja.com
Re: Does perlcc work on windows NT? vishalb@my-deja.com
Re: Dos commands in Perl??????????? (Ilya Zakharevich)
Re: Dos commands in Perl??????????? (Bart Lateur)
Re: Dos commands in Perl??????????? (Ilya Zakharevich)
Re: Dos commands in Perl??????????? <jeff@vpservices.com>
Re: Dos commands in Perl??????????? (Bart Lateur)
encoded CGI data <ccarr@websocket.com>
Re: encoded CGI data (Michael Budash)
Re: encoded CGI data (Michael Budash)
Re: File upload problem <pj7066@my-deja.com>
Finding the largest numbers in an array? ()
Re: Finding the largest numbers in an array? (Abigail)
Re: Finding the largest numbers in an array? (Greg Bacon)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 15 Oct 1999 03:01:00 GMT
From: rancorr@hotmail.com
Subject: Disable output buffering
Message-Id: <7u65d7$nbt$1@nnrp1.deja.com>
I saw on the web the following example in a Perl script:
$| = 1;
It's supposed to disable output buffering. What is output buffering,
and why would I want to disable it?
Please respond to rancorr@hotmail.com.
Thanks!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 15 Oct 1999 03:16:54 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: Disable output buffering
Message-Id: <G0xN3.106$q82.9908@news1.rdc1.mb.home.com>
In article <7u65d7$nbt$1@nnrp1.deja.com>,
rancorr@hotmail.com <rancorr@hotmail.com> wrote:
! I saw on the web the following example in a Perl script:
!
! $| = 1;
!
! It's supposed to disable output buffering. What is output buffering,
! and why would I want to disable it?
perlfaq5 has an entry on this question:
How do I flush/unbuffer an output filehandle? Why must I do this?
try:
man perlfaq5
perldoc perlfaq5
andrew
--
Andrew L. Johnson http://www.manning.com/Johnson/
Doing linear scans over an associative array is like
trying to club someone to death with a loaded Uzi.
-- Larry Wall
------------------------------
Date: Fri, 15 Oct 1999 13:14:37 GMT
From: bmccoy@foiservices.com (Brett W. McCoy)
Subject: Re: Disable output buffering
Message-Id: <slrn80eae0.4oc.bmccoy@moebius.foiservices.com>
Also Sprach rancorr@hotmail.com <rancorr@hotmail.com>:
>I saw on the web the following example in a Perl script:
>
>$| = 1;
>
>It's supposed to disable output buffering. What is output buffering,
>and why would I want to disable it?
See the perlvar document for the full description of this variable.
Setting it does not disable buffering, but more properly puts it into
'block buffering' mode whereas setting it to 0 puts it into line buffering
mode.
--
Brett W. McCoy bmccoy@foiservices.com
Computer Operations Manager (Alpha Geek) http://www.foiservices.com
FOI Services, Inc./DIOGENES 301-975-0110
---------------------------------------------------------------------------
------------------------------
Date: Thu, 14 Oct 1999 09:21:35 +0100
From: r@asd.com (Russell Parker)
Subject: Displaying 2 digits in time
Message-Id: <MPG.126fa2e68ace0e69989680@news.virgin.net>
I am trying to print time & date to a file when an event occurs.
I have got the correct formatting for all other parameters, such as
correct name for the day and month and 4 digit year.
For the time I get something like 14:1. This should be 14:01.
I suspect that I will have the same for the hours in the morning,
although this is not too much of a problem.
How do I correct this?
use Time::localtime;
use Time::gmtime;
use Time::tm;
$hour1=localtime->hour();
$min1=localtime->min();
$year1=localtime->year()+1900;
$gm = gmtime();
$gm2=gmtime();
$weekday1=(qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday
Sunday))[ $gm->wday()];
$month1=(qw(Jan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec))[$gm2-
>mon()];
$date1=localtime->mday();
print("$hour1:"."$min1 "."$weekday1 "."$date1"." $month1". " $year1");
Thanks
Russ Parker
------------------------------
Date: Thu, 14 Oct 1999 02:37:52 -0700
From: mbudash@sonic.net (Michael Budash)
Subject: Re: Displaying 2 digits in time
Message-Id: <mbudash-1410990237520001@ppp-216-101-156-52.dialup.snrf01.pacbell.net>
In article <MPG.126fa2e68ace0e69989680@news.virgin.net>, r@asd.com
(Russell Parker) wrote:
>I am trying to print time & date to a file when an event occurs.
>
>I have got the correct formatting for all other parameters, such as
>correct name for the day and month and 4 digit year.
>
>For the time I get something like 14:1. This should be 14:01.
>I suspect that I will have the same for the hours in the morning,
>although this is not too much of a problem.
>
>How do I correct this?
>
>
>use Time::localtime;
>use Time::gmtime;
>use Time::tm;
>$hour1=localtime->hour();
>$min1=localtime->min();
>$year1=localtime->year()+1900;
>$gm = gmtime();
>$gm2=gmtime();
>$weekday1=(qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday
>Sunday))[ $gm->wday()];
>$month1=(qw(Jan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec))[$gm2-
>>mon()];
>$date1=localtime->mday();
>print("$hour1:"."$min1 "."$weekday1 "."$date1"." $month1". " $year1");
>
>
>Thanks
>Russ Parker
you'll want to check out perl's sprintf function...
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Thu, 14 Oct 1999 10:34:40 GMT
From: c_j_marshall@my-deja.com
Subject: Re: Displaying 2 digits in time
Message-Id: <7u4bk0$bng$1@nnrp1.deja.com>
You could just hack it like this:
if ($min1 < 10){
$min1 =~ s/^/0/g;
}
In article <MPG.126fa2e68ace0e69989680@news.virgin.net>,
r@asd.com (Russell Parker) wrote:
> I am trying to print time & date to a file when an event occurs.
>
> I have got the correct formatting for all other parameters, such as
> correct name for the day and month and 4 digit year.
>
> For the time I get something like 14:1. This should be 14:01.
> I suspect that I will have the same for the hours in the morning,
> although this is not too much of a problem.
>
> How do I correct this?
>
> use Time::localtime;
> use Time::gmtime;
> use Time::tm;
> $hour1=localtime->hour();
> $min1=localtime->min();
> $year1=localtime->year()+1900;
> $gm = gmtime();
> $gm2=gmtime();
> $weekday1=(qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday
> Sunday))[ $gm->wday()];
> $month1=(qw(Jan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec))[$gm2-
> >mon()];
> $date1=localtime->mday();
> print("$hour1:"."$min1 "."$weekday1 "."$date1"." $month1". " $year1");
>
> Thanks
> Russ Parker
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 14 Oct 1999 11:50:09 +0100
From: David Cantrell <NukeEmUp@ThePentagon.com>
Subject: Re: Displaying 2 digits in time
Message-Id: <9rQFOE2FjZuz4BLsait+3u9S4SAb@4ax.com>
On Thu, 14 Oct 1999 09:21:35 +0100, r@asd.com (Russell Parker) said:
>I am trying to print time & date to a file when an event occurs.
>
>I have got the correct formatting for all other parameters, such as
>correct name for the day and month and 4 digit year.
>
>For the time I get something like 14:1. This should be 14:01.
>I suspect that I will have the same for the hours in the morning,
>although this is not too much of a problem.
>
>How do I correct this?
Either using sprintf() or with a variation on a theme of:
$hour=(($hour<10)?'0':'').$hour;
[Copying newsgroup posts to me by mail is considered rude]
--
David Cantrell, part-time Unix/perl/SQL/java techie
full-time chef/musician/homebrewer
http://www.ThePentagon.com/NukeEmUp
------------------------------
Date: 14 Oct 1999 13:26:03 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Displaying 2 digits in time
Message-Id: <3805cbdb_2@newsread3.dircon.co.uk>
Russell Parker <r@asd.com> wrote:
>
> For the time I get something like 14:1. This should be 14:01.
> I suspect that I will have the same for the hours in the morning,
> although this is not too much of a problem.
>
> How do I correct this?
>
perldoc -f sprintf
/J\
--
"He is marvelous at beating men and achieving real penetration" -
Alex Ferguson
------------------------------
Date: 14 Oct 1999 18:42:17 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Displaying 2 digits in time
Message-Id: <slrn80cqi8.cso.abigail@alexandra.delanet.com>
Russell Parker (r@asd.com) wrote on MMCCXXXV September MCMXCIII in
<URL:news:MPG.126fa2e68ace0e69989680@news.virgin.net>:
$$ I am trying to print time & date to a file when an event occurs.
$$
$$ I have got the correct formatting for all other parameters, such as
$$ correct name for the day and month and 4 digit year.
$$
$$ For the time I get something like 14:1. This should be 14:01.
$$ I suspect that I will have the same for the hours in the morning,
$$ although this is not too much of a problem.
$$
$$ How do I correct this?
$$
$$ $min1=localtime->min();
Change this line to:
sleep 60 until length ($min1 = localtime -> min ()) - 1;
Abigail
--
sub f{sprintf$_[0],$_[1],$_[2]}print f('%c%s',74,f('%c%s',117,f('%c%s',115,f(
'%c%s',116,f('%c%s',32,f('%c%s',97,f('%c%s',0x6e,f('%c%s',111,f('%c%s',116,f(
'%c%s',104,f('%c%s',0x65,f('%c%s',114,f('%c%s',32,f('%c%s',80,f('%c%s',101,f(
'%c%s',114,f('%c%s',0x6c,f('%c%s',32,f('%c%s',0x48,f('%c%s',97,f('%c%s',99,f(
'%c%s',107,f('%c%s',101,f('%c%s',114,f('%c%s',10,)))))))))))))))))))))))))
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Wed, 13 Oct 1999 14:56:36 -0700
From: "Ed Toivanen" <et@telus.net>
Subject: Re: Do you now an affordable Perl editor for Windows NT
Message-Id: <yg7N3.62$Fw.248421@news.bctel.net>
I like textpad, from www.textpad.com
Super wicked.
Ed
Matt King <mattking@techie.com> wrote in message
news:7thmra$d0c$1@news.uk.ibm.com...
> Why not just use the Windows notepad.exe? Works fine for me......
>
> Matt
>
>
------------------------------
Date: Thu, 14 Oct 1999 01:27:55 GMT
From: bradley_dc_smith@my-deja.com
Subject: Does perlcc work on windows NT?
Message-Id: <7u3bid$m3j$1@nnrp1.deja.com>
When I run the script, I find that part of the script needs some temp
file name to write in windows.
When I fixed the script, I find that the cl.exe command that it creates
to compile the c code it created is incorrect. (I'm using Visual C++ 6.0
patch 3)
I gave the c code and cl.exe command to one of the developers here who
is competent in Visual C++ and he couldn't get it to work.
Has anyone out there gotten perlcc to work on windows? What changes did
you need to make to fix it?
Thanks all,
Brad
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 15 Oct 1999 00:23:59 GMT
From: vishalb@my-deja.com
Subject: Re: Does perlcc work on windows NT?
Message-Id: <7u5s6j$gv3$1@nnrp1.deja.com>
In article <7u3bid$m3j$1@nnrp1.deja.com>,
bradley_dc_smith@my-deja.com wrote:
> When I run the script, I find that part of the script needs some temp
> file name to write in windows.
That has been corrected in the latest versions.
>
> When I fixed the script, I find that the cl.exe command that it
creates
> to compile the c code it created is incorrect. (I'm using Visual C++
6.0
> patch 3)
If you are using any perl less than perl5.005_61 with all the
compiler patches applied, your chances of making it work are low.
The reason is :
1> As you noticed, the cl command line is incorrect. You need to change
all "*.dll" to "*.lib" to make it work. This has been done very recently
and you can get the patches from p5p ( search for the thread on
compiler for win32)
2> Even if you do manage to compile it, it wouldnot work unless you
either use the borland/gcc compilers instead of vc++ to build perl or
apply another patch to rectify the vc++ specific problems.
>
> I gave the c code and cl.exe command to one of the developers here who
> is competent in Visual C++ and he couldn't get it to work.
>
> Has anyone out there gotten perlcc to work on windows? What changes
did
> you need to make to fix it?
Yes i have. Get the patches from
http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters
>
> Thanks all,
>
> Brad
>
>
cheers,
Vishal
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 12 Oct 1999 23:17:13 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Dos commands in Perl???????????
Message-Id: <7u0fhp$qm1$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Jeff Zucker
<jeff@vpservices.com>],
who wrote in article <380365A5.8E581EBE@vpservices.com>:
> krun@my-deja.com wrote:
> >
> > How would one use dos commands such as dir and cd in perl? Also if
> > there is a way what kind of information is returned when a dir is run?
>
> Have you bothered to read *any* of the documentatin for Perl? Look up
> these things to find answers to your questions: system, qx//,
> backticks, opendir, readdir, chdir. You might also want to investigate
> the File::Find module.
I think this answer is in some respects off topic. The shell commands
dir, cd etc *will not* run with any decent implementation of system().
They are not executables, there are *shell commands*.
So one may need to do
system $ENV{COMSPEC}. '/c', 'dir';
- if one wants to answer the question literally.
Ilya
------------------------------
Date: Wed, 13 Oct 1999 07:14:33 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Dos commands in Perl???????????
Message-Id: <38082c33.2981493@news.skynet.be>
Ilya Zakharevich wrote:
>I think this answer is in some respects off topic. The shell commands
>dir, cd etc *will not* run with any decent implementation of system().
>They are not executables, there are *shell commands*.
>
>So one may need to do
>
> system $ENV{COMSPEC}. '/c', 'dir';
Maybe it's just my system, but
print `dir`;
actually works. "system('dir')" doesn't.
Of course, running `cd .` is silly, since it changes the current
directory for the *child process* only, which is closed (and the effect
lost) after the command finishes. My tip to Krun: look at the docs for
chdir().
--
Bart.
------------------------------
Date: 13 Oct 1999 22:28:04 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Dos commands in Perl???????????
Message-Id: <7u311k$fre$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Bart Lateur
<bart.lateur@skynet.be>],
who wrote in article <38082c33.2981493@news.skynet.be>:
> >I think this answer is in some respects off topic. The shell commands
> >dir, cd etc *will not* run with any decent implementation of system().
> >They are not executables, there are *shell commands*.
> >
> >So one may need to do
> >
> > system $ENV{COMSPEC}. '/c', 'dir';
>
> Maybe it's just my system, but
>
> print `dir`;
>
> actually works. "system('dir')" doesn't.
I think all the M$-related ports do not follow the documentation in
this respect, and always use a shell. I consider this as a bug.
OS/2-port follows the documentation of system()/etc and uses shell
only if "requested".
Ilya
------------------------------
Date: 14 Oct 1999 03:58:01 GMT
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Dos commands in Perl???????????
Message-Id: <3805546C.EB225A2@vpservices.com>
Ilya Zakharevich wrote:
>
> [A complimentary Cc of this posting was sent to Bart Lateur
> <bart.lateur@skynet.be>],
> who wrote in article <38082c33.2981493@news.skynet.be>:
> > >I think this answer is in some respects off topic. The shell commands
> > >dir, cd etc *will not* run with any decent implementation of system().
> > >They are not executables, there are *shell commands*.
> > >
> > >So one may need to do
> > >
> > > system $ENV{COMSPEC}. '/c', 'dir';
> >
> > Maybe it's just my system, but
> >
> > print `dir`;
> >
> > actually works. "system('dir')" doesn't.
>
> I think all the M$-related ports do not follow the documentation in
> this respect, and always use a shell. I consider this as a bug.
Well, not quite always apparently. The activeState 520 build on win95
gives a nod in the right direction. I thoroughly confused myself
discovering it. Apparently if there is an executable of the same name as
a shell command, both system and backticks use the executable rather
than the shell. I have my cygwin/bash/bin directory on my DOS console
path so I can use its "mv" and "cp" and such even though I am not
actually running bash. But guess, what, there is a dir.exe in there
that replicates "ls". I guess for people who want to not have to
remember what OS they are using. SO if I do a system('dir') or a print
`dir`, it runs that cygwin dir.exe, *not* the shell command "dir".
Naturally from a regular DOS console prompt, "dir" runs the shell
command, *not* dir.exe. If I rename dir.exe to something else, then
system('dir') and print `dir` both behave just like running "dir"
outside of perl -- they use the shell command. So contrary to what Bart
reported above, system('dir') does "work" on my setup. "Working" in
this case means calling dir.exe if it exists on the path and calling the
dir shell command if dir.exe doesn't exist or isn't on the path.
Hey, just because I sometimes use M$ doesn't mean I don't think its
wierd.
--
Jeff
------------------------------
Date: Thu, 14 Oct 1999 07:57:46 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Dos commands in Perl???????????
Message-Id: <38067a27.1359888@news.skynet.be>
Ilya Zakharevich wrote:
>I think all the M$-related ports do not follow the documentation in
>this respect, and always use a shell. I consider this as a bug.
Nooo... system('dir') has just one word as the argument, so it doesn't
use a shell; and it doesn't work ("Can't spawn "dir": No such file or
directory (ENOENT)"). system('dir','*.txt') has a list of two words as
arguments, so it doesn't use a shell either, and it fails too.
But system('dir *.txt') has a string of two words as argument, so it
*does* use the shell; and indeed it works. (It prints too STDOUT , so
it's not too useful.)
Backticks, OTOH hand, don't make that distinction, always use the shell,
and both { print `dir` } and { print `dir *.txt` } work.
BTW I'm using the DJGPP DOS port, not Activestate (that's on mly other
computer).
--
Bart.
------------------------------
Date: Fri, 15 Oct 1999 00:58:31 -0500
From: Clinton Carr <ccarr@websocket.com>
Subject: encoded CGI data
Message-Id: <3806C287.D406D898@websocket.com>
What's an easy way to URL encode data to send via CGI Post?
Thanks,
------------------------------
Date: Thu, 14 Oct 1999 23:19:34 -0700
From: mbudash@sonic.net (Michael Budash)
Subject: Re: encoded CGI data
Message-Id: <mbudash-1410992319340001@adsl-216-103-91-123.dsl.snfc21.pacbell.net>
In article <3806C287.D406D898@websocket.com>, Clinton Carr
<ccarr@websocket.com> wrote:
>What's an easy way to URL encode data to send via CGI Post?
>
>Thanks,
use CGI qw/:standard escape/;
$url_encoded_data = escape($data);
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Thu, 14 Oct 1999 23:25:49 -0700
From: mbudash@sonic.net (Michael Budash)
Subject: Re: encoded CGI data
Message-Id: <mbudash-1410992325490001@adsl-216-103-91-123.dsl.snfc21.pacbell.net>
In article
<mbudash-1410992319340001@adsl-216-103-91-123.dsl.snfc21.pacbell.net>,
mbudash@sonic.net (Michael Budash) wrote:
>In article <3806C287.D406D898@websocket.com>, Clinton Carr
><ccarr@websocket.com> wrote:
>
>>What's an easy way to URL encode data to send via CGI Post?
>>
>>Thanks,
>
>use CGI qw/:standard escape/;
>
>$url_encoded_data = escape($data);
>
hmmm... on second thought, how were you planning on executing your 'CGI
Post'? at least one of the possible ways doesn't require my suggested
method...
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Wed, 13 Oct 1999 11:25:18 GMT
From: Pawan <pj7066@my-deja.com>
Subject: Re: File upload problem
Message-Id: <7u1q6m$gbs$1@nnrp1.deja.com>
Hi CS
Thanx for your reply.
You r right, it does not work with 5.003 - we have been able
to solve the problem without CGI.pm
Pawan
In article <ZgoM3.5782$UG5.399187@typ11.nn.bcandid.com>,
"CS" <@mdo.net> wrote:
> It won't work on version 5.003, which is a few years old. I've tried
it,
> and it just won't get along with it.
>
> Besides, CGI.pm (if you're using that) requires version 5.004
>
> Regards, CS
>
> >is running perfectly on the NT server which has Perl 5.004
> >
> >However, the same script is not running with perl 5.003 build
> >300 series - if the perl file is called from a form then it gives
> >an error that the document contains no data.
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 15 Oct 1999 16:51:38 +0950
From: michaels@packet.obtero.com.au ()
Subject: Finding the largest numbers in an array?
Message-Id: <slrn80dkap.dn0.michaels@packet.obtero.com.au>
Hello,
I've got an output file from a network analyzer, which I want
to sort by two fields, then search the second field and get
the line with the largest value, like so:
10 1163 383439 1 192.168.0.1 10.0.0.1 1872 77824
10 1163 383439 1 192.168.0.1 10.0.0.1 4680 187372
10 1163 383439 1 192.168.0.1 10.0.0.1 7488 304108
10 1163 383439 1 192.168.0.1 10.0.0.1 10296 418304
10 1163 383439 1 192.168.0.1 10.0.0.1 13104 535040
10 1163 383439 1 192.168.0.1 10.0.0.1 15912 644588
10 1163 383439 1 192.168.0.1 10.0.0.1 18720 755864
10 1010 543444 1 192.168.1.1 10.1.1.1 8340 23455
10 1010 543444 1 192.168.1.1 10.1.1.1 9432 32330
10 1010 543444 1 192.168.1.1 10.1.1.1 10032 45320
10 1010 543444 1 192.168.1.1 10.1.1.1 12004 50323
...
The sorting part is no problem, but I'm running into difficulty with
picking out the
10 1163 383439 1 192.168.0.1 10.0.0.1 18720 755864
and
10 1010 543444 1 192.168.1.1 10.1.1.1 12004 50323
from the above snippet of logfile. Any clues?
Cheers and thanks,
Mike
------------------------------
Date: 15 Oct 1999 03:02:24 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Finding the largest numbers in an array?
Message-Id: <slrn80dnru.q8s.abigail@alexandra.delanet.com>
michaels@packet.obtero.com.au (michaels@packet.obtero.com.au) wrote on
MMCCXXXVI September MCMXCIII in <URL:news:slrn80dkap.dn0.michaels@packet.obtero.com.au>:
"" Hello,
""
"" I've got an output file from a network analyzer, which I want
"" to sort by two fields, then search the second field and get
"" the line with the largest value, like so:
""
"" 10 1163 383439 1 192.168.0.1 10.0.0.1 1872 77824
"" 10 1163 383439 1 192.168.0.1 10.0.0.1 4680 187372
"" 10 1163 383439 1 192.168.0.1 10.0.0.1 7488 304108
"" 10 1163 383439 1 192.168.0.1 10.0.0.1 10296 418304
"" 10 1163 383439 1 192.168.0.1 10.0.0.1 13104 535040
"" 10 1163 383439 1 192.168.0.1 10.0.0.1 15912 644588
"" 10 1163 383439 1 192.168.0.1 10.0.0.1 18720 755864
"" 10 1010 543444 1 192.168.1.1 10.1.1.1 8340 23455
"" 10 1010 543444 1 192.168.1.1 10.1.1.1 9432 32330
"" 10 1010 543444 1 192.168.1.1 10.1.1.1 10032 45320
"" 10 1010 543444 1 192.168.1.1 10.1.1.1 12004 50323
"" ...
""
"" The sorting part is no problem, but I'm running into difficulty with
"" picking out the
"" 10 1163 383439 1 192.168.0.1 10.0.0.1 18720 755864
"" and
"" 10 1010 543444 1 192.168.1.1 10.1.1.1 12004 50323
"" from the above snippet of logfile. Any clues?
The problem statement isn't quite clear. You are sorting on 2 fields,
but the array has 8 fields. Let's assume you have sorted on second
and third field, and have ties resolved in some way; now you want to
find the last of those sets that tied in the second and third field.
Assume you have the sorted list in @array.
my %hash;
foreach (@array) {
my ($second, $third) = (split)[1,2];
$hash {$second} -> {$third} = $_;
}
Now the hash should contain all the "largest" values.
Abigail
--
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
print } sub __PACKAGE__ { &
print ( __PACKAGE__)} &
__PACKAGE__
( )
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 15 Oct 1999 14:46:22 GMT
From: gbacon@ruby.itsc.uah.edu (Greg Bacon)
Subject: Re: Finding the largest numbers in an array?
Message-Id: <7u7enu$ci2$1@info2.uah.edu>
In article <slrn80dkap.dn0.michaels@packet.obtero.com.au>,
michaels@packet.obtero.com.au () writes:
: I've got an output file from a network analyzer, which I want
: to sort by two fields, then search the second field and get
: the line with the largest value, like so:
:
: 10 1163 383439 1 192.168.0.1 10.0.0.1 1872 77824
: 10 1163 383439 1 192.168.0.1 10.0.0.1 4680 187372
: 10 1163 383439 1 192.168.0.1 10.0.0.1 7488 304108
: 10 1163 383439 1 192.168.0.1 10.0.0.1 10296 418304
: 10 1163 383439 1 192.168.0.1 10.0.0.1 13104 535040
: 10 1163 383439 1 192.168.0.1 10.0.0.1 15912 644588
: 10 1163 383439 1 192.168.0.1 10.0.0.1 18720 755864
: 10 1010 543444 1 192.168.1.1 10.1.1.1 8340 23455
: 10 1010 543444 1 192.168.1.1 10.1.1.1 9432 32330
: 10 1010 543444 1 192.168.1.1 10.1.1.1 10032 45320
: 10 1010 543444 1 192.168.1.1 10.1.1.1 12004 50323
: ...
:
: The sorting part is no problem, but I'm running into difficulty with
: picking out the
: 10 1163 383439 1 192.168.0.1 10.0.0.1 18720 755864
: and
: 10 1010 543444 1 192.168.1.1 10.1.1.1 12004 50323
: from the above snippet of logfile. Any clues?
You didn't make it clear, so I'm guessing that you want to select
the record containing the maximum value in the seventh column for
each value in the third column.
#! /usr/bin/perl -w
use strict;
sub max;
my @records = split /\n/, <<EORecords;
10 1163 383439 1 192.168.0.1 10.0.0.1 1872 77824
10 1163 383439 1 192.168.0.1 10.0.0.1 4680 187372
10 1163 383439 1 192.168.0.1 10.0.0.1 7488 304108
10 1163 383439 1 192.168.0.1 10.0.0.1 10296 418304
10 1163 383439 1 192.168.0.1 10.0.0.1 13104 535040
10 1163 383439 1 192.168.0.1 10.0.0.1 15912 644588
10 1163 383439 1 192.168.0.1 10.0.0.1 18720 755864
10 1010 543444 1 192.168.1.1 10.1.1.1 8340 23455
10 1010 543444 1 192.168.1.1 10.1.1.1 9432 32330
10 1010 543444 1 192.168.1.1 10.1.1.1 10032 45320
10 1010 543444 1 192.168.1.1 10.1.1.1 12004 50323
EORecords
my %thirds;
for (@records) {
my @f = split;
push @{ $thirds{ $f[2] } }, \@f;
}
for (sort { $a <=> $b } keys %thirds) {
my $a = $thirds{$_};
my $maxidx = max $a, 0, scalar @$a;
print join ' ', @{ $a->[$maxidx] }, "\n";
}
# divide and conquer: find index of maximum in subarray
# of @$a of length $len starting at index $start
sub max {
my($a,$start,$len) = @_;
if ($len == 1) {
return $start;
}
elsif ($len == 2) {
if ($a->[$start][6] > $a->[$start+1][6]) {
return $start;
}
else {
return $start+1;
}
}
else {
my $half = int($len / 2);
my $left = max $a, $start, $half;
my $right = max $a, $start+$half, $len-$half;
if ($a->[$left][6] > $a->[$right][6]) {
return $left;
}
else {
return $right;
}
}
}
Enjoy,
Greg
--
UNIX should be used as an adjective.
-- AT&T
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 1058
**************************************