[29153] in Perl-Users-Digest
Perl-Users Digest, Issue: 397 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 2 14:10:19 2007
Date: Wed, 2 May 2007 11:09:12 -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, 2 May 2007 Volume: 11 Number: 397
Today's topics:
Re: Access hash of hashes element problem. <justin.0704@purestblue.com>
Re: capturing STDOUT from and piped "into" program <tbrazil@perforce.com>
Re: capturing STDOUT from and piped "into" program xhoster@gmail.com
Re: Cat file a to *.xls files <grace.jim@gmail.com>
Re: Dynamic DNS management <nobull67@gmail.com>
Re: FAQ 4.46 How do I handle linked lists? <bik.mido@tiscalinet.it>
Re: FAQ 4.46 How do I handle linked lists? <brian.d.foy@gmail.com>
Re: hello world with perl <tadmc@augustmail.com>
Re: hello world with perl <scobloke2@infotop.co.uk>
Re: how to execute external file in script <glennj@ncf.ca>
ignorance and intolerance in computing communties <xah@xahlee.org>
perl out of memory xlue897@rogers.com
Re: perl out of memory <jurgenex@hotmail.com>
Re: perl out of memory <someone@example.com>
Re: perl out of memory <bik.mido@tiscalinet.it>
Re: perl Write filehandle blocks. <uri@stemsystems.com>
Re: perl Write filehandle blocks. xhoster@gmail.com
Re: Problem with Image::Info <rvtol+news@isolution.nl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 02 May 2007 11:27:59 -0000
From: Justin C <justin.0704@purestblue.com>
Subject: Re: Access hash of hashes element problem.
Message-Id: <slrnf3gtdv.fv3.justin.0704@stigmata.purestblue.com>
On 2007-05-01, Tad McClellan <tadmc@augustmail.com> wrote:
> Justin C <justin.0704@purestblue.com> wrote:
>> In article <CNKZh.7221$j63.3948@newsread2.news.pas.earthlink.net>, Mumia W. wrote:
>
>>> and the PRICES file is never explicitly closed by program.
>>
>> I'm sure I read here that file-handles are closed automatically when
>> they go out of scope,
>
>
> That is correct.
>
>
>> I've not bothered closing a file since.
>
>
> perl will always do what it is supposed to do, it is a machine...
>
>
>> Is this
>> bad?
>
>
> ... but that does not lead to the conclusion that the human telling
> perl what to do will do what _it_ is supposed to. :-(
>
> See my tale of woe from leaving out a close():
>
> http://groups.google.com/group/comp.lang.perl.misc/msg/73d4587743c64e2f
OK, point taken. Explicit close() added... now to grep the rest of what
I'd written and see how many have more open()s than close()s :)
Justin.
--
Justin C, by the sea.
------------------------------
Date: 2 May 2007 09:44:09 -0700
From: Tim <tbrazil@perforce.com>
Subject: Re: capturing STDOUT from and piped "into" program
Message-Id: <1178124249.007819.59760@n76g2000hsh.googlegroups.com>
On May 1, 2:48 pm, xhos...@gmail.com wrote:
> Tim <tbra...@perforce.com> wrote:
> > Hi
>
> > I've read a lot good info on this list about capturing STDOUT but I'm
> > still having a problems grasping it. I think I'm missing something. I
> > am trying to capture the output from the "$p4 $spectype -i" command
> > and place it in a $scalar. I know I can't redirect directly into a
> > scalar.
>
> > open(FULLSPEC,"|$p4 $spectype -i");
> > print FULLSPEC @fullspec;
> > close(FULLSPEC);
>
> One possibility, depending on what kinds of characters can exist in
> @fullspec, would be:
>
> my $output = `echo '@fullspec'|$p4 $spectype -i`;
>
> For portability and also for safety (WRT weird characters in @fullspec) you
> could use IPC::Open2, but you have to be careful to handle buffering to
> avoid deadlock. Deadlock should not be a problem either if $p4 reads all
> of the input before generating any output, or if join (" ", @fullspec) is
> small. On many systems, small means less than 4096 bytes.
>
> Perhaps a better answer would be IPC::Run:
>
> my ($out,$err);
> my $in=join " ", @fullspec;
>
> IPC::Run::run([$p4, $spectype, '-i'],\$in,\$out,\$err) or die $!;
>
> print $out;
>
> Xho
>
> --
> --------------------http://NewsReader.Com/--------------------
> Usenet Newsgroup Service $9.95/Month 30GB
Hi Paul and Xho
I really appreciate your responses. I initially tried Paul's solution.
It did indeed work on my OSX and Linux box. I was singing praises to
Paul but then I tried it on Windows XP with Activestate...
unfortunately it locked up.
I then went to try your solution.. It appears that IPC::Run is only
available in a separate package. I forgot to mention one detail ....
I'm attempting to write a perl benchmark test that customers could use
in their own perl environment without having them add additional
packages. :(
I'm using v5.8.5 on Linux and 5.8.8 Activestate on Windows. Knowing
what I just mentioned, any other ideas? Once again, thank you guys
VERY much for the info.
Tim
------------------------------
Date: 02 May 2007 17:10:14 GMT
From: xhoster@gmail.com
Subject: Re: capturing STDOUT from and piped "into" program
Message-Id: <20070502131015.882$DE@newsreader.com>
Tim <tbrazil@perforce.com> wrote:
> On May 1, 2:48 pm, xhos...@gmail.com wrote:
> > Tim <tbra...@perforce.com> wrote:
> > > Hi
> >
> > > I've read a lot good info on this list about capturing STDOUT but I'm
> > > still having a problems grasping it. I think I'm missing something. I
> > > am trying to capture the output from the "$p4 $spectype -i" command
> > > and place it in a $scalar. I know I can't redirect directly into a
> > > scalar.
> >
> > > open(FULLSPEC,"|$p4 $spectype -i");
> > > print FULLSPEC @fullspec;
> > > close(FULLSPEC);
> >
> > One possibility, depending on what kinds of characters can exist in
> > @fullspec, would be:
> >
> > my $output = `echo '@fullspec'|$p4 $spectype -i`;
> >
> > For portability and also for safety (WRT weird characters in @fullspec)
> > you could use IPC::Open2, but you have to be careful to handle
> > buffering to avoid deadlock. Deadlock should not be a problem either
> > if $p4 reads all of the input before generating any output, or if join
> > (" ", @fullspec) is small. On many systems, small means less than 4096
> > bytes.
> >
> > Perhaps a better answer would be IPC::Run:
> >
> > my ($out,$err);
> > my $in=join " ", @fullspec;
> >
> > IPC::Run::run([$p4, $spectype, '-i'],\$in,\$out,\$err) or die $!;
> >
> > print $out;
> >
> > Xho
> >
> > --
> > --------------------http://NewsReader.Com/--------------------
> > Usenet Newsgroup Service $9.95/Month 30GB
>
> Hi Paul and Xho
>
> I really appreciate your responses. I initially tried Paul's solution.
> It did indeed work on my OSX and Linux box. I was singing praises to
> Paul but then I tried it on Windows XP with Activestate...
> unfortunately it locked up.
How big was "@fullspec"? If it was big, then it maybe a buffering issue
that can solved with select. Even if it were not big, it still might be
one, but is likely.
> I then went to try your solution.. It appears that IPC::Run is only
> available in a separate package.
IPC::Run seems to be pure perl, and the source code is available, and thus
the source of it can be incorporated anywhere. I would assume its terms of
use would allow that, but I didn't check the license file--you should if
you want to use it that way. In any event, the ideas behind the package
are surely available to you.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 2 May 2007 06:24:28 -0700
From: Jim <grace.jim@gmail.com>
Subject: Re: Cat file a to *.xls files
Message-Id: <1178112268.830042.49580@c35g2000hsg.googlegroups.com>
On Apr 28, 12:57 am, Tad McClellan <t...@augustmail.com> wrote:
> Michael Carman <mjcar...@mchsi.com> wrote:
> > On 4/26/2007 5:54 PM, Tad McClellan wrote:
> >> Jim <grace....@gmail.com> wrote:
>
> >>> What I'm trying to do is to:
>
> >>> cat filea.txt to all .xls files in a directory
>
> >> No Perl needed, just use the shell!
>
> >> # untested
> >> for file in *.xls; do
> >> cat filea.txt >>$file
>
> > I think Tad has been hanging around Abigail too much lately.
>
> But when _I_ type of bunch of line noise, it never ends up
> being a Perl program. :-(
>
> --
> Tad McClellan SGML consulting
> t...@augustmail.com Perl programming
> Fort Worth, Texas
Thanks for your help. Works perfect!
------------------------------
Date: 2 May 2007 10:41:56 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: Dynamic DNS management
Message-Id: <1178127716.626367.296290@e65g2000hsc.googlegroups.com>
On May 2, 12:42 am, Nooze Goy <nooze...@pookmail.com> wrote:
> I'm in the process of setting up a web server - actually, it's pretty
> much working, just a few irritating things lurking about, occasionally
> leaping out and biting me on the arse.
>
> One of the irritations is that with a dynamic DNS, I'm having to update
> the IP addresses for the authoritative DNS server of multiple domains
> hosted here. They're on one DNS service, ZoneEdit, and I found a couple
> of pieces of code to update the IP addresses. One was ddclient, but
> before I could get the config debugged, I tried another - which is not
> so much a program as a command-line. It works okay, except that
> ZoneEdit's server is agonizingly slow to respond, so it takes ten or
> fifteen seconds to respond for each domain.
>
> wget -O - --http-user=mylogin --http-passwd=myp455
> 'http://dynamic.zoneedit.com/auth/dynamic.html?host=my.domain.com'
>
> In the script, the above line is repeated for each domain; each line
> takes ten or fifteen seconds to process - doesn't seem reasonable, butt
> hu nose?
>
> Obviously, with five or six domains, you're going to be hard-pressed to
> update the IP every minute,
Unless you spawn 5 or 6 wget commands at once.
> and with 20 domains you're basically looking
> at five solid minutes of updating anytime the ISP changes the IP, so it
> doesn't make any sense to update unless it's actually changed.
>
> I wrote a little Perl script to check the IP and log it and compare with
> last time it checked, and do the update only if the two don't match.
>
> It works fine right now - all it does is run a bash script of the
> command-line entries shown above. But, of course, it's still sllooowwwww
> as molasses.
> I'm assuming that there's some rational way to have my perl prog connect
> to the DNS update server directly,
There's Net::DNS if the server accepts standard DNS updates.
> and maybe a) that'll be faster
That's a question about dynamic.zoneedit.com
> or b)
> there's some way to update all the domains in the list either with one
> string
That is a question about the HTTP GET API presented at
http://dynamic.zoneedit.com/auth/dynamic.html
> or in a loop.
A loop would be no faster.
> So... here's the code - feel free to throw rocks at it, but it works...
> (barring typos - I'm looking at the code thru putty, and the copy and
> paste from a terminal window leave a lot to be desired)
I've never had any such problem with PuTTY.
> ####################################################
> #!/usr/bin/perl
Unless you enjoy pain:
use strict;
use warnings;
> use LWP::Simple;
In my experience LWP::Simple is only suited to run once and throw away
scripts. For anything else the small additional effort of using the
real LWP API pays off.
> $site = "http://checkip.dyndns.org";
> $var = get $site;
> $colloc = index($var,":");
> $ip = substr($var,$colloc+2,20);
> $angloc = index($ip,"<");
> $ip = substr($ip,0,$angloc);
Perl has very good pattern matching. Use it.
my ($ip) = get('http://checkip.dyndns.org') =~ /Current IP Address:
(.*?)</;
> open CURIP,">curip" or die "File does not exist, 'curip'";
Consider putting the actual error in the error message rather than an
random guess. Use the 3-arg open() unless you actually understand the
special legacy 2-arg form and require those semantics.
open CURIP,'>','curip' or die "$!, 'curip'";
> print CURIP "$ip";
See FAQ: What's wrong with always quoting "$vars"?
> close CURIP;
> open OLDIP,"oldip";
Use the 3-arg open() unless you actually understand the special legacy
2-arg form and require those semantics. Always check success.
> $oldip = <OLDIP>;
> close OLDIP
> if ( $oldip == $ip ) {
If you'd enabled warnings perl would have told you what's wrong with
that line (so I won't).
> # yep, yep... print "Look the same to me, too, ain't it???\n";
> }
> else
> { #update dns address - run script of
> # wget lines and replace old IP value
> system("./updns");
> system("cp -f curip oldip");
Wouldn't it make more sense to do away with the curip file and just
update the oldip file dirtectly from $ip at this point?
> }
> ###############################################
>
> What should I use to send the update info direct to ZoneEdit?
Well, if you want to stick to the HTTP GET API at
http://dynamic.zoneedit.com/auth/dynamic.html then you should simply
use LWP.
For an example of this download the example Perl script from the
dynamic.zoneedit.com site. (Like, duh!)
Note: this example script is not written in very good Perl.
If you want to do several requests in parallel then you could fork()
or use LWP::Parallel.
------------------------------
Date: Wed, 02 May 2007 11:42:24 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: FAQ 4.46 How do I handle linked lists?
Message-Id: <n7ng33lv7blnnu0alfv7lvsl28fgk8c7k3@4ax.com>
On 1 May 2007 15:29:59 -0700, Brad Baxter <baxter.brad@gmail.com>
wrote:
>> >s/Both pop and shift are both/Both pop and shift are/;
>>
>> s/(?<=Both pop and shift are) both//;
>
>:-)
>
>s/ both//;
# D'Oh!
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Wed, 02 May 2007 06:14:34 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 4.46 How do I handle linked lists?
Message-Id: <020520070614347531%brian.d.foy@gmail.com>
In article <p2df33d302rnj8g1o6eujbp07lk54jagdl@4ax.com>, Michele Dondi
<bik.mido@tiscalinet.it> wrote:
> On 1 May 2007 05:21:22 -0700, Brad Baxter <baxter.brad@gmail.com>
> wrote:
>
> >s/Both pop and shift are both/Both pop and shift are/;
>
> s/(?<=Both pop and shift are) both//;
fixed. Thanks, :)
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Wed, 2 May 2007 05:47:41 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: hello world with perl
Message-Id: <slrnf3gr2d.aue.tadmc@tadmc30.august.net>
Ian Wilson <scobloke2@infotop.co.uk> wrote:
> `perl -e "print qw(Hello World\n)"
^^ ^^
^^ ^^
ITYM "qq" instead of "qw".
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 02 May 2007 14:30:29 +0100
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: hello world with perl
Message-Id: <46389279$0$21844$db0fefd9@news.zen.co.uk>
Tad McClellan wrote:
> Ian Wilson <scobloke2@infotop.co.uk> wrote:
>
>
>> perl -e "print qw(Hello World\n)"
>
> ^^ ^^
> ^^ ^^
>
> ITYM "qq" instead of "qw".
>
>
Oops yes, thanks for the correction.
------------------------------
Date: 2 May 2007 13:09:56 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: how to execute external file in script
Message-Id: <slrnf3h3d4.i9s.glennj@smeagol.ncf.ca>
At 2007-05-01 08:58PM, "Petr Vileta" wrote:
> open IN,"<$file";
> my $sep=$/;
> undef $/;
> my $content = <IN>;
> close IN;
> our $variable = 'Nothing';
> eval $content;
can be expressed simply as: do $file;
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
------------------------------
Date: 2 May 2007 08:33:39 -0700
From: Xah Lee <xah@xahlee.org>
Subject: ignorance and intolerance in computing communties
Message-Id: <1178120019.271716.299590@e65g2000hsc.googlegroups.com>
Today, a motherfucker Christophe Rhodes (aka Xof in irc://chat.freenode.net=
/lisp
) kicked banned me.
Here's the few relevant excerpt. (full, unedited excerpt will be
published if there is a public interest)
Begin excerpt:
[5:31am] <xahlee> k, here is a simple problem but rather tedious to do
it correctly.
.=2E.
[5:32am] <xahlee> given a unit vector A=3D{a1,a2}, write a function
AngleA, such that it returns the positive angle from {1,0} to A.
[5:33am] <xahlee> mathematically this is simple, but to implement it
is rather cumbersome, with many if statements.
[5:34am] <xahlee> also, anyone who has implemented this will know trig
well.
[5:34am] <xahlee> i wonder if there's already in some library in lisp.
(i doubt it)
[5:36am] <pjb> xahlee: (acos (scalar-product A #(1 0)))
.=2E.
[6:34am] <xahlee> can anyone show me the source code of a function
that convert a complex number (a1 b2) to it's polar representation?
[6:35am] <Xof> (defun polarize (complex) (values (abs complex) (phase
complex)))
[6:35am] <Xof> wait, why am I replying to the troll?
[6:36am] <fax> :/
[6:36am] <Jasko> even the mighty Xof is not immune!
[6:36am] <tritchey> Xach: you were right, he HAS turned into mary
poppins.
[6:36am] <xahlee> well... what is the source code for your =E2=80=9Cphase=
=E2=80=9D?
[6:36am] <Xach> xahlee: it is, as kmp once said, given from god
[6:36am] <Xof> clhs phase
[6:36am] <specbot> http://www.lispworks.com/reference/HyperSpec/Body/f_phas=
e=2Ehtm
[6:36am] LiamH joined the chat room.
[6:36am] <fax> xahlee: you know enough maths to write an
impllementation
[6:36am] <froydnj> piso: ah...hmmm
[6:37am] <fax> xahlee: if its a CLHS function, then how its actually
written will be implementation specific
[6:37am] <fax> er CL not CLHS
[6:37am] <xahlee> as i described, i'm interested in the algorithm of
the implementation, not what it means.
[6:37am] <xahlee> =C2=ABcan anyone show me the source code of a function
that convert a complex number (a1 b2) to it's polar representation?=C2=BB
[6:37am] <Xof> all of that is true, but there's quite a good
suggestion for how to implement it on the page I got from specbot
[6:37am] <fax> xahlee: afaik there is no way to calculate it without
conditionals
[6:38am] <Xof> xahlee: and that's what you got
[6:38am] <fax> you can do 4 dot products, or atan.. however you do it
you have to handle cases
[6:38am] <xahlee> fax: thanks fax! only you come thru understand the
question and not being a troll.
[6:38am] <Xof> (atan y x)
[6:38am] <xahlee> the others so far, e.g. xof and pjb in particular,
just wanted to troll.
[6:38am] <Xof> look, ma, no conditionals
[6:38am] <fax> xahlee: more than just me gave you some info..
[6:39am] Xof was promoted to operator by ChanServ.
[6:39am] Xof set a ban on *!
*n=3Dxahlee@adsl-69-236-77-194.dsl.pltn13.pacbell.net.
[6:39am] You were kicked from the chat room by Xof. (now go away,
please)
------------------
Christophe Rhodes has unjustly kicked banned me about 3 times in the
past year in #lisp. Basically, making it impossible for me to use the
service provided by freenode.net in way. Today's incident, is actually
the most lenient. In the past ~3 times, he simply kick banned me
within few minutes i joined the #lisp channel.
Christophe Rhodes is one example of a power-struggling tech geeker in
the computing industry. Incidents like this, happens frequently in
just about all computer forums where almost all members are
exclusively male.
I want to bring this to the public attention (in this case, in the
lisp community). Because, it is motherfuckers like these, that does
society harm, and they all pretent to be saints and justice holders.
-------------------
Some notes about the math problem discussed in the topic:
As i have indicated in my post, it is non-trivial to implement a
function that returns the positive angle of a vector. For example, it
can be done with sign checking of the coordinate components (in total
4 cases, which can be done as 2 levels of nesting if, or simply 4
if.), and or the evaluation of Min[Abs[ArcCos[x],Abs[ArcSin[x]]], or
use clever ways with dot product, or ArcTan. It is not a trivial to
know which algorithm is in general more efficient. (this is important,
since finding the angle of a vector is a basic function, that may
needs to be called millions times directly or indirectly) Further,
consider the inverse trig function, it is likely 99.99% of people with
a PH D in math wouldn't know how these are actually implemented. So,
the question of whether calling one of the inverse trig function is
more robust or efficient than another is a open question. And, besides
the algorithmic level, the question also entails how the language
actually implement the inverse trig functions.
Besides efficiency concerns, there's also robustness concerns. For
example, if the 2 vectors are {1,0} and {0,1}, a simplistic
implementation will result in division by 0 or similar errors.
Checking whether one of them lies on the x or y axis means more if
statements, as well the non-trivial problem of determining if two
numbers are equal. (e.g. is 0.000001 considered equal to 0.0001 )
My interest in bringing this up for discussion, is because i'm writing
a program in Linden Scripting Language to generate a architecture of a
given polyhedral symmetry in Second Life (see http://xahlee.org/sl/index.ht=
ml
), and i need to write a function that returns the positive angle of 2
given vectors from A to B. I have implemented solution to this
problem a few times in Mathematica since about 1993. Being a
efficiency and perfection nerd with some leisure at the moment, i
thought i'd like to know more details about his problem. A optimal
implementation with respect to the algorithm level, or see how
languages implement the function that convert complex numbers to polar
form, or some general understanding and learning with regards to this
problem.
In a person's computing career, concrete and specialized questions
like these abound, and the answers or knowledge about them are scarce.
Due to the general ignorance of technical knowledge, and the power-
struggling nature of males, and the habit of intolerance and =E2=80=9Ctroll-
crying=E2=80=9D in computing communities, made it difficult to have any
sensible discussion of original questions that doesn't fit into some
elementary level of FAQs and concepts.
Asides from complainting about the person who unjustly kicked banned
me many times in the past year (which has happened to me in other irc
channels (in particular, #perl, #python, #emacs,...), mailing lists,
forums, as well happens all the time to many many others (every day in
just about every irc channel).), i hope that in general, tech geekers
be more tolerant and knoweledgable. In particular, aquire
understanding and communication from persons in society who are not in
the computing community.
For example, in newsgroups everyone is all concerned and involved
about the phenomenon of troll all day. To understand this more
seriously, study psychology, sociology, anhtropology, ethnology,
history. I do not mean getting interested and excited with a slashdot
news article then start to discuss it in your forum. But do, take a
class in community colleges, or if suitable, spare a reading of your
favorite science fiction for a text book on the these subjects. The so-
called =E2=80=9Ctroll=E2=80=9D (whatever it means), is a social, behavior p=
henomenon.
So, understanding social sciences is the proper way to understand it,
if necessary, learn how to remedy the situation. Not, for example, by
tech geeking with other tech geekers.
If you are, for example, interested in the comparative superiority of
computer languages that almost every tech geekers seem to know so much
about, then, try to take a course on the great many specific branches
of philosophy, the great branches and depths of (non-computer-
language) lingusitics, or the great depth and branches and specialties
and even philosophies of mathematical logic, or its history. Various
branches or trainings in philosophy will help you in critical
thinking, as well as aid you in seeing perspectives, philosophies, or
how to approach a problem with a good definition. Similarly,
linguistics will help you, in general, understand the concept or
theories of semantics or meaning and syntax and grammar, in a way that
can give you a independent and original thinking on the questions of
judging computing languages. Similarly, mathematical logic gives you a
extremely modern technical tool in evaluating or accessing the
problem. Spare a tech-geeking on a techincal book on your favorite
languages or computer language design book or latest computer
engineering practice guide or forum argumentation or wiki or Open
Sourcing zeitgeist fuck, to read a text book or learn on the above
topics.
Xah
xah@xahlee.org
=E2=88=91 http://xahlee.org/
------------------------------
Date: 2 May 2007 08:26:18 -0700
From: xlue897@rogers.com
Subject: perl out of memory
Message-Id: <1178119578.906292.105520@o5g2000hsb.googlegroups.com>
Hi,
I have a query to search the max number in a large size file. When I
use the perl code below, it generates error : Out of memory! Bus
error.
Perl Code:
perl -e '
for(<>)
{if ($_>$max){$max=$_;}}
print $max;'
<large_size_file
Also, can command line perl with -n run like awk -
'BEGIN{code}
{code}
END{code}
'
Thanks
Steven
------------------------------
Date: Wed, 02 May 2007 15:31:13 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: perl out of memory
Message-Id: <592_h.7628$YQ1.7396@trndny02>
xlue897@rogers.com wrote:
> Hi,
>
> I have a query to search the max number in a large size file. When I
> use the perl code below, it generates error : Out of memory! Bus
> error.
>
> Perl Code:
> perl -e '
> for(<>)
Replace 'for' with 'while'.
The magic of reading a line at a time works for 'while(<>)' only.
jue
------------------------------
Date: Wed, 02 May 2007 15:35:40 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: perl out of memory
Message-Id: <gd2_h.18$KN6.12@edtnps89>
xlue897@rogers.com wrote:
>
> I have a query to search the max number in a large size file. When I
> use the perl code below, it generates error : Out of memory! Bus
> error.
>
> Perl Code:
> perl -e '
> for(<>)
You are using a for loop so perl has to read the entire file first into a list
in memory. Use a while loop instead.
> {if ($_>$max){$max=$_;}}
> print $max;'
> <large_size_file
perl -lne'$max = $_ if $_ > $max; END { print $max }' large_size_file
> Also, can command line perl with -n run like awk -
> 'BEGIN{code}
> {code}
> END{code}
> '
Yes.
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
Date: Wed, 02 May 2007 19:21:35 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: perl out of memory
Message-Id: <k4ih33tsdmpgjanr4tpckin9ibje61ike4@4ax.com>
On Wed, 02 May 2007 15:31:13 GMT, "Jürgen Exner"
<jurgenex@hotmail.com> wrote:
>The magic of reading a line at a time works for 'while(<>)' only.
ATM! :-)
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Wed, 02 May 2007 06:43:39 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: perl Write filehandle blocks.
Message-Id: <x7lkg7ld44.fsf@mail.sysarch.com>
>>>>> "JS" == Joe Smith <joe@inwap.com> writes:
JS> perldoc IPC::Open2
JS> It's cases like this where the parent should fork two children:
JS> one that can block while writing to $WTR yet not preventing the other
JS> fork from reading from $RDR at the same time.
way too much work when an event loop in the parent can handle the open2
and more all by itself. your idea can still deadlock if the parent
doesn't manage correctly the i/o of the pair of children.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 02 May 2007 16:16:28 GMT
From: xhoster@gmail.com
Subject: Re: perl Write filehandle blocks.
Message-Id: <20070502121629.860$zL@newsreader.com>
Uri Guttman <uri@stemsystems.com> wrote:
> >>>>> "JS" == Joe Smith <joe@inwap.com> writes:
>
> JS> perldoc IPC::Open2
>
> JS> It's cases like this where the parent should fork two children:
> JS> one that can block while writing to $WTR yet not preventing the
> other JS> fork from reading from $RDR at the same time.
>
> way too much work when an event loop in the parent can handle the open2
> and more all by itself.
I have a hard time seeing how coding a simple fork is more work than
writing an event loop.
> your idea can still deadlock if the parent
> doesn't manage correctly the i/o of the pair of children.
Sure, and it is possible to code an event loop incorrectly.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Wed, 2 May 2007 11:08:40 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Problem with Image::Info
Message-Id: <f19rhf.1ec.1@news.isolution.nl>
Joe Smith schreef:
> print h1("No photo name specified") unless $Photo;
> print h1("File '$Photo' does not exist in this directory
> on the server") unless -f $Photo;
s/print/die/g
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V11 Issue 397
**************************************