[22884] in Perl-Users-Digest
Perl-Users Digest, Issue: 5105 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 11 06:06:14 2003
Date: Wed, 11 Jun 2003 03:05:07 -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 Wed, 11 Jun 2003 Volume: 10 Number: 5105
Today's topics:
Re: Catching error code outside of the range of 0-255 (Carlton Brown)
Re: Do yu know abetter way to do it ? <beaudet@cyber.kodak.com>
Re: Help! <bwalton@rochester.rr.com>
Re: How to I arrange for a socket connection to time ou <julian@avbrief.com>
How to make write()/format behave more like Text::Wrap? <gerardlanois@netscape.net>
IIS running perl scripts with VB not working (Krusty)
Re: Indenturing words into lists (Damian James)
Inverse match on command line? <i@NOSPAMALLOWED.com>
Re: Inverse match on command line? <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: Mac and Line Breaks (Phil)
Re: need the ascii set for arrow down <gmiller@NOTforSPAM.gregmiller.net>
Re: Perl Matrix Filter Module like in Excel? <bwalton@rochester.rr.com>
Re: Perl Matrix Filter Module like in Excel? <betsamaarcra@mindspring.com>
Re: Perl Matrix Filter Module like in Excel? Dennis@NoSpam.com
Re: Perl Matrix Filter Module like in Excel? Dennis@NoSpam.com
Re: Perl Matrix Filter Module like in Excel? <mgjv@tradingpost.com.au>
Re: Regular expression <sumguy@hooker.com>
Re: stripping leading zeros thru multiple fields <g4rry_short@zw4llet.com>
Re: using Dumper to save hash and retrieving it. <mgjv@tradingpost.com.au>
Re: virtual x server for Tk <simon.andrews@bbsrc.ac.uk>
Why is the system call not working? (Math55)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 10 Jun 2003 22:57:39 -0700
From: carltonbrown@hotmail.com (Carlton Brown)
Subject: Re: Catching error code outside of the range of 0-255
Message-Id: <aa611a32.0306102157.52d6953a@posting.google.com>
Daniel Nichols <daniel.nichols@NOSPAMvirgin.net> wrote in message news:<0ndcev00jl2i58jb872205pfsjopkrabq3@4ax.com>...
[ snup ]
> How can I call an OS program and handle return codes outside of the
> range 0 to 255.
Long story short - sqlplus is a command-line tool, use DBI/DBD modules
if you can get them. They contain methods to get the error codes you
want. Plenty of docs on this. Or you could even (ugh) scrape the
screen output if you're truly stuck with sqlpus in a strict
environment without the DB modules.
Short story long - return codes outside of 0-255 are pretty uncommon
because the terminating system call will typically discard everything
except the lower 8 bits of whatever is passed to it. In fact I
personally know of no exceptions. By the time PERL gets the data, the
system call will have truncated out most of what you were interested
in. You might ask why vendors try to stuff large software error
codes into 8-bit OS return values - well, we can only guess.
------------------------------
Date: Wed, 11 Jun 2003 10:52:09 +0200
From: Jean-Luc BEAUDET <beaudet@cyber.kodak.com>
Subject: Re: Do yu know abetter way to do it ?
Message-Id: <3EE6EDB9.9070906@cyber.kodak.com>
--------------080100010401070406010705
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
John W. Krahn wrote:
>>
>
>my $search_pattern = qr/@{[ sprintf '%s %s %2s \d{2}:\d{2}:\d{2} MEST 2003', @d7tt[0,2,1] ]}/;
>
>if ( $read_line =~ m/$search_patern/ ) {
>../..
>}
>
>
>John
>
John,
Thank yu very much for yur help.
As i'm still learning Perl, i'm not sure i can understand the whole of
yur code:
- the inside sprintf is OK.
But what about the construction with @{[../..]} ?
Could yu explain it to me ?
Best regards.
Jean-Luc B :O)
>
--------------080100010401070406010705
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<html>
<head>
</head>
<body>
<br>
<br>
John W. Krahn wrote:<br>
<blockquote type="cite" cite="mid:3EE64DF3.761E8C4C@acm.org">
<blockquote type="cite">
<pre wrap=""><br></pre>
</blockquote>
<pre wrap=""><!----><br>my $search_pattern = qr/@{[ sprintf '%s %s %2s \d{2}:\d{2}:\d{2} MEST 2003', @d7tt[0,2,1] ]}/;<br><br>if ( $read_line =~ m/$search_patern/ ) {<br>../..<br>}<br><br><br>John</pre>
</blockquote>
John, <br>
Thank yu very much for yur help.<br>
As i'm still learning Perl, i'm not sure i can understand the whole of yur
code:<br>
- the inside sprintf is OK.<br>
But what about the construction with @{[../..]} ?<br>
Could yu explain it to me ?<br>
<br>
Best regards.<br>
<br>
Jean-Luc B :O)<br>
<br>
<blockquote type="cite" cite="mid:3EE64DF3.761E8C4C@acm.org">
<pre wrap=""><br></pre>
</blockquote>
<br>
</body>
</html>
--------------080100010401070406010705--
------------------------------
Date: Wed, 11 Jun 2003 01:09:47 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Help!
Message-Id: <3EE68133.2070401@rochester.rr.com>
marcusNM wrote:
> I have no idea about perl... all I know is that I need a script that
> will create a random custom serial number for the vb6 program that I
----------------^^^^^^
> created... it will need to have a index file so it doesn't repeat any
--------------------------------------------------^^^^^^^^^^^^^^^^^
Hmmmm...random numbers might repeat. If they couldn't, they wouldn't
truly be random. I'm not sure what the purpose of your "serial number"
is. If you just want a unique number, start with 1 and count up each
time you generate one. If you want a unique number which is obfuscated
enough so that the probability someone will generate it accidentally on
purpose is very low, generate a random number and insert your counter
somewhere in it. The random number is obfuscating garble; the counter
is the actual serial number.
> serial numbers. I'll try to give you a basic idea of how it should work:
>
> 1) Person buys my program (but they can't use it until they register)
> 2) Person goes to my website to register
> 3) Perl Program creates custom serial number under the Person's name
> 4) My program searches my website for the Person's name (ie.
> johnsmith.sn) and opens it for the serial number
Hmmmm...that doesn't sound good. If I understand you correctly, you
could only have one John Smith as a customer? Duplicate names abound,
so you'd better have a better customer ID than that.
...
> Marcus
>
--
Bob Walton
------------------------------
Date: Wed, 11 Jun 2003 08:28:54 +0100
From: "Julian Scarfe" <julian@avbrief.com>
Subject: Re: How to I arrange for a socket connection to time out?
Message-Id: <WSAFa.7683$0d7.225489@newsfep4-glfd.server.ntli.net>
"John Brock" <jbrock@panix.com> wrote in message
news:bc2941$g8c$1@panix2.panix.com...
> I am using Perl to write a client module which communicates with
> a server through a socket connection. I want the client to time
> out the socket connection if the server does not respond within,
> let's say, 60 seconds, and I am trying to figure out the correct
> and idiomatic Perl way to do this. (I also want this to be portable,
> since the client needs to run on both Unix and Windows NT).
Strongly recommend you get hold of Lincoln Stein's "Network Programming with
Perl". While I cannot guarantee that it has a recipe for this particular
problem, it covers issues like this in useful depth.
Julian Scarfe
------------------------------
Date: Wed, 11 Jun 2003 03:12:11 GMT
From: Gerard Lanois <gerardlanois@netscape.net>
Subject: How to make write()/format behave more like Text::Wrap?
Message-Id: <uadcpjooe.fsf@netscape.net>
#! /usr/bin/perl -w
use strict;
# I have some text that looks like this.
my $text = "Xxx xxxxxxxxx xxxx xxxx xxxxxx xxxxxxx xxx xx x ".
"xxxxxx. Xxx xxxx xx xxxxxx xxxxxxxxx xxxx xxxx xxxx x xxxxx. ".
"Xxx xxxxxxx xxxx xxxx xxxx xxxxx xxx XXXXXXXXX_XXX_XXXX xxxxxxxxxx ".
"xxxxxxx, xxx xxx xxxxxxxxx xxxx XXXXXXX xx.\cM\cJXxx xxxx ".
"xxxx\cM\cJXxxxxxxx XX 1234567890, Xxxxxx XXXXX12345678";
# If you omit the following statement, write()/format quits when it
# sees the first \cM. Not desireable; I want write()/format to
# process my entire string.
$text =~ s/\cM\cJ/\cJ/g;
# I want to wrap my text to fit within 76 columns, indented 4 columns
# on the left, but still obey any embedded newlines. This code does
# exactly what I want:
use Text::Wrap qw(wrap $columns);
$columns = 72;
map { print(' ' x 4, $_, "\n"); } split(/\n/, wrap('', '', $text));
print "--\n";
# This works too.
$~ = 'FORMAT1';
foreach my $t (split(/\n/, $text)) {
write;
format FORMAT1 =
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
$t
.
}
print "--\n";
# Is it possible to configure a format statement in such a way to achieve
# the output produced above by previous two examples but using only a
# single call to write()?
# This doesn't work, it throws away my newlines:
$~ = 'FORMAT2';
write;
format FORMAT2 =
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
$text
.
# Another approach: is there a way to tell write()/format not to throw away
# embedded newlines?
# Is there a way to configure either Text::Format or Text::Autoformat
# to do this? I made one attempt at each of those but was not able
# to get either one to do what I wanted.
# I tried twiddling the contents of $: to no avail. Does someone know
# a magic $: configuration to achieve what I want?
# Thanks in advance,
# -Gerard
------------------------------
Date: 10 Jun 2003 18:22:51 -0700
From: danparker276@yahoo.com (Krusty)
Subject: IIS running perl scripts with VB not working
Message-Id: <f4a9a3fc.0306101722.24fbff3c@posting.google.com>
On computer B, and C IIS win 2000 server, my script exits without
really running. Or the file I pipe to gets 0 bytes.
If I use a basic exe files, I do get output.
I pretty sure my security setting on both IIS systems are identical.
Or as far as I can tell. Are there any i should really check again?
My exe file accesses other websites / works as a crawler.
On thing I noticed on my computer is if I, put a perl dll file in the
same directory on computer A it fails. (it has activestate installed)
I'm using pp compiler, but perl2exe doesn't work either.
I just installed service pack 3 on 1 of them? Is there a difference
in VB IIS there?
------------------------------
Date: 11 Jun 2003 05:26:11 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Indenturing words into lists
Message-Id: <slrnbedfbj.or2.damian@puma.qimr.edu.au>
On 10 Jun 2003 09:15:51 -0700, slash said:
>I am new to Perl and am trying to come up with an indentured list for
>my following output of another program, which uses the following
>segment (thanks to Jay Tilton's earlier posting)
<snip>
>the output is essentially two columns of words. What I am trying to
>get is the following:
>
>2002
> patent
> system
<snip>
>Any suggestions would be greatly appreciated!
Assuming the output you provided as the input:
#!perl
use strict;
use warnings;
my %rec;
while (<DATA>) {
chomp;
my ($lhs, $rhs) = split;
push @{$rec{ $lhs }}, $rhs;
}
{
local $"="\n\t";
print "$_\n\t@{$rec{$_}}\n" for sort keys %rec;
}
__DATA__
2002 patent
2002 system
4 equal
4 each
4 equal
4 on
4 june
4 2002
a having
a d
a second
a d
a signal
a d
abstract 2002
abstract physical
abstract architectures
abstract digital
abstract cells
abstract device
------------------------------
Date: Wed, 11 Jun 2003 08:16:40 GMT
From: Ian Gil <i@NOSPAMALLOWED.com>
Subject: Inverse match on command line?
Message-Id: <slrnbedmvh.kj5.i@jal.net>
Anyone know how to make the following command line match every paragraph
EXCEPT those that match "pattern"?
perl -00ne'/pattern/ && print' file.txt
Ian
------------------------------
Date: Wed, 11 Jun 2003 08:24:57 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Inverse match on command line?
Message-Id: <Xns93976995EDD46elhber1lidotechnet@62.89.127.66>
Ian Gil wrote:
> Anyone know how to make the following command line match every paragraph
> EXCEPT those that match "pattern"?
>
> perl -00ne'/pattern/ && print' file.txt
Change && to ||.
--
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Wed, 11 Jun 2003 07:42:41 GMT
From: me@there.com (Phil)
Subject: Re: Mac and Line Breaks
Message-Id: <3ee6dd5d.1544921@news.t-online.de>
On 10 Jun 2003 23:52:29 GMT, Martien Verbruggen
<mgjv@tradingpost.com.au> wrote:
>On Tue, 10 Jun 2003 23:06:16 GMT,
> Phil <me@there.com> wrote:
>> I want to read a text file written on MAC.
>
>And, I assume, this is on another platform?
>
>> When I try to read it in a hash list, it seems to be only one line!
>
>The best way to make sure that that works, is to make sure that you
>transfer text files between the various platforms in such a way that
>local end-of-line conventions get automatically translated. If that is
>not possible, because you mounted a file system remotely, or something
>like that, set $/ to the end-of-line character of a MAC file.
>
>Read the section on newlines in the perlport documentation for an
>understanding of what's going on.
>
>> How can I read this file in my perl script, that I have all lines?
>>
>> I read it in this way:
>>
>> open(fHANDLE,"<news.txt");
>
>You should always check that this succeeds.
>
>> @myList = <fHANDLE>;
>> close(fHANDLE);
>
>I'd do something like this:
>
>open FH, $file or die "Couldn't open '$file' for reading: $!";
>$/ = "\015";
>binmode FH;
>chomp(my @lines = <FH>);
>close FH;
>
>The binmode() is probably not necessary, but I like to be explicit
>about when I am working with non-text files. The chomp is there to get
>rid of the non-native line endings.
>
>If you need to open other text files, it's probably best to localise
>the $/ value change.
>
>Martien
>--
> |
>Martien Verbruggen | Useful Statistic: 75% of the people make up
>Trading Post Australia | 3/4 of the population.
> |
Thank you very much!!
it works :)
-Phil
------------------------------
Date: Wed, 11 Jun 2003 02:59:01 GMT
From: Greg Miller <gmiller@NOTforSPAM.gregmiller.net>
Subject: Re: need the ascii set for arrow down
Message-Id: <0m6devsrf1b0k2cas3cgve5ksc8hkfk7cl@4ax.com>
On 10 Jun 2003 05:30:57 -0700, gerard.maloney@intel.com (gerrym)
wrote:
>I have aq ascii menu on a linux box which uses the arrow up and down
>to nagivate the menus.
>I want to automate it using Perl Expect.pm, but I cannot find the
>character set I need to send.
The arrow keys do not have ASCII codes, you need to emulate
them based on the terminal you're using. This link should do it:
http://www.geocities.com/SiliconValley/Campus/7071/vtcodes.html
Greg Miller (gmiller at gregmiller dot net)
http://www.gregmiller.net
http://www.net-chess.com
------------------------------
Date: Wed, 11 Jun 2003 01:34:09 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Perl Matrix Filter Module like in Excel?
Message-Id: <3EE686E9.7020304@rochester.rr.com>
Dennis@NoSpam.com wrote:
...
> Suppose I have a matrix with 30 columns and 5000 rows.
>
> Each row represents a different case calculation and each column represents a
> specific calculation. For instance Column A is the case #, Column B is the
> standard deviation(std) of that case, Column C is the average (ave) of that case
> and so forth with the other columns.
>
> What I'd like to do in perl is create another matrix with the same columns but
> whose rows satisfy some column criteria. As an example I'd like to find all the
> rows whose Column B std is in the bottom 10% of all 5000 std's in that column
> AND whose Column C ave is in the Top 10% of all 5000 ave's in the ave column.
>
> This will create a new matrix with 30 columns and anywhere from 0 to N rows
> where N<5000.
>
> I don't care to display this new filtered matrix but I would like to save it or
> write it to a new file.
>
> Any perl modules that handles matrix filter manipulations like above.?
Well, I don't know about modules, but something like the following
should do the basic job:
use Data::Dumper;
use strict;
use warnings;
my $matrix=[['col1',13 ,'col3'],
['abc' ,23 , 'ghi'],
[23, 42, 19],
[10, 39, 'foo'],
];
print Dumper($matrix);
my $newmatrix=[];
for(@$matrix){ #go through rows of $matrix
next unless $$_[1]>35; #reject undesired condition
#reject some other undesired condition
push @$newmatrix,$_; #save desired row
}
print Dumper($newmatrix);
...
> Dennis
...
--
Bob Walton
------------------------------
Date: Tue, 10 Jun 2003 22:01:47 -0500
From: "Driver" <betsamaarcra@mindspring.com>
Subject: Re: Perl Matrix Filter Module like in Excel?
Message-Id: <bc66dr$l5o$1@slb0.atl.mindspring.net>
Before I go on, do you care about the output's application? Do you want it
in XML, for example?
<Dennis@NoSpam.com> wrote in message
news:eedcevot5dpfnba2fmtkpkve1rqbq0clkr@4ax.com...
> Thanks Ted here is a more concrete example.
>
> Suppose I have a matrix with 30 columns and 5000 rows.
>
> Each row represents a different case calculation and each column
represents a
> specific calculation. For instance Column A is the case #, Column B is
the
> standard deviation(std) of that case, Column C is the average (ave) of
that case
> and so forth with the other columns.
>
> What I'd like to do in perl is create another matrix with the same columns
but
> whose rows satisfy some column criteria. As an example I'd like to find
all the
> rows whose Column B std is in the bottom 10% of all 5000 std's in that
column
> AND whose Column C ave is in the Top 10% of all 5000 ave's in the ave
column.
>
> This will create a new matrix with 30 columns and anywhere from 0 to N
rows
> where N<5000.
>
> I don't care to display this new filtered matrix but I would like to save
it or
> write it to a new file.
>
> Any perl modules that handles matrix filter manipulations like above.?
>
> Thanks.
>
> Dennis
>
>
> Ted Zlatanov <tzz@lifelogs.com> wrote:
>
> >On Tue, 10 Jun 2003, Dennis@NoSpam.com wrote:
> >> In Excel VBA you can filter any column of the spreadsheet, with
> >> commands like top 10% of column A and bottom 5% of column B and only
> >> thus rows that satisfy both conditions will show.
> >>
> >> Is there a perl module that can do the same thing?
> >
> >Perl can limit the data retrieved from a source to any percentage you
> >want, but displaying that data is not built into Perl the way Excel
> >does it.
> >
> >Ask a more specific question, with sample data and what you're trying
> >to do, and we can help you better.
> >
> >Ted
>
------------------------------
Date: Tue, 10 Jun 2003 22:30:12 -0500
From: Dennis@NoSpam.com
Subject: Re: Perl Matrix Filter Module like in Excel?
Message-Id: <dt7dev4dinoup175869gs307cs5ihsi3rl@4ax.com>
The output should be in row form. That is each row of the output should have 30
columns as in the original. The columns data in each row should be separated by
a comma or some other common seperator. e.g. text file or csv file.
The reason I'm turning to perl is that I read, filter and write (append) about
40 to 80 of these files. The filtered output can be 1000+ rows. With 80 files
the final output file is around 80,000+ rows. Excel can only handle 65000 rows
and VBA is very slow. So I thought I'd use perl to generate that 80,000 row
file and then use perl again to sort the new file and perform some more
operations on the new file generating a third and final file.
Thanks.
"Driver" <betsamaarcra@mindspring.com> wrote:
>Before I go on, do you care about the output's application? Do you want it
>in XML, for example?
>
>
><Dennis@NoSpam.com> wrote in message
>news:eedcevot5dpfnba2fmtkpkve1rqbq0clkr@4ax.com...
>> Thanks Ted here is a more concrete example.
>>
>> Suppose I have a matrix with 30 columns and 5000 rows.
>>
>> Each row represents a different case calculation and each column
>represents a
>> specific calculation. For instance Column A is the case #, Column B is
>the
>> standard deviation(std) of that case, Column C is the average (ave) of
>that case
>> and so forth with the other columns.
>>
>> What I'd like to do in perl is create another matrix with the same columns
>but
>> whose rows satisfy some column criteria. As an example I'd like to find
>all the
>> rows whose Column B std is in the bottom 10% of all 5000 std's in that
>column
>> AND whose Column C ave is in the Top 10% of all 5000 ave's in the ave
>column.
>>
>> This will create a new matrix with 30 columns and anywhere from 0 to N
>rows
>> where N<5000.
>>
>> I don't care to display this new filtered matrix but I would like to save
>it or
>> write it to a new file.
>>
>> Any perl modules that handles matrix filter manipulations like above.?
>>
>> Thanks.
>>
>> Dennis
>>
>>
>> Ted Zlatanov <tzz@lifelogs.com> wrote:
>>
>> >On Tue, 10 Jun 2003, Dennis@NoSpam.com wrote:
>> >> In Excel VBA you can filter any column of the spreadsheet, with
>> >> commands like top 10% of column A and bottom 5% of column B and only
>> >> thus rows that satisfy both conditions will show.
>> >>
>> >> Is there a perl module that can do the same thing?
>> >
>> >Perl can limit the data retrieved from a source to any percentage you
>> >want, but displaying that data is not built into Perl the way Excel
>> >does it.
>> >
>> >Ask a more specific question, with sample data and what you're trying
>> >to do, and we can help you better.
>> >
>> >Ted
>>
>
------------------------------
Date: Tue, 10 Jun 2003 22:36:37 -0500
From: Dennis@NoSpam.com
Subject: Re: Perl Matrix Filter Module like in Excel?
Message-Id: <fk8dev4vneq5dahnfrpfh22q0jdr8hpdlu@4ax.com>
Bob thanks for your reply.
However I need to find the bottom 10% of column B. Column B of the matrix has
5000 elements. I need to find the 500th (10% of 5000)bottom element of Column B
and the 500th top element of Column C before I can go through the rows one by
one to see if the column B elements<=#500thB AND Column C element>+#500thC
Bob Walton <bwalton@rochester.rr.com> wrote:
>Dennis@NoSpam.com wrote:
>
>...
>
>
>> Suppose I have a matrix with 30 columns and 5000 rows.
>>
>> Each row represents a different case calculation and each column represents a
>> specific calculation. For instance Column A is the case #, Column B is the
>> standard deviation(std) of that case, Column C is the average (ave) of that case
>> and so forth with the other columns.
>>
>> What I'd like to do in perl is create another matrix with the same columns but
>> whose rows satisfy some column criteria. As an example I'd like to find all the
>> rows whose Column B std is in the bottom 10% of all 5000 std's in that column
>> AND whose Column C ave is in the Top 10% of all 5000 ave's in the ave column.
>>
>> This will create a new matrix with 30 columns and anywhere from 0 to N rows
>> where N<5000.
>>
>> I don't care to display this new filtered matrix but I would like to save it or
>> write it to a new file.
>>
>> Any perl modules that handles matrix filter manipulations like above.?
>
>
>Well, I don't know about modules, but something like the following
>should do the basic job:
>
> use Data::Dumper;
> use strict;
> use warnings;
> my $matrix=[['col1',13 ,'col3'],
> ['abc' ,23 , 'ghi'],
> [23, 42, 19],
> [10, 39, 'foo'],
> ];
> print Dumper($matrix);
> my $newmatrix=[];
> for(@$matrix){ #go through rows of $matrix
> next unless $$_[1]>35; #reject undesired condition
> #reject some other undesired condition
> push @$newmatrix,$_; #save desired row
> }
>
> print Dumper($newmatrix);
>
>
>...
>
>
>> Dennis
>...
------------------------------
Date: 11 Jun 2003 04:41:51 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Perl Matrix Filter Module like in Excel?
Message-Id: <slrnbedcom.115.mgjv@verbruggen.comdyn.com.au>
[Please, in the future, put your reply _after_ the suitably trimmed
text you reply to. This is the convention on this newsgroup, and
usenet in general. Thank you]
[TOFU fixed]
On Tue, 10 Jun 2003 14:59:35 -0500,
Dennis@NoSpam.com <Dennis@NoSpam.com> wrote:
> Ted Zlatanov <tzz@lifelogs.com> wrote:
>
>>On Tue, 10 Jun 2003, Dennis@NoSpam.com wrote:
>>> In Excel VBA you can filter any column of the spreadsheet, with
>>> commands like top 10% of column A and bottom 5% of column B and only
>>> thus rows that satisfy both conditions will show.
>>>
>>> Is there a perl module that can do the same thing?
>>
>>Perl can limit the data retrieved from a source to any percentage you
>>want, but displaying that data is not built into Perl the way Excel
>>does it.
>>
>>Ask a more specific question, with sample data and what you're trying
>>to do, and we can help you better.
> Thanks Ted here is a more concrete example.
>
> Suppose I have a matrix with 30 columns and 5000 rows.
>
> Each row represents a different case calculation and each column
> represents a specific calculation. For instance Column A is the
> case #, Column B is the standard deviation(std) of that case, Column
> C is the average (ave) of that case and so forth with the other
> columns.
That sounds more like a database table to me. Especially, since you
want to do...
> What I'd like to do in perl is create another matrix with the same
> columns but whose rows satisfy some column criteria. As an example
> I'd like to find all the rows whose Column B std is in the bottom
> 10% of all 5000 std's in that column AND whose Column C ave is in
> the Top 10% of all 5000 ave's in the ave column.
If you had the information in a database table, this would be a
reasonably simple SQL statement, or set of statements (depending on
the RDBMS you use).
I'm assuming that by "in the bottom 10%" you mean that if you sorted
the table by that field, the first 500 records would be eligible?
> This will create a new matrix with 30 columns and anywhere from 0 to
> N rows where N<5000.
If you really want matrices, and you want performance, you should look
into the PDL. It's got loads of tools to manipulate matrices and
vectors, including some that can do what you want.
In pure Perl, you have some programming to do. I'd probably get the
sets for each criterion, and then take the intersection of those sets,
probably using the case # as a unique id.
> Any perl modules that handles matrix filter manipulations like above.?
PDL will make your life easier, and certainly faster.
Here's a straight-forward implementation[1]. Note that the only data
that is duplicated in the various arrays are the references, not the
whole rows, i.e. no copies of the rows are made. Note that this has
not been written for efficiency.
However, this little prototype runs within 0.20 seconds of user time
on my machine, so unless you need to do many of these, or your array
is much larger than 5000 elements, I suspect this will suffice.
#!/usr/local/bin/perl
use strict;
use warnings;
# make this reproducible
srand(42);
my @data;
for my $i (1..5000)
{
# make up an array: id, average, deviation
push @data, [$i, 25 + rand(25), 1 + rand(10)];
}
# get the top 500 by average
my @avg_data = (sort { $b->[1] <=> $a->[1] } @data)[0..499];
# get the bottom 500 by deviation
my @dev_data = (sort { $a->[2] <=> $b->[2] } @data)[0..499];
# get the intersection of these two
my (%count, @sub_data);
foreach my $el (@avg_data, @dev_data)
{
push @sub_data, $el if ++$count{$el->[0]} > 1;
}
# Print them, sorted by id.
print "@$_\n" for sort { $a->[0] <=> $b->[0] } @sub_data;
For the next time, instead of just asking for code, it might be nice
if you showed us that you even tried to solve the problem yourself.
Martien
[1] Not tested, except to compile. If it's wrong, I'm sure someone
will fix it.
--
|
Martien Verbruggen | I used to have a Heisenbergmobile. Every time
Trading Post Australia | I looked at the speedometer, I got lost.
|
------------------------------
Date: Wed, 11 Jun 2003 03:50:00 GMT
From: "HongKongHooker" <sumguy@hooker.com>
Subject: Re: Regular expression
Message-Id: <IFxFa.114029$DV.128923@rwcrnsc52.ops.asp.att.net>
"Michael Budash" <mbudash@sonic.net> wrote in message
news:mbudash-28C212.16563710062003@typhoon.sonic.net...
> In article <slrnbecqeq.lbg.tadmc@magna.augustmail.com>,
> tadmc@augustmail.com (Tad McClellan) wrote:
>
> > Ian <iang@optonline.com> wrote:
> >
> > > Say I had the following input line:
> > >
> > > UPDATE=June 3, 2003 {maybe a time here or not} OS=5.7 MEMORY=512 MB
> > > {possibly more data following the KEY=VALUE notation.
> > >
> > > I would like to parse it so that I create a hash such that
> > >
> > > $hash{UPDATE} = "june 3, 2003....."
> > > $hash{OS} = "5.7"
> >
> >
> > > Can this be done as a single regex? if so how.
> >
> >
> > Assuming the input string is in $_:
> >
> > my %hash = /(\w+)=(.*?)(?=\s*\w+=|$)/g;
>
> nice...
>
.... I was gonna say that
------------------------------
Date: Wed, 11 Jun 2003 09:30:01 +0000
From: Garry Short <g4rry_short@zw4llet.com>
Subject: Re: stripping leading zeros thru multiple fields
Message-Id: <bc6peb$c1r$1$8300dec7@news.demon.co.uk>
Michael Budash wrote:
> In article <2855726c.0306100923.3d82edc@posting.google.com>,
> mfabache@yahoo.com (MF) wrote:
>
>> I've come up with the following (via searches and copying code) to
>> strip all leading zeros thru a date field, but I cannot figure how to
>> get to the 2nd field+
>>
>> Expected data: "06/06/2003"
>> Expected output: "6/6/2003"
>> Current output: "6/06/2003)" # How can I tweak this?
>>
>> Thanks,
>> Michael
>> ----
>>
>> use POSIX qw(strftime) ;
>> # $now_string = strftime "%m/%d/%Y", localtime;
>> $now_string = "06/06/2003"; # for testing porposies
>> print "$now_string\n";
>>
>> $now_string =~ s/0(\d+)/$1/; #strip leading zero off of MONTH, now
>> need DAY
>> print "$now_string\n";
>
> start with the g modifier on your substitution regex:
>
> $now_string =~ s/0(\d+)/$1/g; # 'g' for 'global'
>
> oh, but that affects the year, too:
>
> output: 6/6/203
>
> so let's be more specific:
>
> $now_string =~ s{0(\d+(/|$))}{$1}g;
>
> ahhh, there it is:
>
> output: 6/6/2003
>
$now_string =~ /0([0-9]\/)/$1/g;
will also do it, and is a much simpler regex to follow.
@now_array = qw(12/12/2002 01/10/2001 01/01/2000 10/03/1999);
foreach $now_string (@now_array) {
print "$now_string => ";
$now_string =~ s#0([0-9]/)#$1#g;
print "$now_string\n";
}
prints as follows:
garry@Castor:~> perl test.pl
12/12/2002 => 12/12/2002
01/10/2001 => 1/10/2001
01/01/2000 => 1/1/2000
10/03/1999 => 10/3/1999
Garry
------------------------------
Date: 11 Jun 2003 01:17:36 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: using Dumper to save hash and retrieving it.
Message-Id: <slrnbed0pn.115.mgjv@verbruggen.comdyn.com.au>
On Wed, 11 Jun 2003 00:34:53 GMT,
ktom <abc@nowhere.com> wrote:
> i have created a file using the Data::Dumper command..
>
> the command used was
> print OFILE Data::Dumper->Dump([\%pHash],['*xHash']);
>
> it created the file whose first few lines look like.
> %xHash = (
> '25' => {
> '1169' => {
> 'value' => '3.157',
> 'name' => 'PSSYNC_VOH'
> },
> '559' => {
>
> i am trying to retrieve is using the do (as suggested in the book) and
> having troubles. i have used the forms below and i haven't been able to
> access or print (using Dumper) the values that i thought i have brought in.
>
> #my $xHash = do $inFile2 || die "can't consume dbFile $inFile2\n";
> #%postHash = do $inFile2 || die "can't consume dbFile $inFile2\n";
> do $inFile2 || die "can't consume dbFile $inFile2\n";
Don't use ||, use or instead, or properly parenthesise the do. In
this specific case it makes no difference, but there are many other
expressions and functions where it does make a difference (like open()).
> print Dumper(%postHash);
> print Dumper(%{$xHash});
> print %xHash;
Have you made sure that the file that do is reading from is closed,
i.e. you're not reading from a file that has only been half flushed?
Have you attempted to inspect $! and $@ to see what the error might
be? It is generally very helpful to investigate what exactly is
causing the error. You did read the documentation on do in the
perlfunc manual page, right?
Is your %xHash lexically scoped (with my)? If so, take into account
that do EXPR can't work with lexicals. You need to make sure that
%xHash is a global (declare with our, or for old Perls with use vars).
Test data and code:
use strict;
use warnings;
use Data::Dumper;
my %pHash = (
'25' => {
'1169' => {
'value' => '3.157',
'name' => 'PSSYNC_VOH'
},
},
);
open OFILE, ">foo.hash" or die $!;
print OFILE Data::Dumper->Dump([\%pHash],['*xHash']);
close OFILE;
our %xHash;
my $rc = do "foo.hash";
die "can't consume dbFile foo.hash: ", $! || $@
unless defined $rc;
print Data::Dumper->Dump([\%xHash]);
For the next time, please create a small, self-contained, valid Perl
program that exhibits your problem when you have one (but do not
wildly post large slabs of code). Something as simple as the above
would do. At least that tells us what you did and how. There are
simply too many questions left that you haven't provided information
for. Code snippets never tell the full story.
Martien
PS If your input file can return undef from the last statement, you need
to change the test condition to include tests for $! and $@
--
|
Martien Verbruggen |
Trading Post Australia | What's another word for Thesaurus?
|
------------------------------
Date: Wed, 11 Jun 2003 09:23:52 +0100
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Re: virtual x server for Tk
Message-Id: <3EE6E718.5040001@bbsrc.ac.uk>
Chip wrote:
> "Darren Dunham" <ddunham@redwood.taos.com> wrote in message
> news:79oFa.2559$_P2.130646217@newssvr21.news.prodigy.com...
>
>>It is unclear to me from your post what your intention is. Do you want
>>to see TK output on the screen in front of you?
>
>
> Yes Darren, I am telneting ( or using ssh ) into a server from another
> box and want the display to be on the box I am in front of, not the server.
>
> I'm Using putty to telnet in from a windows box. I think your on
> the right track because I have seen referances to redirecting the
> display but that is where my problem is.
You still don't have enough running at your end to be able to do what
you want. In order to see graphics displayed on the remote machine you
need to have an X server running on your windows box. We use Exceed to
do this:
http://www.hummingbird.com/products/nc/exceed/index.html
..but a free alternative would be to install cygwin
(http://www.cygwin.com/) which includes an X server (XFree86).
Once you have your X server running locally the easiest thing to do is
to set up putty to use ssh rather than telnet to connect, and then in
the ssh options, tick the box which says "Enable X11 forwarding".
Your remote program should then be able to display on your windows box.
Hope this helps
Simon.
------------------------------
Date: 11 Jun 2003 02:47:30 -0700
From: magelord@t-online.de (Math55)
Subject: Why is the system call not working?
Message-Id: <a2b8188a.0306110147.31311b9@posting.google.com>
hello,
i wrote this system call with backticks:
`du -m -a ./|awk '{print $2 , $1}' > /tmp/all`;
it always gives me an parse error because of the ''. even if i try it like this:
`du -m -a ./|awk \'{print $2 , $1}\' > /tmp/all`; or
`du -m -a ./|awk {print $2 , $1} > /tmp/all`;
it does not work.
anyone who can help me?
THANKS!!!!!
------------------------------
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 5105
***************************************