[31815] in Perl-Users-Digest
Perl-Users Digest, Issue: 3078 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 16 16:09:24 2010
Date: Mon, 16 Aug 2010 13:09:06 -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 Mon, 16 Aug 2010 Volume: 11 Number: 3078
Today's topics:
Re: Appropriate technique for altering a text file? <cartercc@gmail.com>
Re: bulk flush input (Tim McDaniel)
Re: Can't print entire line. <nospam-abuse@ilyaz.org>
Re: code snippet to convolve 2 vectors sln@netherlands.com
combining hashes <monkey@joemoney.net>
Re: combining hashes <rvtol+usenet@xs4all.nl>
Consistent ps/top output format <bart@nijlen.com>
Re: Consistent ps/top output format <uri@StemSystems.com>
Re: Consistent ps/top output format <bart@nijlen.com>
Re: Consistent ps/top output format <sherm.pendley@gmail.com>
Re: Consistent ps/top output format <glex_no-spam@qwest-spam-no.invalid>
Recursion regular expression (xtended) sln@netherlands.com
Re: Recursion regular expression (xtended) sln@netherlands.com
Re: Why this warning? <justin.1007@purestblue.com>
Re: Why this warning? <smallpond@juno.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 16 Aug 2010 06:46:26 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Appropriate technique for altering a text file?
Message-Id: <3fcde8a3-be60-4e51-81ab-ff5b6ee95c42@a36g2000yqc.googlegroups.com>
On Aug 14, 11:28=A0pm, "Uri Guttman" <u...@StemSystems.com> wrote:
> print line like this:
>
> =A0 =A0 =A0 =A0 print join( ',', map qq{"$_"}, @fields ), "\n" ;
Thank you. I don't use grep() or map() much ... tidbits like this make
reading c.l.p.m. worthwhile.
> then you haven't done much parsing so far. plenty of files have
> multiline formats.
Not when your data results from a database, which mine does. I'm not a
programmer, but a database guy who write scripts to munge data which
is read from a database, written to a database, or both.
> =A0 c> I've been writing some Lisp, and sooner or later I'll solve a
> =A0 c> problem with Lisp, and then maybe they'll be more accepting of
> =A0 c> Perl.
>
> a strange way of getting perl accepted! :)
I once took a graduate level management course in the business school
of a large, state university. Many of the students were essentially
fifth year seniors, but many were junior to mid level management a
decade or so out of school. I was the only SwE guy in the class, and
received abuse from those in management who had had bad experiences
from IT or their SW developers. The accepted Standard was Visual
Basic, because Everybody used Visual Basic, and if you didn't you
couldn't do any Work. The textbook (which was actually a good book - I
kept it and still use it from time to time) was written using VB. The
fact that I used Perl was seen as a sign of the backwardness and
intractability of IT, as opposed to the rational, mature, and forward
looking nature of Management.
CC
------------------------------
Date: Sun, 15 Aug 2010 12:07:40 -0500
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: bulk flush input
Message-Id: <sfjlj7-fkg.ln1@tmcd.austin.tx.us>
I read the newsgroup only occasionally, so I'm sorry to get to this
late.
In article <14bc26hm1r5jp13174fmbkf49ekgdv4l51@4ax.com>,
John Kelly <jak@isp2dial.com> wrote:
>On Sat, 26 Jun 2010 18:23:21 +0200, "Dr.Ruud" <rvtol+usenet@xs4all.nl>
>wrote:
>
>>Ben Morrow wrote:
>>
>>> my $data;
>>> while (<>) {
>>> chomp;
>>> length or next;
>>> $data = $_;
>>> last;
>>> }
>>> {
>>> local $/ = \2048;
>>> 1 while <>;
>>> }
>>
>>This nicely keeps memory usage limited.
>>I always use 4096.
>
>I decided to use 4096 too. I also replaced the "length" test with a
>regex, to ignore lines containing only superfluous whitespace, prior to
>the first line of data:
>
> /^\s*$/ and next;
I suspect
/\S/ or next;
is more efficient. Or at least I can't see how it can be less
efficient.
--
Tim McDaniel; Reply-To: tmcd@panix.com
------------------------------
Date: Mon, 16 Aug 2010 04:43:33 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Can't print entire line.
Message-Id: <slrni6hgfl.cm1.nospam-abuse@powdermilk.math.berkeley.edu>
On 2010-08-15, Tad McClellan <tadmc@seesig.invalid> wrote:
>>>> while (my $line = <@tmsh_show>) {
> Deparse says it is a glob():
Of course. AFAIK, the rules of disambiguation of <> are very simple:
if it is a bareword or a $BARE::WORD, it is a readline(); otherwise it
is a glob. E.g., <${foo}> is a glob.
Yours,
Ilya
------------------------------
Date: Mon, 16 Aug 2010 11:30:49 -0700
From: sln@netherlands.com
Subject: Re: code snippet to convolve 2 vectors
Message-Id: <sr0j665udl617m53m86ol48mjn97cdicsm@4ax.com>
On Sat, 14 Aug 2010 15:52:52 +0200, Toralf Förster <toralf.foerster@gmx.de> wrote:
>I'm looking for perl code examples to get the convoltion of 2 arrays eg.
>like this :
>
>[1, 2] x [3, 4] = [ 3, 10, 8]
Nothing fancy, the straight forward way.
-sln
------------
use strict;
use warnings;
my @A = (1, 2);
my @B = (3, 4);
my @R;
for my $x (0 .. $#A)
{
my ($col, $mult) = ($x, $A[$x]);
for my $y (0 .. $#B)
{
$R[$col++] += $B[$y] * $mult;
}
}
print "@R";
------------------------------
Date: Mon, 16 Aug 2010 15:53:59 -0400
From: monkeys paw <monkey@joemoney.net>
Subject: combining hashes
Message-Id: <nKmdnc6f9LfFCvTRnZ2dnUVZ_r-dnZ2d@insightbb.com>
I have two hashrefs, i want to combine them into one hash.
I think there is an easier way than what i am doing (shown below):
$fc = {'a' => 'hash'};
$ref = {'another' => 'hash'};
for (keys %{$fc}) {
$args{$_} = $fc->{$_};
}
for (keys %{$ref}) {
$args{$_} = $ref->{$_};
}
------------------------------
Date: Mon, 16 Aug 2010 22:00:43 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: combining hashes
Message-Id: <4c6998eb$0$22939$e4fe514c@news.xs4all.nl>
monkeys paw wrote:
> I have two hashrefs, i want to combine them into one hash.
> I think there is an easier way than what i am doing (shown below):
>
> $fc = {'a' => 'hash'};
> $ref = {'another' => 'hash'};
>
> for (keys %{$fc}) {
> $args{$_} = $fc->{$_};
> }
> for (keys %{$ref}) {
> $args{$_} = $ref->{$_};
> }
my $combi = { %$fc, %$ref };
--
Ruud
------------------------------
Date: Mon, 16 Aug 2010 01:39:21 -0700 (PDT)
From: Bart Van der Donck <bart@nijlen.com>
Subject: Consistent ps/top output format
Message-Id: <908c2528-de72-4424-9fba-2936e1015244@5g2000yqz.googlegroups.com>
Hello,
I have written a Perl script to store and interpret the output of the
unix 'ps'-command. It works well on my machine (FreeBSD 6.2.), but it
doesn't work on a few other unix variants that I tested.
I came to the conclusion that the output format is the culprit. This
appears to differ across ps/top variants on several OS-es, even with
the command line options mentioned in the docs.
Is there any way to get the output of "ps" (or "top -b") into a
reliable consistent format ?
Thanks,
--
Bart
------------------------------
Date: Mon, 16 Aug 2010 05:00:16 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Consistent ps/top output format
Message-Id: <87y6c7gcf3.fsf@quad.sysarch.com>
>>>>> "BVdD" == Bart Van der Donck <bart@nijlen.com> writes:
BVdD> I have written a Perl script to store and interpret the output of the
BVdD> unix 'ps'-command. It works well on my machine (FreeBSD 6.2.), but it
BVdD> doesn't work on a few other unix variants that I tested.
BVdD> I came to the conclusion that the output format is the culprit. This
BVdD> appears to differ across ps/top variants on several OS-es, even with
BVdD> the command line options mentioned in the docs.
BVdD> Is there any way to get the output of "ps" (or "top -b") into a
BVdD> reliable consistent format ?
use a module. Sys::Info covers bsd, linux and winblows
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Mon, 16 Aug 2010 02:28:31 -0700 (PDT)
From: Bart Van der Donck <bart@nijlen.com>
Subject: Re: Consistent ps/top output format
Message-Id: <59888b25-adaf-45df-af52-d6a5bf29f026@j8g2000yqd.googlegroups.com>
Uri Guttman wrote:
> >>>>> "BVdD" =3D=3D Bart Van der Donck <b...@nijlen.com> writes:
>
> =A0 BVdD> I have written a Perl script to store and interpret the output =
of the
> =A0 BVdD> unix 'ps'-command. It works well on my machine (FreeBSD 6.2.), =
but it
> =A0 BVdD> doesn't work on a few other unix variants that I tested.
>
> =A0 BVdD> I came to the conclusion that the output format is the culprit.=
This
> =A0 BVdD> appears to differ across ps/top variants on several OS-es, even=
with
> =A0 BVdD> the command line options mentioned in the docs.
>
> =A0 BVdD> Is there any way to get the output of "ps" (or "top -b") into a
> =A0 BVdD> reliable consistent format ?
>
> use a module. Sys::Info covers bsd, linux and winblows
Thanks - I've looked into it, but the information returned by
Sys::Info is too general for me. The script should detect the 20 most
CPU-intensive processes ("ps -aux" or "top -b" on FreeBSD), e.g.:
PID USER THR PRI NICE SIZE RES STATE TIME WCPU COMMAND
978 root 1 8 -20 5636K 2964K nanslp 18.2H 0.10% perl
8003 bind 1 4 20 28012K 1892K kqread 452:24 0.00% named
1019 root 1 4 -15 6172K 1332K sbwait 279:27 0.00% perl
...
--
Bart
------------------------------
Date: Mon, 16 Aug 2010 06:09:09 -0400
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: Consistent ps/top output format
Message-Id: <m2r5hykgxm.fsf@sherm.shermpendley.com>
Bart Van der Donck <bart@nijlen.com> writes:
> Is there any way to get the output of "ps" (or "top -b") into a
> reliable consistent format ?
Try asking in comp.unix.shell - this group is about Perl.
sherm--
--
Sherm Pendley
<camelbones.sourceforge.net>
Cocoa Developer
------------------------------
Date: Mon, 16 Aug 2010 11:05:56 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Consistent ps/top output format
Message-Id: <4c6961e5$0$89386$815e3792@news.qwest.net>
Bart Van der Donck wrote:
> Uri Guttman wrote:
>
>>>>>>> "BVdD" == Bart Van der Donck <b...@nijlen.com> writes:
>> BVdD> I have written a Perl script to store and interpret the output of the
>> BVdD> unix 'ps'-command. It works well on my machine (FreeBSD 6.2.), but it
>> BVdD> doesn't work on a few other unix variants that I tested.
>>
>> BVdD> I came to the conclusion that the output format is the culprit. This
>> BVdD> appears to differ across ps/top variants on several OS-es, even with
>> BVdD> the command line options mentioned in the docs.
>>
>> BVdD> Is there any way to get the output of "ps" (or "top -b") into a
>> BVdD> reliable consistent format ?
>>
>> use a module. Sys::Info covers bsd, linux and winblows
>
> Thanks - I've looked into it, but the information returned by
> Sys::Info is too general for me. The script should detect the 20 most
> CPU-intensive processes ("ps -aux" or "top -b" on FreeBSD), e.g.:
>
> PID USER THR PRI NICE SIZE RES STATE TIME WCPU COMMAND
> 978 root 1 8 -20 5636K 2964K nanslp 18.2H 0.10% perl
> 8003 bind 1 4 20 28012K 1892K kqread 452:24 0.00% named
> 1019 root 1 4 -15 6172K 1332K sbwait 279:27 0.00% perl
> ...
Then you probably want to access the process table.
See:
http://search.cpan.org/~durist/Proc-ProcessTable-0.45/ProcessTable.pm
------------------------------
Date: Mon, 16 Aug 2010 07:38:30 -0700
From: sln@netherlands.com
Subject: Recursion regular expression (xtended)
Message-Id: <n3ji66h5l3pa3j8cupt9kt7qkvpsp8vt3d@4ax.com>
Original message replied to was posted to perl.beginners
8-14, but it didn't show up. EasyNews is acting weird.
To test, I'm posting it here...
-sln
On Fri, 13 Aug 2010 13:47:41 -0700 (PDT), tobias.wagener@googlemail.com (irata) wrote:
>Hi...
>
>I want to replace in a javscript structure like the one below every
>occurence of "{#...}", "{?...}", "{+...}" and "{=...}" through
>something different (also nested):
> function() {
> test1 = "{#Caption}";
> test2 = "{#Te{?st}}";
> test3 = "{+date.{0}}";
> }
>
>with this regular expression
> my( $open ) = qr/{[=+#?]/;
> my( $close ) = qr/}/;
> my( $not ) = qr/[^{}]++/;
> do {
> $found = $text =~ s/
> (
> $open
> (?: $not | (?1) )
> $close
> )
> /replace($1)/esxg;
> } while ( $found );
>I can handle case "test1" and "test2" but the case "test3" won't work.
>Could some help me how I can change the expression that it match
>"{+date.{0}}" without bothering about the "{0}" (this could also be
>"{foo}").
>
>I try it with:
> my( $not ) = qr/(?>(?:(?!$open)|(?!$close))+)/;
>but that won't work.
>
>Thanks and best regards. And please excuse my english, I hope you will
>understand everything, otherwise ask me ;-)
>
>T.
I saw this by chance
You should post this complex question to the clpm group.
Something in here should be of help. Don't know what though.
-sln
-------------------------
use strict;
use warnings;
# Require {[=+#?]} but not {}
my $open = '\{';
my $ctrl = '[=+#?]';
my $close = '\}';
my $regex = qr/
( # GRP 1
$open
( ($ctrl) ( # GRP 2, 3, 4
(?:
( # GRP 5
$open
(?:
(?>(?:(?! $open$ctrl | $open | $close).)+)
| (?5)
)*
$close
)
|
(?>(?:(?! $open$ctrl | $open | $close).)+)
| (?1)
)*
) ) # end GRP 2, 4
$close
)
/xs;
my $code = join '',<DATA>;
print "\n",'-'x10,"\nBefore:\n",'-'x10,"\n$code\n",'-'x10,"\n";
my $found = 0;
while ($code =~ /$regex/g) {
print "found: $1\n";
$found = 1;
}
if ($found) {
1 while ($code =~ s/$regex/"['$3'$4]"/eg);
print "\n",'-'x10,"\nAfter:\n",'-'x10,"\n$code\n";
}
__DATA__
I want to replace in a javscript structure like the one below every
occurence of "{#...}", "{?...}", "{+...}" and "{=...}" through
something different (also nested):
function() {
test1 = "{#Caption}";
test2 = "{#Te{?st{8}}}";
test3 = "{+date.{0}}";
}
------------------------------
Date: Mon, 16 Aug 2010 08:51:31 -0700
From: sln@netherlands.com
Subject: Re: Recursion regular expression (xtended)
Message-Id: <qcni66h52g78e690k60jmk9qfqit54utvc@4ax.com>
On Mon, 16 Aug 2010 07:38:30 -0700, sln@netherlands.com wrote:
>Original message replied to was posted to perl.beginners
>8-14, but it didn't show up. EasyNews is acting weird.
>To test, I'm posting it here...
>
Oh its a mailing list that shows up as a usenet group.
I don't know how any of this is usefull or works so, not
wanting to get emails ... First and last time to the read-only
useless perl.beginners, er ah, newsgroup.
-sln
------------------------------
Date: Mon, 16 Aug 2010 11:59:08 +0100
From: Justin C <justin.1007@purestblue.com>
Subject: Re: Why this warning?
Message-Id: <s8inj7-e4k.ln1@zem.masonsmusic.co.uk>
On 2010-08-14, Sal <here@softcom.net> wrote:
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my %sum = {};
> for (my $i = 1; $i <= 6; $i++) {
> for (my $j = 1; $j <= 6; $j++) {
> for (my $k = 1; $k <= 6; $k++) {
> my $tot = $i+$j+$k;
> my $key = "$i " . "$j " . "$k ";
> $sum{$key} = $tot;
> print "$i " . "$j " . "$k " . " $tot\n";
> }
> }
> }
>
> foreach my $key (sort keys %sum) {
> print "$key => $sum{$key}\n";
> }
>
> When the above is executed it first prints the entire hash, then
> returns the error:
>
> Use of uninitialized value $sum{"HASH(0x95fe818)"} in concatenation
> (.) or string at ./3dice.pl line 19.
> HASH(0x95fe818) =>
>
> Why is the last hash value blank?
Probably because in your declaration of the hash you have declared the
hash to be {}, you then add other keys and values to the hash. If you
declare the hash thus:
my %sum;
instead then I think you will find all as you expect it to be. Didn't
perl warn you "Reference found where even-sized list expected at
untitled line 6."? Mine did.
Justin.
--
Justin C, by the sea.
------------------------------
Date: Mon, 16 Aug 2010 12:31:45 -0400
From: Steve C <smallpond@juno.com>
Subject: Re: Why this warning?
Message-Id: <i4bp5t$jgk$1@news.eternal-september.org>
Sal wrote:
>
> Thanks to all on this forum who have taken the time to assist me. You
> guys are great! After C/C++, Java, PHP, and dabbling a little in
> Python, Perl is becoming my favorite language. I honestly don't
> understand all the hype about Python.
Python programmers would point to your parens problem as a perfect example
of why Python is preferred. Perl programs are perplexing. You have to
parse a lot of punctuation to program Perl.
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 3078
***************************************