[28575] in Perl-Users-Digest
Perl-Users Digest, Issue: 9939 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 7 14:05:43 2006
Date: Tue, 7 Nov 2006 11: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, 7 Nov 2006 Volume: 10 Number: 9939
Today's topics:
Re: Data plotting questions Nov. 2, 2006 <jgibson@mail.arc.nasa.gov>
Re: Huge Memory Load for reading into memory <tzz@lifelogs.com>
Re: Huge Memory Load for reading into memory <David.Squire@no.spam.from.here.au>
Re: Huge Memory Load for reading into memory xhoster@gmail.com
Newbie's easy question/answer - I hope <evillen@gmail.com>
Re: Newbie's easy question/answer - I hope <David.Squire@no.spam.from.here.au>
Re: Newbie's easy question/answer - I hope <jurgenex@hotmail.com>
Re: Newbie's easy question/answer - I hope <evillen@gmail.com>
Re: Newbie's easy question/answer - I hope <evillen@gmail.com>
Re: Newbie's easy question/answer - I hope <jurgenex@hotmail.com>
Re: Newbie's easy question/answer - I hope <evillen@gmail.com>
Re: Newbie's easy question/answer - I hope <mark.clementsREMOVETHIS@wanadoo.fr>
Re: Newbie's easy question/answer - I hope <David.Squire@no.spam.from.here.au>
Re: Newbie's easy question/answer - I hope <john@castleamber.com>
perl & lsof kind gmlvsk2@gmail.com
Re: process subregions on an image/matrix <alexxx.magni@gmail.com>
Re: process subregions on an image/matrix xhoster@gmail.com
Re: Putting a line in a specific place in a file <someone@example.com>
Re: Putting a line in a specific place in a file <bryan@worldspice.net>
Regular expressions <newsmanDELETE@REMOVEdahl-stamnes.net>
Re: What is more detailled than $^O ? <tzz@lifelogs.com>
Re: What is more detailled than $^O ? <ynl@nsparks.net>
Re: What is more detailled than $^O ? <cwilbur@mithril.chromatico.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 07 Nov 2006 09:47:38 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Data plotting questions Nov. 2, 2006
Message-Id: <071120060947389379%jgibson@mail.arc.nasa.gov>
In article <h1%3h.3404$L6.544@newsread3.news.pas.earthlink.net>,
edgrsprj <edgrsprj@ix.netcom.com> wrote:
> First I would like to thank all of the people who responded with helpful
> suggestions for my Plot applications question.
>
> It appears that the next step to take would be to download the latest
> version of Perl from the ActiveState site. And in that regard, I have the
> following question:
>
>
> I am presently using Perl version 5.8.3.809 from ActiveState with Windows
> XP. If I install the latest version, will that have any significant impact
> on the Perl programs I have already developed?
Not likely. The latest stable version is 5.8.8. Language implementors
do not make major changes in minor releases. There were a number of
significant changes going from 5.6 to 5.8, and a moderate number of
changes from 5.8.0 to 5.8.1, mostly in the Unicode support area, but by
the time a major release gets to version .3, most of what changes in
each release is bug fixes and tweaks to some of the more obscure
aspects of the language. The language developers go to extraordinary
lengths to ensure that the changes do not break existing programs.
>
>
> For example, I make extensive use of the "GoTo" command. That is probably
> not the case for most people writing computer programs. If the latest Perl
> version has eliminated that command then that would have a significant
> impact on my present computer programs. Obviously, without seeing my
> programs no one would actually be able to answer that question in detail. I
> am just looking for general information.
No version release of a major language will eliminate a basic
functionality such as the goto statement. Usually, keywords and
functions will be added, but only at major releases, such as the
upcoming release of Perl 5.10, and the additions will be designed to be
compatible with existing code.
>
> Finally, I see that ActiveState has versions of several other languages
> available including Python and Tcl. Without getting too technical, can
> anyone explain how they differ from Perl? I am primarily interested in a
> versatile language which would be easy for scientists to use. Perl is quite
> versatile. But I personally feel that you need a fair amount of programming
> experience to make effective use of it.
Perl, TCL, and Python are all very capable, general-purpose languages.
They are somewhat similar and overlap in their design and functionality
(I am not greatly experienced with TCL or Python, so I may be
overlooking some basic differences). None is "easy for scientists to
use" (speaking as a former 'scientist'). They all require a degree of
programming experience to use effectively. Which is easiest to use is
open to debate, in which I shall not engage. You can also consider
Ruby, which is popular these days. There may be others to consider as
well, such as Java, Visual Basic, Ada, and Fortran, all of which have
their advantages for non-programmers.
Nobody here is likely to take the time to give you a detailed
comparison of any 3 computer languages. There is much existing
literature on this subject, as it is a favorite pastime of programmers.
Try Google. The search "computer language comparison" led me quickly to
<http://www.jvoegele.com/software/langcomp.html>, for example.
------------------------------
Date: Tue, 07 Nov 2006 16:40:45 +0000
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Huge Memory Load for reading into memory
Message-Id: <g69y7qnxl9u.fsf@lifelogs.com>
On 7 Nov 2006, rahul.thathoo@gmail.com wrote:
> I am trying to load a 600MB file into memory through the below code.
> But when I do a top on the system, I see that over the duration of the
> program run, the memory usage is 7.5 Gigs!! the top command says: VIRT:
> 7449m and Res: 7.289m - of course I have 8GB of RAM at my disposal. But
> the point is why is this happening for a file which is only 600MB in
> size. Here is the code:
>
> open UM, MAP_FILE or die "Can't open Usermap.\n";
> my %mapHash;
> while(<UM>){
> @tokens = split(/:/, $_);
> $zHashKey = $tokens[0];
> @zMovArr = split(/\s/, $tokens[1]);
> $mapHash{$zHashKey} = [@zMovArr];
> }
> close UM;
Approach 1:
Make the inner loop
@tokens = split(/:/, $_, 2);
$mapHash{$tokens[0]} = $tokens[1];
and then parse out the tokens later as needed.
Approach 2:
use a database (DBM, SQLite, a RDBMS like MySQL, etc.) to hold your
data
Is what you showed really all the code? I doubt there's a 10x
overhead from 600 MB of text data in any case. Look for copies of the
hash, or other data that's using the memory.
Ted
------------------------------
Date: Tue, 07 Nov 2006 16:49:09 +0000
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: Huge Memory Load for reading into memory
Message-Id: <eiqde5$ja7$1@gemini.csx.cam.ac.uk>
Ted Zlatanov wrote:
> On 7 Nov 2006, rahul.thathoo@gmail.com wrote:
>
>> I am trying to load a 600MB file into memory through the below code.
>> But when I do a top on the system, I see that over the duration of the
>> program run, the memory usage is 7.5 Gigs!! the top command says: VIRT:
>> 7449m and Res: 7.289m - of course I have 8GB of RAM at my disposal. But
>> the point is why is this happening for a file which is only 600MB in
>> size. Here is the code:
>>
>> open UM, MAP_FILE or die "Can't open Usermap.\n";
>> my %mapHash;
>> while(<UM>){
>> @tokens = split(/:/, $_);
>> $zHashKey = $tokens[0];
>> @zMovArr = split(/\s/, $tokens[1]);
>> $mapHash{$zHashKey} = [@zMovArr];
>> }
>> close UM;
[snip]
> Is what you showed really all the code? I doubt there's a 10x
> overhead from 600 MB of text data in any case. Look for copies of the
> hash, or other data that's using the memory.
I seem to recall reading here in the last couple of months that there
*is* indeed an overhead that could do that for hashes (as used above)
... something of the order of 60 bytes per entry, independent of the
size of the key or value. If the keys and values are only a few bytes
each, then a 10x overhead is not implausible.
Would someone with real knowledge of the relevant internals like to comment?
DS
------------------------------
Date: 07 Nov 2006 17:25:02 GMT
From: xhoster@gmail.com
Subject: Re: Huge Memory Load for reading into memory
Message-Id: <20061107122619.836$mB@newsreader.com>
David Squire <David.Squire@no.spam.from.here.au> wrote:
> Ted Zlatanov wrote:
> > On 7 Nov 2006, rahul.thathoo@gmail.com wrote:
> >
> >> I am trying to load a 600MB file into memory through the below code.
> >> But when I do a top on the system, I see that over the duration of the
> >> program run, the memory usage is 7.5 Gigs!! the top command says:
> >> VIRT: 7449m and Res: 7.289m - of course I have 8GB of RAM at my
> >> disposal. But the point is why is this happening for a file which is
> >> only 600MB in size. Here is the code:
> >>
> >> open UM, MAP_FILE or die "Can't open Usermap.\n";
> >> my %mapHash;
> >> while(<UM>){
> >> @tokens = split(/:/, $_);
> >> $zHashKey = $tokens[0];
> >> @zMovArr = split(/\s/, $tokens[1]);
> >> $mapHash{$zHashKey} = [@zMovArr];
> >> }
> >> close UM;
>
> [snip]
>
> > Is what you showed really all the code? I doubt there's a 10x
> > overhead from 600 MB of text data in any case. Look for copies of the
> > hash, or other data that's using the memory.
>
> I seem to recall reading here in the last couple of months that there
> *is* indeed an overhead that could do that for hashes (as used above)
There is only one hash used, so it's overhead would be minimal (other than
the key overhead, but that is generally less than the overhead of an
equivalent scalar string). There are a lot of arrays, which also have
overhead. And scalars, which also have a lot of overhead. (A "real"
undefined scalar takes ~20 bytes, one with the empty string takes over 40
bytes, on one of my machines)
> ... something of the order of 60 bytes per entry, independent of the
> size of the key or value. If the keys and values are only a few bytes
> each, then a 10x overhead is not implausible.
>
> Would someone with real knowledge of the relevant internals like to
> comment?
Modern Perls share their keys among all the hashes, and last time I
researched it the first use of a key in any hash used the length of the
key, plus ~20 bytes. Further use of the same key in other hashes used just
12 bytes per key. The value is just a scalar and has the storage
requirements of a scalar. This was 32 bit, presumably 64 bit machines have
substantially higher overhead.
But storage is highly context dependent, and is hysteretic.
If you are storing numbers, taking care to not store the stringy version
of them can cut storage by more than half.
my @x = split; #stores as strings
my @x = map $_+0, split; #stores as ints/floats
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 7 Nov 2006 08:48:36 -0800
From: "evillen@gmail.com" <evillen@gmail.com>
Subject: Newbie's easy question/answer - I hope
Message-Id: <1162918116.760814.235660@m73g2000cwd.googlegroups.com>
Why does the following code:
------
$ixf=0;
while($ixf<33)
{
if($ixf =~ (/0|8|14|23/)){print "My \$ixf is $ixf<br>";}
$ixf++;
}
-----
produce this:
My $ixf is 0
My $ixf is 8
My $ixf is 10
My $ixf is 14
My $ixf is 18
My $ixf is 20
My $ixf is 23
My $ixf is 28
My $ixf is 30
I expected only 0, 8, 14 or 23?
Thanks
------------------------------
Date: Tue, 07 Nov 2006 16:56:58 +0000
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: Newbie's easy question/answer - I hope
Message-Id: <eiqdsq$k3d$1@gemini.csx.cam.ac.uk>
evillen@gmail.com wrote:
> Why does the following code:
>
> ------
> $ixf=0;
>
> while($ixf<33)
> {
> if($ixf =~ (/0|8|14|23/)){print "My \$ixf is $ixf<br>";}
> $ixf++;
> }
> -----
>
> produce this:
>
> My $ixf is 0
> My $ixf is 8
> My $ixf is 10
> My $ixf is 14
> My $ixf is 18
> My $ixf is 20
> My $ixf is 23
> My $ixf is 28
> My $ixf is 30
>
> I expected only 0, 8, 14 or 23?
...because you have not anchored the beginnings and ends of your match
patters. All the matches shown above contain the characters 0, 8, 14 or
23 *somewhere* in the string.
To get the result you want, you would need:
----
#!/usr/bin/perl
use strict;
use warnings;
for (0..32) {
print "Match for $_\n" if /^0$|^8$|^14$|^23$/;
}
----
Output:
Match for 0
Match for 8
Match for 14
Match for 23
----
Note also the more Perlish way of doing the loop and the conditional :)
Also I have not assumed HTML output.
DS
------------------------------
Date: Tue, 07 Nov 2006 17:00:33 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Newbie's easy question/answer - I hope
Message-Id: <RY24h.3979$bg7.710@trndny04>
evillen@gmail.com wrote:
> Why does the following code:
>
> ------
> $ixf=0;
>
> while($ixf<33)
> {
> if($ixf =~ (/0|8|14|23/)){print "My \$ixf is $ixf<br>";}
> $ixf++;
> }
> -----
>
> produce this:
>
> My $ixf is 0
> My $ixf is 8
> My $ixf is 10
> My $ixf is 14
> My $ixf is 18
> My $ixf is 20
> My $ixf is 23
> My $ixf is 28
> My $ixf is 30
>
> I expected only 0, 8, 14 or 23?
Because e.g. 10 contains a 0, 18 contains an 8, and 30 contains a 0, too.
And those are the alternatives you are matching.
jue
------------------------------
Date: 7 Nov 2006 09:02:57 -0800
From: "evillen@gmail.com" <evillen@gmail.com>
Subject: Re: Newbie's easy question/answer - I hope
Message-Id: <1162918977.626443.251990@e3g2000cwe.googlegroups.com>
Many thanks David
David Squire wrote:
> evillen@gmail.com wrote:
> > Why does the following code:
> >
> > ------
> > $ixf=0;
> >
> > while($ixf<33)
> > {
> > if($ixf =~ (/0|8|14|23/)){print "My \$ixf is $ixf<br>";}
> > $ixf++;
> > }
> > -----
> >
> > produce this:
> >
> > My $ixf is 0
> > My $ixf is 8
> > My $ixf is 10
> > My $ixf is 14
> > My $ixf is 18
> > My $ixf is 20
> > My $ixf is 23
> > My $ixf is 28
> > My $ixf is 30
> >
> > I expected only 0, 8, 14 or 23?
>
> ...because you have not anchored the beginnings and ends of your match
> patters. All the matches shown above contain the characters 0, 8, 14 or
> 23 *somewhere* in the string.
>
> To get the result you want, you would need:
>
> ----
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
>
> for (0..32) {
> print "Match for $_\n" if /^0$|^8$|^14$|^23$/;
> }
>
> ----
>
> Output:
>
> Match for 0
> Match for 8
> Match for 14
> Match for 23
>
> ----
>
> Note also the more Perlish way of doing the loop and the conditional :)
> Also I have not assumed HTML output.
>
>
> DS
------------------------------
Date: 7 Nov 2006 09:04:00 -0800
From: "evillen@gmail.com" <evillen@gmail.com>
Subject: Re: Newbie's easy question/answer - I hope
Message-Id: <1162919040.186108.26910@b28g2000cwb.googlegroups.com>
I suspected this but why didn't '4' match?
J=FCrgen Exner wrote:
> evillen@gmail.com wrote:
> > Why does the following code:
> >
> > ------
> > $ixf=3D0;
> >
> > while($ixf<33)
> > {
> > if($ixf =3D~ (/0|8|14|23/)){print "My \$ixf is $ixf<br>";}
> > $ixf++;
> > }
> > -----
> >
> > produce this:
> >
> > My $ixf is 0
> > My $ixf is 8
> > My $ixf is 10
> > My $ixf is 14
> > My $ixf is 18
> > My $ixf is 20
> > My $ixf is 23
> > My $ixf is 28
> > My $ixf is 30
> >
> > I expected only 0, 8, 14 or 23?
>
> Because e.g. 10 contains a 0, 18 contains an 8, and 30 contains a 0, too.
> And those are the alternatives you are matching.
>=20
> jue
------------------------------
Date: Tue, 07 Nov 2006 17:10:31 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Newbie's easy question/answer - I hope
Message-Id: <b634h.3160$qJ6.621@trndny07>
evillen@gmail.com wrote:
[Please do not top post, trying to repair]
> Jürgen Exner wrote:
>> evillen@gmail.com wrote:
>>> if($ixf =~ (/0|8|14|23/)){print "My \$ixf is $ixf<br>";}
>>>
>>> produce this:
>>>
>>> My $ixf is 0
>>> My $ixf is 8
>>> My $ixf is 10
>>> My $ixf is 14
>>> My $ixf is 18
>>> My $ixf is 20
>>> My $ixf is 23
>>> My $ixf is 28
>>> My $ixf is 30
>>>
>>> I expected only 0, 8, 14 or 23?
>>
>> Because e.g. 10 contains a 0, 18 contains an 8, and 30 contains a 0,
>> too. And those are the alternatives you are matching.
>
> I suspected this but why didn't '4' match?
Because your pattern is asking for a match against '14'. The text '14' is
not a substring of '4'.
jue
------------------------------
Date: 7 Nov 2006 09:12:58 -0800
From: "evillen@gmail.com" <evillen@gmail.com>
Subject: Re: Newbie's easy question/answer - I hope
Message-Id: <1162919578.236025.17940@m73g2000cwd.googlegroups.com>
J=FCrgen Exner wrote:
> evillen@gmail.com wrote:
> [Please do not top post, trying to repair]
> > J=FCrgen Exner wrote:
> >> evillen@gmail.com wrote:
> >>> if($ixf =3D~ (/0|8|14|23/)){print "My \$ixf is $ixf<br>";}
> >>>
> >>> produce this:
> >>>
> >>> My $ixf is 0
> >>> My $ixf is 8
> >>> My $ixf is 10
> >>> My $ixf is 14
> >>> My $ixf is 18
> >>> My $ixf is 20
> >>> My $ixf is 23
> >>> My $ixf is 28
> >>> My $ixf is 30
> >>>
> >>> I expected only 0, 8, 14 or 23?
> >>
> >> Because e.g. 10 contains a 0, 18 contains an 8, and 30 contains a 0,
> >> too. And those are the alternatives you are matching.
> >
> > I suspected this but why didn't '4' match?
>
> Because your pattern is asking for a match against '14'. The text '14' is
> not a substring of '4'.
>=20
Right - I realised that as soon as I posted... thanks
> jue
------------------------------
Date: Tue, 07 Nov 2006 18:16:07 +0100
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: Newbie's easy question/answer - I hope
Message-Id: <4550bf54$0$25955$ba4acef3@news.orange.fr>
David Squire wrote:
> evillen@gmail.com wrote:
>> Why does the following code:
>>
>> ------
>> $ixf=0;
>>
>> while($ixf<33)
>> {
>> if($ixf =~ (/0|8|14|23/)){print "My \$ixf is $ixf<br>";}
>> $ixf++;
>> }
>> -----
>>
>> produce this:
>>
>> My $ixf is 0
>> My $ixf is 8
>> My $ixf is 10
>> My $ixf is 14
>> My $ixf is 18
>> My $ixf is 20
>> My $ixf is 23
>> My $ixf is 28
>> My $ixf is 30
>>
>> I expected only 0, 8, 14 or 23?
>
> ...because you have not anchored the beginnings and ends of your match
> patters. All the matches shown above contain the characters 0, 8, 14 or
> 23 *somewhere* in the string.
>
> To get the result you want, you would need:
>
> ----
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
>
> for (0..32) {
> print "Match for $_\n" if /^0$|^8$|^14$|^23$/;
> }
/^(0|8|14|23)$/
is a little easier on the eye.
>
> ----
>
> Output:
>
> Match for 0
> Match for 8
> Match for 14
> Match for 23
>
> ----
>
> Note also the more Perlish way of doing the loop and the conditional :)
> Also I have not assumed HTML output.
>
>
> DS
------------------------------
Date: Tue, 07 Nov 2006 17:40:30 +0000
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: Newbie's easy question/answer - I hope
Message-Id: <eiqgef$pcr$1@gemini.csx.cam.ac.uk>
David Squire wrote:
> evillen@gmail.com wrote:
>> Why does the following code:
>>
>> ------
>> $ixf=0;
>>
>> while($ixf<33)
>> {
>> if($ixf =~ (/0|8|14|23/)){print "My \$ixf is $ixf<br>";}
>> $ixf++;
>> }
>> -----
[snip]
>>
>> I expected only 0, 8, 14 or 23?
>
> ...because you have not anchored the beginnings and ends of your match
> patters. All the matches shown above contain the characters 0, 8, 14 or
> 23 *somewhere* in the string.
>
> To get the result you want, you would need:
>
> ----
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
>
> for (0..32) {
> print "Match for $_\n" if /^0$|^8$|^14$|^23$/;
> }
>
> ----
... and given that you seem really to be testing for numerical equality
here, the version below is probably clearer, and quite possibly faster:
----
#!/usr/bin/perl
use strict;
use warnings;
my @good_numbers = (0, 8, 14, 23);
for my $i (0..32) {
$_ == $i and print "Match for $i\n" and last for @good_numbers;
}
----
DS
------------------------------
Date: 7 Nov 2006 17:46:26 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Newbie's easy question/answer - I hope
Message-Id: <Xns987477C55FA6castleamber@130.133.1.4>
David Squire <David.Squire@no.spam.from.here.au> wrote:
> print "Match for $_\n" if /^0$|^8$|^14$|^23$/;
That's a lot of noise, how about:
print "Match for $_\n" if /^(0|8|14|23)$/
--
John Experienced Perl programmer: http://castleamber.com/
Perl help, tutorials, and examples: http://johnbokma.com/perl/
------------------------------
Date: 7 Nov 2006 08:06:40 -0800
From: gmlvsk2@gmail.com
Subject: perl & lsof kind
Message-Id: <1162915600.591972.153510@m7g2000cwm.googlegroups.com>
Is there a perl module that will give me process name for a port?
I would give it open port and it would give me executable name that
listens on that port.
Thank you
------------------------------
Date: 7 Nov 2006 09:00:33 -0800
From: "alexxx.magni@gmail.com" <alexxx.magni@gmail.com>
Subject: Re: process subregions on an image/matrix
Message-Id: <1162918833.556290.192950@i42g2000cwa.googlegroups.com>
thank you for your help!
Sadly - I'm not a Perl guru at all - it's not clear to me how it works:
1st of all, the calls to "push @stack, $x-1,$y;": I believed that push
wanted just 2 arguments ( push ARRAY, LIST: This function treats
ARRAY as a stack and pushes the values of LIST onto the end of ARRAY
etc etc)
2nd, what's the use of $c, continuously updated?
3rd (and last!) what is there in @stack? The matrix indices? It's not
clear what happens to @stack, since it is sometimes push-ed, but never
pop-ped, so how can it be exhausted?
sorry if I wrote stupid questions, I'm trying to learn...
Alessandro
xhoster@gmail.com ha scritto:
> "alexxx.magni@gmail.com" <alexxx.magni@gmail.com> wrote:
> > Hi everybody, I need a bit of help on the programming side:
> >
> > I'm trying to write a program to perform a filtering operation on an
> > image,
> > represented as a matrix of integers.
> > So I'm 1st thing writing a procedure that scans the image, and, when
> > finding a pixel in the color to be processed, it scans all the
> > neighboring pixels until all the cluster is processed (and, if its size
> > is in the correct range, it applies the transform).
> >
> > Right now I perform this scanning of the cluster in the way I find most
> > elegant: recursion:
> >
> > sub recurseinto
> > {
> > my ($x,$y)=@_;
> > my $c;
> >
> > $flag[$x][$y]=1;
> > $c=1;
> >
> > if (($x-1>0)&&($flag[$x-1][$y]==0)&&($img[$x-1][$y]==$col)) { $c +=
> > recurseinto($x-1,$y) }
> > if (($x+1<=$width)&&($flag[$x+1][$y]==0)&&($img[$x+1][$y]==$col)) {
> > $c += recurseinto($x+1,$y) }
> > if (($y-1>0)&&($flag[$x][$y-1]==0)&&($img[$x][$y-1]==$col)) { $c +=
> > recurseinto($x,$y-1) }
> > if (($y+1<=$height)&&($flag[$x][$y+1]==0)&&($img[$x][$y+1]==$col))
> > { $c += recurseinto($x,$y+1) }
> > return $c;
> >
> > }
> >
> > Well, it works, but - I hate to admit it - it's slow.
> >
> > The question is: in which other way you would perform this task?
>
> You could use traditional methods to remove recursion using a stack.
>
> my @stack = (@_); #starting point
> #....
> while (@stack) {
> my ($x,$y)=splice @stack,0,2;
> if whatever($x-1,$y) { push @stack, $x-1,$y; $c++};
> if whatever($x+1,$y) { push @stack, $x+1,$y; $c++};
> # etc.
> }
>
> But if you need it to be hugely faster, I'd look into switching languages,
> either to C (Inline::C) or some specialized image processing language.
>
> Xho
>
> --
> -------------------- http://NewsReader.Com/ --------------------
> Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 07 Nov 2006 17:35:39 GMT
From: xhoster@gmail.com
Subject: Re: process subregions on an image/matrix
Message-Id: <20061107123656.354$0g@newsreader.com>
"alexxx.magni@gmail.com" <alexxx.magni@gmail.com> wrote:
> thank you for your help!
> Sadly - I'm not a Perl guru at all - it's not clear to me how it works:
> 1st of all, the calls to "push @stack, $x-1,$y;": I believed that push
> wanted just 2 arguments ( push ARRAY, LIST: This function treats
> ARRAY as a stack and pushes the values of LIST onto the end of ARRAY
> etc etc)
The 2nd argument is a list, which means it can look like more than one
argument. push @x, 1, 2 pushes the list (1,2) unto @x. It is the same
as push @x,1; push @x,2;
> 2nd, what's the use of $c, continuously updated?
I don't know, I just carried that over from your code. I guess it keeps
track of the size of the "splotch"
> 3rd (and last!) what is there in @stack?
flattened Pairs of x,y coordinates. It might be more "perlish" for
@stack to have arrayrefs, each one to an two-element array. But that takes
more memory and probably is slower than the flattened list.
> The matrix indices? It's not
> clear what happens to @stack, since it is sometimes push-ed, but never
> pop-ped, so how can it be exhausted?
The code:
my ($x,$y)=splice @stack,0,2;
Is equivalent to:
my $x=shift @stack;
my $y=shift @stack;
(Which means I used a queue rather than a stack. It shouldn't change the
outcome, just the order of processing. To use a stack, you would
instead use "my ($x,$y)=splice @stack, -2, 2;")
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Tue, 07 Nov 2006 16:07:17 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Putting a line in a specific place in a file
Message-Id: <Va24h.59793$P7.7501@edtnps90>
samasama wrote:
>
>>while (<>) {
>> if (/BEGIN PATTERN/ .. /END PATTERN/) {
>> # line falls between BEGIN and END in the
>> # text, inclusive.
>> }
>>}
>>
>>
>>while (<>) {
>> if (FIRST_LINE_NUM .. LAST_LINE_NUM) {
>> # operate only between first and last line, inclusive.
>> }
>>}
>>
>
> That did help, but what about the =~ /E/ ?
> I tried finding ref to that in perlre but couldn't... ?
$ seq 10 18 | perl -lne' my $x = 3 .. /16/; print "Line Number: $. Contents:
$_ Flip-flop: $x" '
Line Number: 1 Contents: 10 Flip-flop:
Line Number: 2 Contents: 11 Flip-flop:
Line Number: 3 Contents: 12 Flip-flop: 1
Line Number: 4 Contents: 13 Flip-flop: 2
Line Number: 5 Contents: 14 Flip-flop: 3
Line Number: 6 Contents: 15 Flip-flop: 4
Line Number: 7 Contents: 16 Flip-flop: 5E0
^
^
^
Line Number: 8 Contents: 17 Flip-flop:
Line Number: 9 Contents: 18 Flip-flop:
Notice the 'E' above? That is what the pattern is matching.
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: 7 Nov 2006 09:22:18 -0800
From: "samasama" <bryan@worldspice.net>
Subject: Re: Putting a line in a specific place in a file
Message-Id: <1162920138.269656.101400@k70g2000cwa.googlegroups.com>
> Line Number: 7 Contents: 16 Flip-flop: 5E0
> ^
> ^
> ^
> Line Number: 8 Contents: 17 Flip-flop:
> Line Number: 9 Contents: 18 Flip-flop:
>
> Notice the 'E' above? That is what the pattern is matching.
>
>
Hmmm, but /16/ was the pattern ?
Does ( $. == $base_gpg_line .. /exclude\=.*/i ) return E0 ?
If so then the =~ /E/ makes sense to me.
Once again thanks
Signed, complete noob
--
samasama
------------------------------
Date: Tue, 07 Nov 2006 20:03:23 +0100
From: =?ISO-8859-1?Q?J=F8rn?= Dahl-Stamnes <newsmanDELETE@REMOVEdahl-stamnes.net>
Subject: Regular expressions
Message-Id: <4550d87b@news.broadpark.no>
I'm trying to extract parts of a string with the following line:
$relay =~ s/^\[(.+)\]$|^(.+) \[.+$/$1/;
But $relay contain data only if it match the first part of the expression.
I have tested both parts of the expression, and they both work.
Can the |-operator be used in the line above?
--
Jørn Dahl-Stamnes
http://www.dahl-stamnes.net/dahls/
------------------------------
Date: Tue, 07 Nov 2006 16:51:11 +0000
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: What is more detailled than $^O ?
Message-Id: <g69u01bxksg.fsf@lifelogs.com>
On 7 Nov 2006, ynl@nsparks.net wrote:
> In article <g69k6281bu6.fsf@lifelogs.com>, tzz@lifelogs.com says...
>> In non-Perl terms, this information is often in /etc. The file
>> /etc/issue in particular is often useful.
>>
>> It's almost always better to test for tools and features than
>> distributions anyhow. If you need package X, don't assume it's
>> installed, check. For a web server, Apache for example, there's tools
>> to tell you the version and compiled-in or loaded features. Perl
>> can't solve this problem in general terms AFAIK.
>>
>
> Yes, but I don't want to test what feature is available or not.
Well then that's too bad for you :) You can't just decide that
reality should suit you. Either you test for the features you want,
or you write unreliable code. Anyhow, what you are saying below leads
me to believe you don't really need to know about OS features.
> The fact is that some of the Perl CGI scripts we spread in our
> intranet and extranet have to proceed with reports from
> proprietaries logs in different trees depending of the specific
> linux distribution (actually : Ubuntu, Debian, Red Hat Ent, Fedora
> and Suse, but more in future).
> Also, some of these logs may have different signification depending of
> the current distribution (so, we can't simply check for file presence
> and deduct it's this or this distribution).
> And, to facilitate the stuff, some of the servers may change from time
> to time (I mean, change of linux ditribution from multi-boot or raw
> change) and every admin has choice to keep of strip-out some parts of
> the logs tree I told about ; this without notice, so I can't maintain a
> simple database saying server #1 is under Debian, server #2 is under
> Fedora, etc.
>
> Well, because of this specific context, I have to determinate what is
> the current linux ditribution (at least the 'main name' as said above,
> even if I can't know the version) up front of all. Never mind what are
> the available features or installed packages, it's not the information
> I'm looking for and our packages will run whatever be the config.
Sounds like you just need to look in a few places, examine the first
few lines of the log files, and determine whether to process them in
mode A or B or C etc. It doesn't seem to be about recognizing the OS,
but about detecting log files in several locations and finding the
formats. Am I missing something? Is it ever the case that you may
mistakenly use mode B when mode A was needed if you use this approach?
I would expect this to be more reliable than OS detection, too,
because you are actually checking for job prerequisites rather than
guessing based on the OS.
Ted
------------------------------
Date: Tue, 7 Nov 2006 19:25:20 +0100
From: Yohan N Leder <ynl@nsparks.net>
Subject: Re: What is more detailled than $^O ?
Message-Id: <MPG.1fbaedff61007c7a9898fc@news.tiscali.fr>
In article <g69u01bxksg.fsf@lifelogs.com>, tzz@lifelogs.com says...
> Well then that's too bad for you :) You can't just decide that
> reality should suit you. Either you test for the features you want,
> or you write unreliable code. Anyhow, what you are saying below leads
> me to believe you don't really need to know about OS features.
>
You surely know the sentence : "Tell me what you need and I'll tell you
how to do without"... Really and independently to the kindly of your
post, I'll don't debate about the pertinence or not of the choice, but
how to achieve this precise choice : I'm not alone here, but just the
one who has to achieve this specific choice these days... So, I'll do it
whatever be the way to succeed... And I'll do it because I know how it
works in our team : sometimes, some work on stuff which are not directly
useful to their own job but on a direction which will be more efficient
for the global structure/projects : in others words, even if in my own
current little case I could do otherwise, it would be not a good choice
just because this decision to write something which detect the "linux
distribution" has been choosen by a team, keeping in mind what could be
useful a day or another to the others in this same team (a matter of
middle term approach).
So, my question remains the same : how to check what's the current linux
distribution from a cgi Perl script ? Say, to begin and to point a
concrete case : how to distinguish if a linux is a Debian/Ubuntu or a
RedHat/Fedora ?
------------------------------
Date: 07 Nov 2006 13:37:50 -0500
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: What is more detailled than $^O ?
Message-Id: <87r6wfqf0h.fsf@mithril.chromatico.net>
Yohan N Leder <ynl@nsparks.net> writes:
> You surely know the sentence : "Tell me what you need and I'll tell you
> how to do without"... Really and independently to the kindly of your
> post, I'll don't debate about the pertinence or not of the choice, but
> how to achieve this precise choice :
There's a concept known as the XY problem. The querent asks "How do I
do Y?" In reality, he's interested in knowing how to X, and he's
convinced that doing Y is the best way to do X. Such a querent is
almost always wrong.
In this case, you want to know if it's Debian or Fedora so you know
where to look for the log files and what format to expect the log
files in. There's no built-in pre-existing way to find out what
distribution you're on; so look for the log files in both places and
parse them according to the format you'd expect them to be if they
were there. Problem solved.
Charlton
------------------------------
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 V10 Issue 9939
***************************************