[22443] in Perl-Users-Digest
Perl-Users Digest, Issue: 4664 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 5 00:05:40 2003
Date: Tue, 4 Mar 2003 21:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 4 Mar 2003 Volume: 10 Number: 4664
Today's topics:
Re: [REPOST] Using a (config) file relative to a module (Jay Tilton)
Re: Best way to learn perl? (Charles Blair)
Re: Best way to learn perl? <mgjv@tradingpost.com.au>
Can Perl can have the include head file like c? (Clark Zhong)
Re: Can Perl can have the include head file like c? <tony_curtis32@yahoo.com>
Re: Can Perl can have the include head file like c? <mgjv@tradingpost.com.au>
Re: Counter64 values returned by the Net::SNMP module <dgay@init0.org>
Re: DBD and DBI on Solaris 64 bit <makbo@pacbell.net>
Re: DBD and DBI on Solaris 64 bit <rereidy@indra.com>
exported constants, Win32::File <Joly.Patrick@ic.gc.ca>
Re: Greedy regexps <noreply@gunnar.cc>
Re: insert meta tags into an existing html file <jurgenex@hotmail.com>
Re: memory testing with Perl ctcgag@hotmail.com
Re: memory testing with Perl <penny1482@attbi.com>
Re: Moving on a grd. ctcgag@hotmail.com
Re: Moving on a grd. <mail@annuna.com>
parallelization of correlated nested loop ctcgag@hotmail.com
Re: parallelization of correlated nested loop <mgjv@tradingpost.com.au>
Re: Perl Mysql uploading a image in a database. ctcgag@hotmail.com
Re: Perl Mysql uploading a image in a database. <mgjv@tradingpost.com.au>
Re: Perl Script to Produce XML <hillmw@charter.net>
Re: Power status on laptop <bobx@linuxmail.org>
Re: Program Flow.. ctcgag@hotmail.com
Re: Shell commands <jurgenex@hotmail.com>
Re: Shell commands <REMOVEsdnCAPS@comcast.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 04 Mar 2003 23:10:10 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: [REPOST] Using a (config) file relative to a module location...
Message-Id: <3e6526eb.97244334@news.erols.com>
Michele Dondi <bik.mido@tiscalinet.it> wrote:
: OTOH the interpreter does
: know where a module is: it wouldn't do much harm IMHO to also set an
: $INC variable (local to a module), just as $ARGV is set when
: "processing" @ARGV...
I don't know how I missed this before, but the __FILE__ token is
exactly what you want the $INC variable to be.
You would still need the File::Basename or File::Spec to use its value
to access other files, but it cuts out the indirection needed by the
%ENV approach. The code wouldn't even need to know anything about its
filename. Replace dirname($INC{'foo.pm'}) with dirname(__FILE__)
and it can be copy/pasted anywhere it's needed.
Having '.' in @INC makes things just a little tricky. Invoking
chdir() would make a relative path useless. The rel2abs() function in
File::Spec could be useful here.
------------------------------
Date: Wed, 05 Mar 2003 03:21:52 GMT
From: c-blair@uiuc.edu (Charles Blair)
Subject: Re: Best way to learn perl?
Message-Id: <k3e9a.6280$o7.73249@vixen.cso.uiuc.edu>
I would suggest learning the easier parts of C, specifically
if-statements, for-statements, and while-statements (not structures
or pointers and not the details of printf and scanf), since perl
has borrowed these.
------------------------------
Date: Wed, 05 Mar 2003 04:23:15 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Best way to learn perl?
Message-Id: <slrnb6autj.1ir.mgjv@verbruggen.comdyn.com.au>
On Wed, 05 Mar 2003 03:21:52 GMT,
Charles Blair <c-blair@uiuc.edu> wrote:
> I would suggest learning the easier parts of C, specifically
> if-statements, for-statements, and while-statements (not structures
> or pointers and not the details of printf and scanf), since perl
> has borrowed these.
But they are also sufficiently diffeent not to use them as a complete
model of how things work in Perl. Apart from that, Perl has some
control structures that are not available in C, and that often create
more idiomatic Perl. I think, that if the OP is interested in learning
Perl only, it's probably better not to start at C.
I believe that the suggestion to get Andrew Johnson's book has already
been made in this thread, so I won't repeat it. :)
Martien
--
|
Martien Verbruggen | Little girls, like butterflies, need no
Trading Post Australia | excuse - Lazarus Long
|
------------------------------
Date: 4 Mar 2003 19:07:07 -0800
From: unixfighter@163.com (Clark Zhong)
Subject: Can Perl can have the include head file like c?
Message-Id: <265c2336.0303041907.68cd59c2@posting.google.com>
Hai, can anyone help me?
I want to include a config file in a main perl file, How can I do?
------------------------------
Date: Tue, 04 Mar 2003 21:09:41 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Can Perl can have the include head file like c?
Message-Id: <87of4qbjbe.fsf@limey.hpcc.uh.edu>
>> On 4 Mar 2003 19:07:07 -0800,
>> unixfighter@163.com (Clark Zhong) said:
> Hai, can anyone help me? I want to include a config
> file in a main perl file, How can I do?
what do you actually want to do? i.e. what problem are
you trying to solve? trying to squish a perl problem into
a C paradigm may not be the best way to go.
hth
t
------------------------------
Date: Wed, 05 Mar 2003 04:26:39 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Can Perl can have the include head file like c?
Message-Id: <slrnb6av3v.1ir.mgjv@verbruggen.comdyn.com.au>
On 4 Mar 2003 19:07:07 -0800,
Clark Zhong <unixfighter@163.com> wrote:
> Hai, can anyone help me?
> I want to include a config file in a main perl file, How can I do?
Look up (in the perlfunc documentation) do, require and use. Also have
a read of the perlmod documentation. It depends on what you want to do
exactly, which of these you should use. You are contradicting yourself
a bit by stating that you "want to include a config file", and
equating that with a "include head file like c". These two have
nothing to do with each other. Perl has no direct equivalent of a
C header file, but modules come closest. A "config file" is vague
enough to not be able to comment too much on that.
You should probably be more specific about what you want to achieve,
instead of assuming that you already know the emchanism by which you
would achieve it.
Martien
--
|
Martien Verbruggen |
Trading Post Australia | The gene pool could use a little chlorine.
|
------------------------------
Date: Wed, 05 Mar 2003 02:18:02 GMT
From: "Cox NNTP" <dgay@init0.org>
Subject: Re: Counter64 values returned by the Net::SNMP module
Message-Id: <u7d9a.114499$P1.7082807@news1.east.cox.net>
>
> I am using the Net::SNMP module v4.0.3 (with ActiveState Perl 5.6.1)
> to return, among other things, Counter64 values. But every such value
> is returned as either 0 or 9223372036854775808.
>
> (This is data defined by the Fiber Channel Management MIB, being
> returned by a McDATA SNMP Agent.)
>
> Obviously not all statistics counts will have exactly the same
> large value; so it looks like something is wrong here! Any ideas?
>
> I'm pulling the values straight out of the $session->var_bind_list
> hash.
>
Can you retrieve the values you would expect by using snmpget/walk (without
using the perl module)?
------------------------------
Date: Wed, 05 Mar 2003 01:31:40 GMT
From: makbo <makbo@pacbell.net>
Subject: Re: DBD and DBI on Solaris 64 bit
Message-Id: <3E65537B.2010807@pacbell.net>
I have a related question. I am a long time Perl and DBD::Oracle user
under various Unix systems. (I still remeber when oraperl was new...)
I downloaded gcc (current version) and successfully compiled it under
Solaris 8 64-bit.
I downloaded Perl 5.8 64-bit and successfully compiled it. I installed
Oracle 9i 64-bit and successfully compiled and installed DBI and
DBD::Oracle 64-bit.
A script using DBD::CSV to write out flat files from the database that
worked reasonably well under 32-bit Perl 5.6, Solaris 5.6, Oracle 8i,
now runs slow as a lame dog (i.e. triple the time) under the newer
64-bit environment (as stated above) -- all data items constant.
Any ideas? Anyone with similar experience?
Joe Smith wrote:
> In article <3E5B774D.5020905@indra.com>, Ron Reidy <rereidy@indra.com> wrote:
>
>>Rich wrote:
>>
>>>I am running Solaris 9 64 bit which comes with Perl v5.6.1 built for
>>>sun4-solaris-64int. I want to build in the DBD and DBI modules for
>>
>>Since you don't have a 64bit C compiler, dowload the 64bit gcc C
>>compiler from http://www.sunfreeware.com/, and rebuild Perl and all the
>>other modules you have installed.
>
>
> An important point, worth repeating, is that you need to use the same
> compiler for modules as the main program.
>
> That is, if you are going to be using gcc to compile the modules, then
> you need to compile perl from its sources.
>
> -Joe
------------------------------
Date: Tue, 04 Mar 2003 19:13:36 -0700
From: Ron Reidy <rereidy@indra.com>
Subject: Re: DBD and DBI on Solaris 64 bit
Message-Id: <3E655D50.2020409@indra.com>
I am going to go out on a limb here and guess the problem is with your
Oracle 9i instance. Have you:
1. Profiled the Perl code?
2. Used event 10046 to trace waits in the database?
I have runPerl 5.8.0 compiled to use 64 bit integers and DBI/DBD::Oracle
on 64 Bit Solais against 8i (64 bit), 9iR1, and 9iR2 and have not seen
these problems.
--
Ron Reidy
Oracle DBA
makbo wrote:
> I have a related question. I am a long time Perl and DBD::Oracle user
> under various Unix systems. (I still remeber when oraperl was new...)
>
> I downloaded gcc (current version) and successfully compiled it under
> Solaris 8 64-bit.
>
> I downloaded Perl 5.8 64-bit and successfully compiled it. I installed
> Oracle 9i 64-bit and successfully compiled and installed DBI and
> DBD::Oracle 64-bit.
>
> A script using DBD::CSV to write out flat files from the database that
> worked reasonably well under 32-bit Perl 5.6, Solaris 5.6, Oracle 8i,
> now runs slow as a lame dog (i.e. triple the time) under the newer
> 64-bit environment (as stated above) -- all data items constant.
>
> Any ideas? Anyone with similar experience?
>
> Joe Smith wrote:
>
>> In article <3E5B774D.5020905@indra.com>, Ron Reidy
>> <rereidy@indra.com> wrote:
>>
>>> Rich wrote:
>>>
>>>> I am running Solaris 9 64 bit which comes with Perl v5.6.1 built for
>>>> sun4-solaris-64int. I want to build in the DBD and DBI modules for
>>>
>>>
>>> Since you don't have a 64bit C compiler, dowload the 64bit gcc C
>>> compiler from http://www.sunfreeware.com/, and rebuild Perl and all
>>> the other modules you have installed.
>>
>>
>>
>> An important point, worth repeating, is that you need to use the same
>> compiler for modules as the main program.
>>
>> That is, if you are going to be using gcc to compile the modules, then
>> you need to compile perl from its sources.
>>
>> -Joe
>
>
------------------------------
Date: Tue, 4 Mar 2003 19:05:31 -0500
From: "Joly, Patrick: IAC" <Joly.Patrick@ic.gc.ca>
Subject: exported constants, Win32::File
Message-Id: <3E3612E8D41DD3118DCC060000000000096D65C1@pubgate-01.ic.gc.ca>
I can't seem to be able to read the constant that Win32::File reportedly
exports. For instance, when running the following script on Windows
2000 (I am using ActivePerl 5.8):
# Create a new file
use strict;
use warnings;
chdir "c:/";
# create a new file
open(DIR, ">newfile.txt") || die "can't open file";
print DIR "feed on line\nand another.";
close DIR;
# see if I can read its attributes
use Win32::File qw( GetAttributes SetAttributes );
my $attr;
GetAttributes('c:/newfile.txt', $attr);
print "$attr\n";
print NORMAL;
print ARCHIVE;
print COMPRESSED;
print DIRECTORY;
print HIDDEN;
print OFFLINE;
print READONLY;
print SYSTEM;
print TEMPORARY;
__END__
The output I get is:
Name "main::NORMAL" used only once: possible typo at test.pl line 16.
<snip>
32
print() on unopened filehandle NORMAL at test.pl line 16.
print() on unopened filehandle ARCHIVE at test.pl line 17.
print() on unopened filehandle COMPRESSED at test.pl line 18.
print() on unopened filehandle DIRECTORY at test.pl line 19.
print() on unopened filehandle HIDDEN at test.pl line 20.
print() on unopened filehandle OFFLINE at test.pl line 21.
print() on unopened filehandle READONLY at test.pl line 22.
print() on unopened filehandle SYSTEM at test.pl line 23.
print() on unopened filehandle TEMPORARY at test.pl line 24.
Anyone knows what I am doing wrong? Thanks
Patrick Joly, Economist
Industrial Analysis Centre, Industry Canada
Joly.Patrick@ic.gc.ca
------------------------------
Date: Wed, 05 Mar 2003 02:11:47 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Greedy regexps
Message-Id: <b43j4f$1rll31$1@ID-184292.news.dfncis.de>
I just had to understand... :)
Bigus wrote:
> I am parsing some HTML code in the following manner:
> [snip]
> $html =~ s/<td.+?class=\"*head1.*?>(.*?)<\/td>/###$1###/gi;
--------------------^^^
That's the 'problem'.
> Say the HTML reads:
>
> <table width="100%" border="0" cellspacing="0" cellpadding="0">
> <tr align="left">
> <td class="head1">FIRST HEADING</td>
> </tr>
> <tr align="left">
> <td class="body1">Some text.. blah blah</td>
> </tr>
> <tr align="left">
> <td class="head1">SECOND HEADING</td>
> </tr>
> <tr align="left">
> <td class="body1">Some more text.. waffle waffle</td>
> </tr>
> </table>
>
> After parsing with the above script, it comes out like this:
>
> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr
> align="left"> ###FIRST HEADING### </tr> <tr align="left"> ###SECOND
> HEADING### </tr> <tr align="left"> <td class="body1">Some more text.. waffle
> waffle</td> </tr></table>
>
> So, basically, what it's done is that the first match has swallowed up:
>
> </tr>
> <tr align="left">
> <td class="body1">Some text.. blah blah</td>
>
> which I obviously don't want it to do. Strangely, the last match works fine.
On the contrary: The first match works fine, i.e. '.+?' matches the
space between td and class. During the second match, '.+?' represents
the string
' class="body1">Some text.. blah blah</td> </tr> <tr align="left"> <td '
Accordingly, the result you reported is what can be expected.
/ Gunnar
P.S. Thanks Abigail and Tad for your clarifications. Nothing new to me,
actually, but like Spencer I first failed to apply it in this example.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 05 Mar 2003 03:15:22 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: insert meta tags into an existing html file
Message-Id: <eZd9a.68756$ep5.43668@nwrddc02.gnilink.net>
piet wrote:
> How do I insert new meta tags into an existing local html file?
Please see my answer in The Other NG.
I hope you still remember where you posted :-(
jue
------------------------------
Date: 04 Mar 2003 23:21:15 GMT
From: ctcgag@hotmail.com
Subject: Re: memory testing with Perl
Message-Id: <20030304182115.520$07@newsreader.com>
Ted Zlatanov <tzz@lifelogs.com> wrote:
> Has anyone written a memory tester using Perl? I don't mean something
> fancy, just to create an array of N elements and then verify the
> contents.
Yes, but not under that guise. The automated testers for almost
any module that deals with large amounts of data should implicitly
be memory testers, also.
> The key feature is that I'd like to know when the script
> has reached, let's say, 512MB of memory usage.
On linux, I do $size = (split ' ', `ps -p $$ -o rss `)[1] ;
to get the approximate memory size in kilobytes. I don't know what
you use on windows.
> I've assumed so far
> that every element is just a little larger than its contents
Very bad assumption. I've brought our server to it's knees on that
assumption before. (Tie::Cache can underestimate memory consumption
by a factor of 6 or more, if you have deep data structures with small
contents.)
> and added
> the contents up (ignoring the interpreter size, so I'm guaranteed to
> use at least that much memory), but I was wondering if there's a
> better way.
If I can make a function that fabricates "typical data" for your
application, then I do this:
my @data;
foreach (1..100_000) {
push @data, typical_data();
print scalar @data, "\t", (`ps -p $$ -o rss `)[1] unless @data % 1000;
};
You can then graph, regress, or just eyeball the output. Remember the
memory is in kb, not in bytes.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: Wed, 05 Mar 2003 00:13:02 GMT
From: "Dick Penny" <penny1482@attbi.com>
Subject: Re: memory testing with Perl
Message-Id: <iib9a.320263$tq4.7100@sccrnsc01>
> Ted Zlatanov <tzz@lifelogs.com> wrote:
> On linux, I do $size = (split ' ', `ps -p $$ -o rss `)[1] ;
Am sort of a newbie on a Win2K platform, I do recognize $$, it is in Perl
docs, but
what is ps
what is -p
what is -o
what is rss
and what does this whole string represent?
Thanks.
Dick Penny
------------------------------
Date: 04 Mar 2003 23:29:08 GMT
From: ctcgag@hotmail.com
Subject: Re: Moving on a grd.
Message-Id: <20030304182908.658$Es@newsreader.com>
Joe Creaney <mail@annuna.com> wrote:
> Again I am trying to write simple programs in perl and getting a little
> fustrated. I am trying to write a little demo program that will print
> out a grid
> *...
> ....
> ....
> ....
> I would like to be able to move the star around the grid. I realize
> that this is a text program and will have to re-print the grid after
> each move. Is there a place I could look up simmilar programs.
>
> I see lots of books on how to write the syntax of a language but very
> few on teaching how write programs.
I'm excerpting this from a program I wrote to solve the "pegged"
logic puzzle. HTH:
my $board = [ [qw/ x x o o o x x/],
[qw/ x x o o o x x/],
[qw/ o o o o o o o/],
[qw/ o o o . o o o/],
[qw/ o o o o o o o/],
[qw/ x x o o o x x/],
[qw/ x x o o o x x/] ];
print print_board($board);
sub print_board {
#returns a string representing the current state of the board.
my $string;
$string .= (join " ", @$_)."\n" foreach @{(shift)};
return $string;
};
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: Tue, 04 Mar 2003 21:36:57 -0600
From: Joe Creaney <mail@annuna.com>
Subject: Re: Moving on a grd.
Message-Id: <3E6570D9.1080800@annuna.com>
This is a multi-part message in MIME format.
--------------020800030704000403040404
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
I did some work on my idea. My problem is that I want to use a foreach
loop to print out the values of the array @grid. I immagine that I
could get the program to work if I use nested for i = 1 to 5 to print
out the arrays.
I have been playing with the program and it is realy buggs. I am still
working on it.
Here is the code:
ctcgag@hotmail.com wrote:
> Joe Creaney <mail@annuna.com> wrote:
>
>>Again I am trying to write simple programs in perl and getting a little
>>fustrated. I am trying to write a little demo program that will print
>>out a grid
>>*...
>>....
>>....
>>....
>> I would like to be able to move the star around the grid. I realize
>>that this is a text program and will have to re-print the grid after
>>each move. Is there a place I could look up simmilar programs.
>>
>>I see lots of books on how to write the syntax of a language but very
>>few on teaching how write programs.
>
>
> I'm excerpting this from a program I wrote to solve the "pegged"
> logic puzzle. HTH:
>
> my $board = [ [qw/ x x o o o x x/],
> [qw/ x x o o o x x/],
> [qw/ o o o o o o o/],
> [qw/ o o o . o o o/],
> [qw/ o o o o o o o/],
> [qw/ x x o o o x x/],
> [qw/ x x o o o x x/] ];
>
>
> print print_board($board);
>
> sub print_board {
> #returns a string representing the current state of the board.
> my $string;
> $string .= (join " ", @$_)."\n" foreach @{(shift)};
> return $string;
> };
>
> Xho
>
--------------020800030704000403040404
Content-Type: text/plain;
name="grd.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="grd.pl"
#! usr/bin/perl -w
my $c;
my $i;
my $ypos= "0";
my $xpos= "0";
sub pgrid {
my ($xp,$yp) = @_;
my $l;
my $l1;
my $cc;
my @grd=(
[ qw(. . . . . )],
[ qw(. . . . . )],
[ qw(. . . . . )],
[ qw(. . . . . )],
[ qw(. . . . . )],
);
print "Printing Grid \n";
while ($l < 5) {
while ($l1 < 5 ) {
if (($l == $xp) and ($l1 == $yp)) {
print "*"; } else {
print "$grd[$l],[$l1]"; }
$l1++;
}
print "\n";
$l++;
}
}
sub move {
my ($mi, $xm, $ym) = @_;
my %mov = (n => [ 0, -1], s => [ 0, 1], e => [1, 0], w => [-1, 0]);
$xm += $mov{$mi[0]};
$ym += $mov{$mi[1]};
if ($mx > 5)
{$mx=0;}
if ($mx < 0)
{$mx=5;}
if ($my > 5)
{$my=0;}
if ($my < 0)
{$my=5;}
return $mx, $my;
}
pgrid ($xpos,$ypos);
while ($i ne "q") {
print "Which way:";
$i=<STDIN>; chomp $i;
($i, $xpos, $ypos) = move($i, $xpos, $ypos);
pgrid ($xpos, $ypos);
}
print "You are done!";
--------------020800030704000403040404--
------------------------------
Date: 05 Mar 2003 01:59:06 GMT
From: ctcgag@hotmail.com
Subject: parallelization of correlated nested loop
Message-Id: <20030304205906.821$h1@newsreader.com>
I need to take an input of ~2e6 items, and find an output list
(I think it will be ~1e5 items) where each item already in the output
list can veto any new addition. It's easier explained in perl:
my @in=<IN>;
shuffle(\@in);
my @good;
OUTER: foreach my $prospect ( @in ) {
foreach my $good (@good) {
next OUTER if veto($good,$prospect) ;
};
push @good, $_
};
print join "\n", @good;
__END__
I want to make it faster.
I've inlined veto, but with no real gain.
I've re-wrote veto into an C xsub, which helped a lot but isn't enough.
I've used knowledge of the internal workings of veto and
the internal structure of $prospect to replace @good with a data structure
which allows me immediately skip 2/3 of @good, without needing
to call the costly veto() for those. (I still have to call it for the
remaining 1/3). But the overhead complexity eats much of the gains, and
even a perfect n fold improvement wouldn't be enough. Plus the complexity
makes other optimizations and/or maintenance difficult.
I've rewritten everything into C. That's not much better than having
just veto in C.
So now I want to parallelize it. (I have access to ~25 CPUs that act like
one SMP machine, at least regarding IPC). But this seems like a hard to
parallelize algorithm, as @good is needed everywhere and can be changed
everywhere.
My only idea so far is to break @good into two parts,
@base_good and @new_good, having slaves filter the input through
the (mostly static) @base_good to a master, and the master retest (and
possibly add) these filtered inputs into @new_good. Occasionally, the
master would "push @base_good, @new_good" and redistribute the new
@base_good out to the slaves.
Anyone see a better way to parallelize this in Perl with simple
forking methods? (I don't want to get into the business of doing parallel
programming in C, or shared memory in Perl, unless absolutely necessary).
My first inclination is to redistribute @base_good by having slaves die at
predetermined checkpoints and then fork new ones, to eliminate the need for
two-way communiation.
This leaves me with the problem if merging 25 input streams in an efficient
and non-corrupting (i.e. line-buffered) way. I couldn't find any CPAN
modules to do this. I don't think it would be too difficult to build a
line-buffering function over IO::Select or Parallel::Jobs, but I don't want
to do that if such already exists somehwhere. Am I overlooking some
module/feature?
Thanks for any help,
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: Wed, 05 Mar 2003 04:34:43 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: parallelization of correlated nested loop
Message-Id: <slrnb6avj4.1ir.mgjv@verbruggen.comdyn.com.au>
On 05 Mar 2003 01:59:06 GMT,
ctcgag@hotmail.com <ctcgag@hotmail.com> wrote:
> I need to take an input of ~2e6 items, and find an output list
> (I think it will be ~1e5 items) where each item already in the output
> list can veto any new addition. It's easier explained in perl:
>
>
> my @in=<IN>;
> shuffle(\@in);
>
> my @good;
>
> OUTER: foreach my $prospect ( @in ) {
> foreach my $good (@good) {
> next OUTER if veto($good,$prospect) ;
> };
> push @good, $_
> };
> print join "\n", @good;
>
> __END__
If you'd posted veto() and shuffle(), maybe people could suggest an
algorithm change to speed it up. Without those, it is going to be
impossible to say whether that double loop (over @in and @good) is
necessary, or whether it could be replaced with something else. It is
also impossible to say whether the process could be changed to read
line by line, instead of the whole file at once (maybe with a
post-process for the shuffle, whatever that is).
You're asking for suggestions on how to make this faster, but you
leave out the crucial information about the algortihm youre using, or
even about what veto() is doing.
Maybe, instead of @good, it would be better to keep a C-accessible
hash. hard to tell. But it surely smells like that to me.
Martien
--
|
Martien Verbruggen |
Trading Post Australia | values of Beta will give rise to dom!
|
------------------------------
Date: 04 Mar 2003 23:54:54 GMT
From: ctcgag@hotmail.com
Subject: Re: Perl Mysql uploading a image in a database.
Message-Id: <20030304185454.684$kv@newsreader.com>
niels_bond@hotmail.com (niels) wrote:
> Hello there,
>
> I'm trying to upload a image from a html form to a mysql database.
>
> For some reason i can't manage to do this right. Don't tell me to save
> the image in a directory and save a url in the database. I just don't
> want that.
>
> Here's the code:
>
> local $/=undef;
> $afbeelding=<$reclame_image>;#(Reclame_image is the variable from the
> form)
I'll assume this part is working, although you should probably
binmode it. You are not using strict, it looks like. Shame on
you.
>
> $afbeelding=$dbh->quote($afbeelding);
Don't do that.
> $sql="insert into imgarchief(image)values('$afbeelding')";
use place holders,
my $sth=$dbh->prepare(
"insert into imgarchief(image)values(?)"
);
> $sth=Execute_Query($sql);#just a sub that executes the query
Good lord, why? You write a single subroutine of your own to encapsulate
a single method call. Why not just use the method call itself? This
unnecessary proliferation of subroutines is the 2nd most annoying thing
my coworkers do. (2nd only to not using strict on large programs.)
> Sometimes, he saves the image right. sometimes i get an error.
What error?
> To show the image i use this.
>
> $reclame_imgno=shift;
>
> print "Content-Type: image/jpeg\n\n";
> print "$reclame_imgno";
You just printed some text into what is supposed to be a binary image
stream. (and also didn't binmode the stream.).
> my $reclamesth=Execute_Query("select image from imgarchief where
> img_id=$reclame_imgno");
Again with the Execute_Query? Again no place holders! Use them.
> while($return=$reclamesth->fetchrow)
> {
> print $return;
> }
Why would you expect to get more than one row back from the query?
If you did, why would you want to concatenate them altogether? I don't
think jpeg images work that way.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: Wed, 05 Mar 2003 00:20:44 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Perl Mysql uploading a image in a database.
Message-Id: <slrnb6agmr.1ir.mgjv@verbruggen.comdyn.com.au>
On 04 Mar 2003 23:54:54 GMT,
ctcgag@hotmail.com <ctcgag@hotmail.com> wrote:
> niels_bond@hotmail.com (niels) wrote:
>>
>> I'm trying to upload a image from a html form to a mysql database.
>> local $/=undef;
>> $afbeelding=<$reclame_image>;#(Reclame_image is the variable from the
>> form)
>
> I'll assume this part is working, although you should probably
> binmode it. You are not using strict, it looks like. Shame on
> you.
Not should (anymore). Must. Even on Unix platforms, you have to use
binmode to read binary data. Under perl 5.6.1 and before (on unix) it
probably will work, but under 5.8.0, leaving binmode off, even on unix
systems, can cause problems, due to the possible UTF-8 interpretation
of data, and depending on which PerlIO layers are active.
Martien
--
|
Martien Verbruggen | Useful Statistic: 75% of the people make up
Trading Post Australia | 3/4 of the population.
|
------------------------------
Date: Wed, 5 Mar 2003 03:33:01 -0600
From: "Michael Hill" <hillmw@charter.net>
Subject: Re: Perl Script to Produce XML
Message-Id: <v6aruoclc73pea@corp.supernews.com>
I fixed the header and still was getting another problem. Based on what I
saw on that Apache site I added to my .htaccess
file "AddHandler cgi-script .cgi" in my html directory.
So.... the same script xml.cgi runs in the /html directory, but not in the
/cgi-bin directory. Here are the links:
http://www.hulenbend.net/xml.cgi
http://www.hulenbend.net/cgi-bin/xml.cgi
Here is the cgi:
print "Content-type: text/xml; charset=utf-8\n\n";
print "<?xml:stylesheet type='text/xsl' href='ops_rev.xsl'?>\n";
print "<portfolio>\n";
print "<review>\n";
print "<id>1</id>\n";
print "<type>A</type>\n";
print "<title>A really Cool event</title>\n";
print "<e_start>2003-03-04</e_start>\n";
print "<e_end>2003-03-04</e_end>\n";
print "<t_date>2003-03-04</t_date>\n";
print "<orgs>10</orgs>\n";
print "<event_dol>100000</event_dol>\n";
print "</review>\n";
print "</portfolio>\n";
The cgi doesn't work.
Mike
"Peter Cooper" <newsfeed2@boog.co.uk> wrote in message
news:K%39a.12125$EN3.97111@newsfep4-glfd.server.ntli.net...
> Michael Hill wrote:
>
> > print "<?xml:stylesheet type='text/xsl' href='my.xsl'?>\n";
> <snip>
> > print "</portfolio>\n";
> >
> > I added a type to my .htaccess file in the cgi-bin directory thinking
that
> > was the problem.
> >
> > This same display below works fine in my html directory:
>
> Are you printing a Content-Type before sending the XML? If not, there's
your
> problem.
>
> Pete
>
>
------------------------------
Date: Wed, 05 Mar 2003 00:49:17 GMT
From: "Bob X" <bobx@linuxmail.org>
Subject: Re: Power status on laptop
Message-Id: <hQb9a.23412$0L3.9962584@news2.news.adelphia.net>
Quick Google search...and there may be others.
On a *nix laptop:
http://www.muppetlabs.com/~reaper/laptop/battmon.html
------------------------------
Date: 05 Mar 2003 00:35:52 GMT
From: ctcgag@hotmail.com
Subject: Re: Program Flow..
Message-Id: <20030304193552.195$Qv@newsreader.com>
Benjamin Goldberg <goldbb2@earthlink.net> wrote:
>
> Also.... You may have better performance if you could create the
> database connection in the parent, and set the InactiveDestroy
> attribute on the database handle in the child. That is:
Don't do that, it is a recipe for disaster. All the children would
be trying to talk to the database on the same connection. If you do that,
Oracle will slam the door in your face without comment, and mysql will get
very confused. I don't know specifically what ingres does, but I doubt it
is graceful. Each child that will talk to the database needs its own
connection.
Where InactiveDestroy comes in is if you want to have a connection
that persists *in the parent* across the $pm->start calls. In this case,
you need to set InactiveDestroy in each child (and swear to God that the
children won't do anything to that object other than set InactiveDestroy!).
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: Wed, 05 Mar 2003 03:19:40 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Shell commands
Message-Id: <g1e9a.68761$ep5.13002@nwrddc02.gnilink.net>
Andy wrote:
> This should be relatively straightforward but I'm having a tough time.
> I'm trying to use the copy command within a perl script, but I need
> to pass an option to the command as well. I basically need to execute
> the following (i'm on win32 but it works the same on unix):
>
> xcopy /S D:\scripts\somedir R:\somedir
Why are you forking a new process and calling an external program (not to
mention writing non-protable code) if there is a Perl solution?
use File::Copy;
jue
------------------------------
Date: Tue, 04 Mar 2003 22:04:18 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Shell commands
Message-Id: <Xns9334EA9D6915Asdn.comcast@216.166.71.239>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
"Jürgen Exner" <jurgenex@hotmail.com> wrote in news:g1e9a.68761$ep5.13002
@nwrddc02.gnilink.net:
> Andy wrote:
>> This should be relatively straightforward but I'm having a tough time.
>> I'm trying to use the copy command within a perl script, but I need
>> to pass an option to the command as well. I basically need to execute
>> the following (i'm on win32 but it works the same on unix):
>>
>> xcopy /S D:\scripts\somedir R:\somedir
>
> Why are you forking a new process and calling an external program (not to
> mention writing non-protable code) if there is a Perl solution?
>
> use File::Copy;
xcopy does a deep copy (recurses subdirectories). Afaik, File::Copy does
not do that.
- --
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPmV3ImPeouIeTNHoEQJkrwCg6MKjWwJgu2r3n0Lot0ow7hT+sKoAoPaK
p9JrJemAymGMJ4G/lXzxV2nq
=yRQs
-----END PGP SIGNATURE-----
------------------------------
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 4664
***************************************