[11400] in Perl-Users-Digest
Perl-Users Digest, Issue: 5000 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 26 16:20:38 1999
Date: Fri, 26 Feb 99 13:18:11 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 26 Feb 1999 Volume: 8 Number: 5000
Today's topics:
Sorting trouble. Assistance appreciated. <par@removethis.bahnhof.se>
Re: Sorting trouble. Assistance appreciated. <jdf@pobox.com>
Re: Sorting trouble. Assistance appreciated. (Larry Rosler)
sorting <burger@csd.queensu.ca>
Re: sorting <mnag@exeter.nospam.please>
Re: sorting <tchrist@mox.perl.com>
Re: sorting <Arnold_Mueller@csi.com>
Re: Speed Up Perl (Micha3 Rutka)
Re: Speed Up Perl <r.i.h.powell@rl.ac.uk>
Re: splitting Pairs of characters (Greg Ward)
sql in perl <elst.fels@nospam.ping.be>
Re: sql in perl <Arnold_Mueller@csi.com>
Re: sql in perl (Abigail)
Re: sql in perl the_ferret@my-dejanews.com
srand question <cnorris@hotmail.com>
Re: srand question (M.J.T. Guy)
Re: srand question <Philip.Newton@datenrevision.de>
Re: SRC: psgrep - make cool queries against ps output <mpersico@erols.com>
SSLeay and install <internet@reimer.ch>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 26 Feb 1999 11:04:21 +0100
From: "Par Svensson" <par@removethis.bahnhof.se>
Subject: Sorting trouble. Assistance appreciated.
Message-Id: <7b5rfh$1ojf@news1.newsguy.com>
Hello,
I have a problem that I don't really know how to solve.
I have this file consisting of a few hundred rows of text,
each about 700 characters long. I want to sort it like this:
First with regards to the text contents of position [32-48].
All rows with identical text in [32-48], I want to sort by the
text in [160-192]...and so on for about five levels.
This is easily done in MS Access, but my aim is to exclude
such abominations.
When the sorting is finished the file should look the same,
only with the rows switched around in the manner described.
I hope that someone does understand my delirious rantings
and is able to help :-)
Thanks in advance,
/Par
par@spri.sven
To reply via e-mail, please change "sven" to "se"
------------------------------
Date: 26 Feb 1999 10:25:12 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: <par@spri.sven>
Subject: Re: Sorting trouble. Assistance appreciated.
Message-Id: <m3n221rxuv.fsf@joshua.panix.com>
"Par Svensson" <par@bahnhof.se> writes:
> I have this file consisting of a few hundred rows of text, each
> about 700 characters long. I want to sort it like this:
If you have a few megabytes to spare, you can simply read the file
into an array, and sort the array using an extension of the ideas
found in the following document.
http://www.perl.com/CPAN-local/doc/FMTEYEWTK/sort.html
Because your data have fixed-width fields, you get a big win by using
unpack/pack.
#!/perl -wl
my $format = 'a12a8a16a24a3a14'; #whatever
my @lines = map { [unpack $format, $_] } <FILE>;
@lines = sort { $a->[4] cmp $b->[4]
|| $a->[2] cmp $b->[2] } @lines;
for (@lines) { print NEWFILE pack $format, @$_ }
In short:
0) perldoc perlfaq4 [How do I sort an array by (anything)?]
1) read that sorting doc
2) perldoc -f sort
3) perldoc -f pack
4) perldoc -f unpack
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Fri, 26 Feb 1999 07:18:25 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Sorting trouble. Assistance appreciated.
Message-Id: <MPG.11405b1f30de03ea989692@nntp.hpl.hp.com>
In article <7b5rfh$1ojf@news1.newsguy.com>, on Fri, 26 Feb 1999 11:04:21
+0100 par@removethis.bahnhof.se says...
> I have a problem that I don't really know how to solve.
> I have this file consisting of a few hundred rows of text,
> each about 700 characters long. I want to sort it like this:
>
> First with regards to the text contents of position [32-48].
> All rows with identical text in [32-48], I want to sort by the
> text in [160-192]...and so on for about five levels.
I would start by looking at the excellent documentation for the 'sort'
function that came with your Perl installation. There you will also
find a reference to a document called 'Far More Than You Ever Wanted To
Know About Sorting'.
In the case you describe, the most appropriate way to extract the
sorting keys is with 'substr' or 'unpack'.
> To reply via e-mail, please change "sven" to "se"
I would have, had you done so yourself.
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sun, 21 Feb 1999 17:56:59 -0500
From: Bob Burge <burger@csd.queensu.ca>
Subject: sorting
Message-Id: <Pine.SO4.4.05.9902211752510.16394-100000@csd>
Howdy, I've got an @ array of names and want to sort on the content and
not the indexing number. Any suggestions?
Thanks,
Bob
------------------------------
Date: Sun, 21 Feb 1999 19:15:51 -0500
From: "Manish Nag" <mnag@exeter.nospam.please>
Subject: Re: sorting
Message-Id: <Fh1A2.836$HF4.2048962@brnws01.ne.mediaone.net>
use the built-in sort function on your array and return it to a new array
which holds the sorted
version.
Eg.
@arr1 = ("Allen","Dirk","Brad");
@arr2 = sort(@list);
@arr2 ends up being ("Allen","Brad","Dirk")
_________________________
Manish Nag
Furnace Blast Technologies, Inc.
1800 Massachusetts Ave #31
Cambridge, MA 02140
(617) 868-9080
mnag@geocities.com
Bob Burge wrote in message ...
>Howdy, I've got an @ array of names and want to sort on the content and
>not the indexing number. Any suggestions?
>
>Thanks,
>Bob
>
------------------------------
Date: 21 Feb 1999 17:23:47 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: sorting
Message-Id: <36d0a393@csnews>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, Bob Burge <burger@csd.queensu.ca> writes:
:Howdy, I've got an @ array of names and want to sort on the content and
:not the indexing number. Any suggestions?
Yup: read what the perlfunc manpage says about the sort operator.
--tom
--
What's the difference between Country music and Western music? Well,
Country is about getting drunk, feeling sorry for yourself, and hitting
on your neighbor's wife. Western, on the other hand, is about riding
the range, wide open spaces, and hitting on your neighbor's sheep.
------------------------------
Date: Mon, 22 Feb 1999 10:44:20 +0100
From: "Arnold M|ller" <Arnold_Mueller@csi.com>
Subject: Re: sorting
Message-Id: <#fchwdkX#GA.298@ntdwwaaw.compuserve.com>
Bob Burge wrote in message ...
>Howdy, I've got an @ array of names and want to sort on the content and
>not the indexing number. Any suggestions?
>
>Thanks,
>Bob
e.g.
@names=('Peter','Joe','Alice'...);
@names=sort @names;
#@names=('Alice','Joe','Peter'...);
or if you want to do a case-insensitive sort :
@names=sort {uc(a) cmp uc(b)} @names;
Bye.
Arnold M|ller
------------------------------
Date: 23 Feb 1999 13:01:24 +0100
From: rutka@lucent.com (Micha3 Rutka)
Subject: Re: Speed Up Perl
Message-Id: <wsmzp65l46j.fsf@hzsac503.nl.lucent.com>
Ala Qumsieh <aqumsieh@matrox.com> writes:
> I believe lines 17 thru 21 (inclusive) can be safely deleted without
> any loss of functionality. The real problem lies in the OS. Switch to
> Linux and go get a refund for Winblows from Micro$oft.
Ala,
did somebody flamed you already for pointing problems in the OS? I was
flamed once with an argument that the OS cannot be bad because 99.99%
people are using it ;-).
Michal
------------------------------
Date: Fri, 26 Feb 1999 09:06:41 +0000
From: Rosemary I H Powell <r.i.h.powell@rl.ac.uk>
Subject: Re: Speed Up Perl
Message-Id: <36D66421.65E05D79@rl.ac.uk>
Can I download one from CPAN?
Rosemary,
Just Another Microsoft Idiot
Abigail wrote:
>
> pvdkamer@inter.NL.net (pvdkamer@inter.NL.net) wrote on MCMXCVI September
> MCMXCIII in <URL:news:36caa3c2.10005684@news.wxs.nl>:
> \\ Does anyone have a sulution to speed up perl scripts ?
>
> Put a Porche engine in your computer.
>
> Abigail
> --
> perl -e '$_ = q *4a75737420616e6f74686572205065726c204861636b65720a*;
> for ($*=******;$**=******;$**=******) {$**=*******s*..*qq}
> print chr 0x$& and q
> qq}*excess********}'
------------------------------
Date: 22 Feb 1999 23:23:36 GMT
From: gward@cnri.reston.va.us (Greg Ward)
Subject: Re: splitting Pairs of characters
Message-Id: <7asoto$6hr$1@news0-alterdial.uu.net>
Suad Musovich <suad@nix.tmk.auckland.ac.nz> wrote:
> I have messily split single characters and printed the
> array in pairs but it would send a Perl coder screaming
> "philistine" if they saw my code :)
You could always try posting it, but a) duck, and b) put on asbestos
underwear. However, the most obvious way to do this is so trivial that
you probably don't need to post your attempts.
> This is for splitting a HW address like 000502F3DD12
> into 00:05:02:F3:DD:12
If $address contains the string to split, then do this:
@chunks = ($address =~ m/(..)/g);
and @chunks will be the array of two-character sub-strings from
$address. Note that if $address has an odd number of characters
("length ($address) % 2 != 0"), then the last character will be silently
dropped, so you should probably check for this condition first.
while (confused) { "man perlre" }
Don't feel bad if you stay confused for a while -- for some reason, it
took me *years* of hacking Perl before I figured out how the /g modifier
works on m//. (On s///, it's simple, but I had a mental block about
m//g -- don't ask me why.) If you're still stuck after reading the man
page N times (for N > 1), feel free to ask here for more help!
Greg
--
Greg Ward - software developer gward@cnri.reston.va.us
Corporation for National Research Initiatives
1895 Preston White Drive voice: +1-703-620-8990 x287
Reston, Virginia, USA 20191-5434 fax: +1-703-620-0913
------------------------------
Date: Mon, 22 Feb 1999 07:05:27 +0100
From: "myname@mydomain.com" <elst.fels@nospam.ping.be>
Subject: sql in perl
Message-Id: <7aqs0s$i06$1@news3.Belgium.EU.net>
Can anyone tell me if it is possible to use the SQL language inside perl ?
And if so how would you have to embed it in the code ?
Thank you for all your help,
Peter Elst
~ Ride the VIBES ~
------------------------------
Date: Mon, 22 Feb 1999 10:59:13 +0100
From: "Arnold M|ller" <Arnold_Mueller@csi.com>
Subject: Re: sql in perl
Message-Id: <uNMoDmkX#GA.314@ntdwwaaw.compuserve.com>
Use the WIN32::ODBC package (if you want to write for Windows).
First you have to set up a System-DNS in the ODBC32-Configurations.
(Start->Settings->Control Panel->ODBC).
Remember the name you gave it and open a connection to your database in the
following way:
#PERL-Code
use WIN32::ODBC;
$db=new Win32::ODBC("DSN=$DSNName;UID=$yourID;PWD=$yourMostSecretPWD");
Excecute SQL-Statements like this:
#PERL-Code
$db->Sql($yourSQLStatement);
$db->FetchRow();
%dataRow=$db->DataHash();
#now %dataRow is a hash with the columnnames as keys and values... well as
it's values.
Documentation about the Win32::ODBC-package can be found at:
http://www.roth.net/odbc/odbc.html
Bye.
Arnold M|ller
myname@mydomain.com wrote in message <7aqs0s$i06$1@news3.Belgium.EU.net>...
>Can anyone tell me if it is possible to use the SQL language inside perl ?
>And if so how would you have to embed it in the code ?
>
>Thank you for all your help,
>
>Peter Elst
>
>~ Ride the VIBES ~
>
>
>
>
------------------------------
Date: 22 Feb 1999 16:24:59 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: sql in perl
Message-Id: <7as0cr$f5m$2@client2.news.psi.net>
myname@mydomain.com (elst.fels@nospam.ping.be) wrote on MMI September
MCMXCIII in <URL:news:7aqs0s$i06$1@news3.Belgium.EU.net>:
-- Can anyone tell me if it is possible to use the SQL language inside perl ?
No. That is, there isn't anything in perl that understands SQL.
You can however send SQL statements to database servers; see CPAN
for various modules.
Abigail
--
perl -e '$a = q 94a75737420616e6f74686572205065726c204861636b65720a9 and
${qq$\x5F$} = q 97265646f9 and s g..g;
qq e\x63\x68\x72\x20\x30\x78$&eggee;
{eval if $a =~ s e..eqq qprint chr 0x$& and \x71\x20\x71\x71qeexcess}'
------------------------------
Date: Thu, 25 Feb 1999 04:47:49 GMT
From: the_ferret@my-dejanews.com
Subject: Re: sql in perl
Message-Id: <7b2klj$vf8$1@nnrp1.dejanews.com>
Typically, SQL is used in conjunction with DBI <http://www.hermetica.com/
technologia/DBI/> and some DBDs. There are many references to this at <http://
reference.perl.com/query.cgi?database>. I had the same questions some seven or
eight months ago and these are the two places where I started.
Good luck!
Bruce
In article <7aqs0s$i06$1@news3.Belgium.EU.net>,
"myname@mydomain.com" <elst.fels@nospam.ping.be> wrote:
> Can anyone tell me if it is possible to use the SQL language inside perl ?
> And if so how would you have to embed it in the code ?
>
> Thank you for all your help,
>
> Peter Elst
>
> ~ Ride the VIBES ~
>
>
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 22 Feb 1999 23:58:35 GMT
From: "Craig" <cnorris@hotmail.com>
Subject: srand question
Message-Id: <01be5ebf$8cc15ec0$ce3a56d1@puter>
I need to get a better srand seed for a a cgi application I'm doing. I
found a way to get a better seed in the Perl docs, but its written for the
Unix side (I'm on Win32). What would I have to call to equal the following
statement, so that it would run on Win32?
srand(time ^ $$ ^ unpack"%L*", `ps axww | gzip`);
I appreciate any help!
Craig
------------------------------
Date: 23 Feb 1999 01:14:01 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: srand question
Message-Id: <7asvcp$o59$1@pegasus.csx.cam.ac.uk>
Craig <cnorris@hotmail.com> wrote:
>I need to get a better srand seed for a a cgi application I'm doing. I
>found a way to get a better seed in the Perl docs, but its written for the
>Unix side (I'm on Win32). What would I have to call to equal the following
>statement, so that it would run on Win32?
>
>srand(time ^ $$ ^ unpack"%L*", `ps axww | gzip`);
Assuming you're using an up-to-date Perl, don't bother to call srand()
at all. Perl will automatically do a better job than anything you
can manage.
>From perldoc -f srand:
In fact, it's usually not necessary to call C<srand()> at all, because if
it is not called explicitly, it is called implicitly at the first use of
the C<rand()> operator. However, this was not the case in version of Perl
before 5.004, so if your script will run under older Perl versions, it
should call C<srand()>.
Mike Guy
------------------------------
Date: Wed, 24 Feb 1999 09:17:07 +0100
From: Philip Newton <Philip.Newton@datenrevision.de>
Subject: Re: srand question
Message-Id: <36D3B583.FC4E135A@datenrevision.de>
Craig wrote:
>
> I need to get a better srand seed for a a cgi application I'm doing.
Do you know about the Math::TrulyRandom module on CPAN? I've never tried
it myself, but ISTR that it looks at various often-changing things on
your machine to provide "better" random numbers. Don't know whether it
does Win32 too, though.
HTH, HAND
Cheers,
Philip
------------------------------
Date: Mon, 22 Feb 1999 21:59:38 -0500
From: "Matthew O. Persico" <mpersico@erols.com>
Subject: Re: SRC: psgrep - make cool queries against ps output
Message-Id: <36D2199A.1E5A1BB1@erols.com>
Tom.
I took this very useful script a while ago and added some switches to
include/exclude the header, include entries with/without the caller's
pid, exclude the entry for psgrep, the ability to store/choose from
multiple pack formats and POD. I use it in produciton shell scripts and
never have touched raw ps for abnout four months now. Should I post it
for discussion or send it to you privately?
Tom Christiansen wrote:
>
> Besides a demo of when you should use eval to make functions and when
> you should instead use closures, this is a general technique applicable
> to any small database that you'd like to make powerful queries against.
>
> Here's how you find lines containing ``sh'' at the end of a word:
> % psgrep '/sh\b/'
>
> Processes whose command names end in ``sh'':
> % psgrep 'command =~ /sh$/'
>
> Processes running with a user id below 10:
> % psgrep 'uid < 10'
>
> Login shells with active ttys:
> % psgrep 'command =~ /^-/' 'tty ne "?"'
>
> Processes running on pseudo-ttys:
> % psgrep 'tty =~ /^[p-t]/'
>
> Non-superuser processes running detached:
> % psgrep 'uid && tty eq "?"'
>
> Huge processes that aren't owned by the super-user:
> % psgrep 'size > 10 * 2**10' 'uid != 0'
>
> #!/usr/bin/perl -w
> # psgrep - print selected lines of ps output by
> # compiling user queries into code
>
> use strict;
>
> # each field from the PS header
> my @fieldnames = qw(FLAGS UID PID PPID PRI NICE SIZE
> RSS WCHAN STAT TTY TIME COMMAND);
>
> # determine the unpack format needed (hard-coded for Linux ps)
> my $fmt = cut2fmt(8, 14, 20, 26, 30, 34, 41, 47, 59, 63, 67, 72);
>
> my %fields; # where the data will store
>
> die <<Thanatos unless @ARGV;
> usage: $0 criterion ...
> Each criterion is one a Perl expression involving:
> @fieldnames
> All criteria must be met for a line to be printed.
> Thanatos
>
> # Create function aliases for uid, size, UID, SIZE, etc.
> # Empty parens on closure args needed for void prototyping.
> for my $name (@fieldnames) {
> no strict 'refs';
> *$name = *{lc $name} = sub () { $fields{$name} };
> }
>
> my $code = "sub is_desirable { " . join(" and ", @ARGV) . " } ";
> unless (eval $code.1) {
> die "Error in code: $@\n\t$code\n";
> }
>
> open(PS, "ps wwaxl |") || die "cannot fork: $!";
> print scalar <PS>; # emit header line
> while (<PS>) {
> @fields{@fieldnames} = trim(unpack($fmt, $_));
> print if is_desirable(); # line matches their criteria
> }
> close(PS) || die "ps failed!";
>
> # convert cut positions to unpack format
> sub cut2fmt {
> my(@positions) = @_;
> my $template = '';
> my $lastpos = 1;
> for my $place (@positions) {
> $template .= "A" . ($place - $lastpos) . " ";
> $lastpos = $place;
> }
> $template .= "A*";
> return $template;
> }
>
> sub trim {
> my @strings = @_;
> for (@strings) {
> s/^\s+//;
> s/\s+$//;
> }
> return wantarray ? @strings : $strings[0];
> }
>
> # the following was used to determine column cut points.
> # sample input data follows
> #123456789012345678901234567890123456789012345678901234567890123456789012345
> # 1 2 3 4 5 6 7
> # Positioning:
> # 8 14 20 26 30 34 41 47 59 63 67 72
> # | | | | | | | | | | | |
> __END__
> FLAGS UID PID PPID PRI NI SIZE RSS WCHAN STA TTY TIME COMMAND
> 100 0 1 0 0 0 760 432 do_select S ? 0:02 init
> 140 0 187 1 0 0 784 452 do_select S ? 0:02 syslogd
> 100100 101 428 1 0 0 1436 944 do_exit S 1 0:00 /bin/login
> 100140 99 30217 402 0 0 1552 1008 posix_lock_ S ? 0:00 httpd
> 0 101 593 428 0 0 1780 1260 copy_thread S 1 0:00 -tcsh
> 100000 101 30639 9562 17 0 924 496 R p1 0:00 ps axl
> 0 101 25145 9563 0 0 2964 2360 idetape_rea S p2 0:06 trn
> 100100 0 10116 9564 0 0 1412 928 setup_frame T p3 0:00 ssh -C www
> 100100 0 26554 9653 0 0 812 436 setup_frame T p2 0:00 man perlfunc
> 100100 0 26560 26554 0 0 1076 572 setup_frame T p2 0:00 less
> 100000 101 19058 9562 0 0 1396 900 setup_frame T p1 0:02 nvi /tmp/a
> --
> It's there as a sop to former Ada programmers. :-)
> --Larry Wall regarding 10_000_000 in <11556@jpl-devvax.JPL.NASA.GOV>
--
Matthew O. Persico
http://www.erols.com/mpersico
http://www.digistar.com/bzip2
------------------------------
Date: Wed, 24 Feb 1999 13:10:14 +0100
From: Patrick Stalder <internet@reimer.ch>
Subject: SSLeay and install
Message-Id: <36D3EC26.A5251DC2@reimer.ch>
Hi
I have downloaded the newest version of the SSleay. I'm working on a
Windows 98/NT and would like to install this program on my machine. But
I find no way to install it. Has anyone an idea, where I find more
informationen for the install. I have read all the docs, but I could not
find anything helpfully.
Has someone install this program on a machine and can help me on the
installing process?
Thanks for any help
Patrick
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 5000
**************************************