[29792] in Perl-Users-Digest
Perl-Users Digest, Issue: 1035 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 15 09:09:50 2007
Date: Thu, 15 Nov 2007 06:09:09 -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 Thu, 15 Nov 2007 Volume: 11 Number: 1035
Today's topics:
100% cpu loop of time() ... <iler.ml@gmail.com>
Re: 100% cpu loop of time() ... <ben@morrow.me.uk>
Re: Automatic document generation <spamtrap@dot-app.org>
Re: Back references <pgp@see.sig.invalid>
new CPAN modules on Thu Nov 15 2007 (Randal Schwartz)
Re: Question about printing XML using XML::Simple <bigiain@mightymedia.com.au>
regular expression for digits <pawlaczus@yahoo.com>
Re: regular expression for digits Yann.Esposito@gmail.com
Re: regular expression for digits <peter@makholm.net>
Re: regular expression for digits <mritty@gmail.com>
Re: regular expression for digits <mritty@gmail.com>
Rename files using directory names <ldolan@thinkinghatbigpond.net.au>
Repeating element string parsing and iteration <throwaway43054@gmail.com>
Re: Repeating element string parsing and iteration <krahnj@telus.net>
Re: Repeating element string parsing and iteration <m@rtij.nl.invlalid>
Re: sleep/fork/shell/SIGCHLD interaction problem <gerph@gerph.org>
Two Perl programming questions <TimKnoll@gmail.com>
Re: Use of uninitialized value in concatenation <krahnj@telus.net>
using a function in map? <bugbear@trim_papermule.co.uk_trim>
Re: using a function in map? <peter@makholm.net>
Re: using a function in map? <abigail@abigail.be>
Re: using a function in map? <mritty@gmail.com>
Re: using a function in map? <bugbear@trim_papermule.co.uk_trim>
Why is Errno.pm on CPAN <peter@makholm.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 15 Nov 2007 04:40:50 -0800 (PST)
From: Yakov <iler.ml@gmail.com>
Subject: 100% cpu loop of time() ...
Message-Id: <502d39ec-6fe8-4037-baa7-94cd47a57b4b@k62g2000hse.googlegroups.com>
One perl daemon happens to go sometimes into 100% cpu state.
When I do strace or ltrace on it, I see infinite sequence of time()
calls,
and nothing in between.
But the source code, although has couple of calls to time(), nowhere
has possibility of infinite lop of time(). I wonder whether perl
interpreter can be doing this inside it, maybe restarting on signals
or something ? The code is single-threaded. Wrt to signals, it either
ignores
signals, or dies on signals.
Yakov
------------------------------
Date: Thu, 15 Nov 2007 13:26:34 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: 100% cpu loop of time() ...
Message-Id: <a1ut05-s31.ln1@osiris.mauzo.dyndns.org>
Quoth Yakov <iler.ml@gmail.com>:
> One perl daemon happens to go sometimes into 100% cpu state.
> When I do strace or ltrace on it, I see infinite sequence of time()
> calls,
> and nothing in between.
>
> But the source code, although has couple of calls to time(), nowhere
> has possibility of infinite lop of time(). I wonder whether perl
> interpreter can be doing this inside it, maybe restarting on signals
> or something ? The code is single-threaded. Wrt to signals, it either
> ignores
> signals, or dies on signals.
Are you able to run it with a debugging build of perl, and break in with
a debugger to get a stacktrace?
Ben
------------------------------
Date: Thu, 15 Nov 2007 04:06:44 -0500
From: Sherman Pendley <spamtrap@dot-app.org>
Subject: Re: Automatic document generation
Message-Id: <m1pryb7u8r.fsf@dot-app.org>
"A. Sinan Unur" <1usa@llenroc.ude.invalid> writes:
> howa <howachen@gmail.com> wrote in news:25a3dadf-c212-452f-ac08-
> 46f9fbdb6da0@s19g2000prg.googlegroups.com:
>
>> Anyone is using automatic document generation in Perl (like Javadoc,
>> which generate HTML pages for API references)
>>
>> Any suggestions?
>
> perldoc perlpod
Also:
perldoc pod2html
perldoc pod2latex
perldoc pod2man
perldoc pod2text
sherm--
--
WV News, Blogging, and Discussion: http://wv-www.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Thu, 15 Nov 2007 13:13:35 +0000
From: Philip Potter <pgp@see.sig.invalid>
Subject: Re: Back references
Message-Id: <fhhgm0$1ch$1@aioe.org>
Uri Guttman wrote:
> that is incorrect. those are grabs and the scalar variables used to
> access them later on (in the replacement string or later).
>
> backreferences are when you refer to a previous grab INSIDE the same
> regex. $1 inside a regex will refer to a grab from an earler regex grab,
> not the current one. you use \1 to refer to the first grab in the
> current regex.
Whoops! Thanks for the correction. (And thanks to Tad as well.)
--
Philip Potter pgp <at> doc.ic.ac.uk
------------------------------
Date: Thu, 15 Nov 2007 05:42:17 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Thu Nov 15 2007
Message-Id: <JrJ96H.15MK@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
Algorithm-Dependency-Source-DBI-0.05
http://search.cpan.org/~adamk/Algorithm-Dependency-Source-DBI-0.05/
Database source for Algorithm::Dependency
----
Algorithm-Tree-NCA-0.02
http://search.cpan.org/~matkin/Algorithm-Tree-NCA-0.02/
Constant time retrieval of *Nearest Common Ancestor*
----
Business-OnlinePayment-TransactionCentral-0.05
http://search.cpan.org/~ivan/Business-OnlinePayment-TransactionCentral-0.05/
Transaction Central backend module for Business::OnlinePayment
----
CGI-Application-URIMapping-0.02
http://search.cpan.org/~kazuho/CGI-Application-URIMapping-0.02/
A dispatcher and permalink builder
----
Catalyst-Controller-SOAP-0.0.1
http://search.cpan.org/~druoso/Catalyst-Controller-SOAP-0.0.1/
Catalyst SOAP Controller
----
Catalyst-Controller-SOAP-0.0.2
http://search.cpan.org/~druoso/Catalyst-Controller-SOAP-0.0.2/
Catalyst SOAP Controller
----
Catalyst-Controller-SOAP-0.0.3
http://search.cpan.org/~druoso/Catalyst-Controller-SOAP-0.0.3/
Catalyst SOAP Controller
----
CatalystX-CRUD-0.11
http://search.cpan.org/~karman/CatalystX-CRUD-0.11/
CRUD framework for Catalyst applications
----
Chart-Math-Axis-1.03
http://search.cpan.org/~adamk/Chart-Math-Axis-1.03/
Implements an algorithm to find good values for chart axis
----
DBD-ODBC-1.15_2
http://search.cpan.org/~mjevans/DBD-ODBC-1.15_2/
ODBC Driver for DBI
----
DBIx-Class-QueryLog-1.0.3
http://search.cpan.org/~gphat/DBIx-Class-QueryLog-1.0.3/
Log queries for later analysis.
----
Data-Average-0.03000
http://search.cpan.org/~dmaki/Data-Average-0.03000/
Hold Data Set To Calculate Average
----
Data-Package-1.03
http://search.cpan.org/~adamk/Data-Package-1.03/
Base class for packages that are purely data
----
Data-Package-CSV-1.01
http://search.cpan.org/~adamk/Data-Package-CSV-1.01/
A Data::Package class for CSV data using Parse::CSV
----
Data-Package-SQLite-1.01
http://search.cpan.org/~adamk/Data-Package-SQLite-1.01/
A data package for a SQLite database
----
Data-Toolkit-0.2
http://search.cpan.org/~afindlay/Data-Toolkit-0.2/
----
Decision-ParseTree-0.04
http://search.cpan.org/~notbenh/Decision-ParseTree-0.04/
Replacing waterfall IF-ELSIF-ELSE blocks
----
Decision-ParseTree-0.041
http://search.cpan.org/~notbenh/Decision-ParseTree-0.041/
Replacing waterfall IF-ELSIF-ELSE blocks
----
Devel-Unplug-0.03
http://search.cpan.org/~andya/Devel-Unplug-0.03/
Simulate the non-availability of modules
----
Dispatch-Declare-0.1.1
http://search.cpan.org/~rlb/Dispatch-Declare-0.1.1/
Build a hash based dispatch table declaratively
----
Dispatch-Declare-0.1.2
http://search.cpan.org/~rlb/Dispatch-Declare-0.1.2/
Build a hash based dispatch table declaratively
----
EV-0.9
http://search.cpan.org/~mlehmann/EV-0.9/
perl interface to libev, a high performance full-featured event loop
----
File-Find-Parallel-0.51
http://search.cpan.org/~andya/File-Find-Parallel-0.51/
Traverse a number of similar directories in parallel
----
File-Tasks-0.07
http://search.cpan.org/~adamk/File-Tasks-0.07/
A set of file tasks to be executed in a directory
----
Games-Hack-Live-0.404
http://search.cpan.org/~pmarek/Games-Hack-Live-0.404/
Perl script to ease playing games
----
Games-Hack-Patch-i686-0.5
http://search.cpan.org/~pmarek/Games-Hack-Patch-i686-0.5/
How to patch code sequences on i686
----
Geo-Coder-Yahoo-0.03
http://search.cpan.org/~abh/Geo-Coder-Yahoo-0.03/
Geocode addresses with the Yahoo! API
----
HTML-Template-Compiled-0.90
http://search.cpan.org/~tinita/HTML-Template-Compiled-0.90/
Template System Compiles HTML::Template files to Perl code
----
JSON-1.15
http://search.cpan.org/~makamaka/JSON-1.15/
parse and convert to JSON (JavaScript Object Notation).
----
Lingua-KO-DateTime-0.02
http://search.cpan.org/~aero/Lingua-KO-DateTime-0.02/
convert time to korean format.
----
MIME-Types-1.22
http://search.cpan.org/~markov/MIME-Types-1.22/
Definition of MIME types
----
Mac-iTunes-0.01_01
http://search.cpan.org/~dinomite/Mac-iTunes-0.01_01/
----
Mail-IMAPClient-2.99_07
http://search.cpan.org/~markov/Mail-IMAPClient-2.99_07/
An IMAP Client API
----
Mixin-ExtraFields-0.007
http://search.cpan.org/~rjbs/Mixin-ExtraFields-0.007/
add extra stashes of data to your objects
----
Module-ExtractUse-0.21
http://search.cpan.org/~domm/Module-ExtractUse-0.21/
Find out what modules are used
----
MooseX-LogDispatch-1.0001
http://search.cpan.org/~ash/MooseX-LogDispatch-1.0001/
A Logging Role for Moose
----
MooseX-Policy-SemiAffordanceAccessor-0.01
http://search.cpan.org/~drolsky/MooseX-Policy-SemiAffordanceAccessor-0.01/
A policy to name accessors foo() and set_foo()
----
Net-Defensio-0.01
http://search.cpan.org/~bchoate/Net-Defensio-0.01/
Perl interface for Defensio.com antispam services.
----
Net-Jabber-Bot-1.3.0
http://search.cpan.org/~toddr/Net-Jabber-Bot-1.3.0/
Automated Bot creation with safeties
----
Net-SIP-0.39
http://search.cpan.org/~sullr/Net-SIP-0.39/
Framework SIP (Voice Over IP, RFC3261)
----
Net-Twitter-FriendFinder-0.02
http://search.cpan.org/~tomyhero/Net-Twitter-FriendFinder-0.02/
find your twitter friend :-)
----
Ogre-0.29
http://search.cpan.org/~slanning/Ogre-0.29/
Perl binding for the OGRE C++ graphics library
----
Params-Util-0.31
http://search.cpan.org/~adamk/Params-Util-0.31/
Simple, compact and correct param-checking functions
----
Parse-Marpa-0.001_042
http://search.cpan.org/~jkegl/Parse-Marpa-0.001_042/
(pre-Alpha) Jay Earley's general parsing algorithm, with LR(0) precomputation
----
Scriptalicious-1.12
http://search.cpan.org/~samv/Scriptalicious-1.12/
Make scripts more delicious to SysAdmins
----
ShipIt-Step-CheckYAMLChangeLog-0.02
http://search.cpan.org/~marcel/ShipIt-Step-CheckYAMLChangeLog-0.02/
ShipIt step for YAML Changes files
----
Socket-GetAddrInfo-0.01
http://search.cpan.org/~pevans/Socket-GetAddrInfo-0.01/
a wrapper for Socket6's getaddrinfo and getaddrinfo, or emulation for platforms that do not support it
----
Test-DBIC-0.01003
http://search.cpan.org/~kolibrie/Test-DBIC-0.01003/
Facilitates Automated Testing for DBIx::Class
----
Test-Distribution-2.00
http://search.cpan.org/~srshah/Test-Distribution-2.00/
perform tests on all modules of a distribution
----
Test-Group-0.09
http://search.cpan.org/~domq/Test-Group-0.09/
Group together related tests in a test suite
----
Test-Virtual-Filesystem-0.01
http://search.cpan.org/~cdolan/Test-Virtual-Filesystem-0.01/
Validate a filesystem
----
Text-Pipe-0.03
http://search.cpan.org/~marcel/Text-Pipe-0.03/
Common text filter API
----
Text-Pipe-Translate-0.01
http://search.cpan.org/~marcel/Text-Pipe-Translate-0.01/
Translate text from one language to another
----
Time-Elapsed-0.22
http://search.cpan.org/~burak/Time-Elapsed-0.22/
Displays the elapsed time as a human readable string.
----
WebService-Backlog-0.02
http://search.cpan.org/~yamamoto/WebService-Backlog-0.02/
Perl interface to Backlog.
----
kurila-1.5_0
http://search.cpan.org/~tty/kurila-1.5_0/
Perl Kurila
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Thu, 15 Nov 2007 16:28:38 +1100
From: Iain Chalmers <bigiain@mightymedia.com.au>
Subject: Re: Question about printing XML using XML::Simple
Message-Id: <bigiain-208458.16283815112007@news.usenetmonster.com>
In article <srmdnUwx5r4mJKbanZ2dnUVZ_tuonZ2d@comcast.com>,
somebody <some@body.com> wrote:
> I'm using XML::Simple to read an XML file named test.xml, which is listed
> below. I'm trying to print individual elements in the xml file like this:
>
>
> my $xml = new XML::Simple(KeyAttr=>[], ForceArray => 1);
> my $ref = $xml->XMLin($xmlfile);
> ##print Dumper($ref);
>
> #These don't work
>
> print $ref->{USER}->{NAME}->{FIRST_NAME};
> print $ref->{XMLFILE}->{USER}->{NAME}->{FIRST_NAME};
> print $ref->{USER}->{NAME}->{FIRST_NAME}->[0];
>
>
> How can I print an individual element like <LAST_NAME>?
What did that commented out print Dumper($ref) show you?
did you try:
print $ref->{USER}->[0]->{NAME}->[0]->{FIRST_NAME}->[0];
I suspect that KeyAttr=>[] and ForceArray => 1 might not be what you
want...
cheers,
big
--
"Everything you love, everything meaningful with depth and history,
all passionate authentic experiences will be appropriated, mishandled,
watered down, cheapened, repackaged, marketed and sold to the people
you hate." Mr Jalopy quoting Hooptyrides (on jalopyjunktown.com)
------------------------------
Date: Thu, 15 Nov 2007 01:36:34 -0800 (PST)
From: Abanowicz Tomasz <pawlaczus@yahoo.com>
Subject: regular expression for digits
Message-Id: <f2159188-33ed-4a6f-bfcf-930bfe5e68bd@c29g2000hsa.googlegroups.com>
Hello
My @files array contains file names:
11.jpg
111.jpg
0121.pic
1.gif
1
pic 1 cool.gif
aaa1bbb.jpg
I would like to "grep" files containing "1" digit and not "11", "111",
"0121" etc.:
1.gif
1
pic 1 cool.gif
aaa1bbb.jpg
I use the following to do that:
grep (/[^0-9]+$i[^0-9]+/, @files)
Unfortunately it does not match:
1.gif
1
files.
How should my grep look in order to cover those 2 files as well.
thank You for help
------------------------------
Date: Thu, 15 Nov 2007 01:45:53 -0800 (PST)
From: Yann.Esposito@gmail.com
Subject: Re: regular expression for digits
Message-Id: <ae3bd10d-94d5-46ec-965b-fb56bb7bb881@e4g2000hsg.googlegroups.com>
use * and not +
Y.
Abanowicz Tomasz a =E9crit :
> Hello
> My @files array contains file names:
> 11.jpg
> 111.jpg
> 0121.pic
> 1.gif
> 1
> pic 1 cool.gif
> aaa1bbb.jpg
>
> I would like to "grep" files containing "1" digit and not "11", "111",
> "0121" etc.:
> 1.gif
> 1
> pic 1 cool.gif
> aaa1bbb.jpg
>
> I use the following to do that:
>
> grep (/[^0-9]+$i[^0-9]+/, @files)
>
> Unfortunately it does not match:
> 1.gif
> 1
>
> files.
>
> How should my grep look in order to cover those 2 files as well.
>
> thank You for help
------------------------------
Date: Thu, 15 Nov 2007 09:50:13 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: regular expression for digits
Message-Id: <87oddvq1m2.fsf@hacking.dk>
Abanowicz Tomasz <pawlaczus@yahoo.com> writes:
> I would like to "grep" files containing "1" digit and not "11", "111",
[...]
> I use the following to do that:
>
> grep (/[^0-9]+$i[^0-9]+/, @files)
What is $i and is it relevant?
If you just need to find stings containing one and only one digit I
would use tr///:
grep { tr/0-9// == 1 } @files;
//Makholm
------------------------------
Date: Thu, 15 Nov 2007 03:55:44 -0800 (PST)
From: Paul Lalli <mritty@gmail.com>
Subject: Re: regular expression for digits
Message-Id: <fb28310b-947a-49ac-a530-3bc5808e483c@w34g2000hsg.googlegroups.com>
On Nov 15, 4:36 am, Abanowicz Tomasz <pawlac...@yahoo.com> wrote:
> Hello
> My @files array contains file names:
> 11.jpg
> 111.jpg
> 0121.pic
> 1.gif
> 1
> pic 1 cool.gif
> aaa1bbb.jpg
>
> I would like to "grep" files containing "1" digit and not "11", "111",
> "0121" etc.:
> 1.gif
> 1
> pic 1 cool.gif
> aaa1bbb.jpg
>
> I use the following to do that:
>
> grep (/[^0-9]+$i[^0-9]+/, @files)
>
> Unfortunately it does not match:
> 1.gif
> 1
>
> files.
>
> How should my grep look in order to cover those 2 files as well.
You need to look for a 1 that's preceded by either a non-digit or the
start of string, and followed by either a non-digit or the end of
string:
/(?:^|\D)1(?:\D|$)/
Paul Lalli
------------------------------
Date: Thu, 15 Nov 2007 04:01:39 -0800 (PST)
From: Paul Lalli <mritty@gmail.com>
Subject: Re: regular expression for digits
Message-Id: <1847704a-0cc5-4461-9e3b-764a03fcc901@w28g2000hsf.googlegroups.com>
On Nov 15, 4:45 am, Yann.Espos...@gmail.com wrote:
> Abanowicz Tomasz a =E9crit :
> > My @files array contains file names:
> > 11.jpg
> > 111.jpg
> > 0121.pic
> > 1.gif
> > 1
> > pic 1 cool.gif
> > aaa1bbb.jpg
>
> > I would like to "grep" files containing "1" digit and
> > not "11", "111",
> > "0121" etc.:
> > 1.gif
> > 1
> > pic 1 cool.gif
> > aaa1bbb.jpg
>
> > I use the following to do that:
>
> > grep (/[^0-9]+$i[^0-9]+/, @files)
>
> > Unfortunately it does not match:
> > 1.gif
> > 1
>
> > files.
>
> > How should my grep look in order to cover those 2 files as well.
> use * and not +
Please don't guess when you don't know the answer. This is blatantly
incorrect. grep (/[^0-9]*$i[^0-9]*/, @files) allows 0 nondigits
immediately before or after, but doesn't say anything about what comes
before or after the 0 nondigits.
Paul Lalli
------------------------------
Date: Thu, 15 Nov 2007 13:33:33 GMT
From: "Peter Jamieson" <ldolan@thinkinghatbigpond.net.au>
Subject: Rename files using directory names
Message-Id: <NUX_i.13265$CN4.10200@news-server.bigpond.net.au>
I have inherited many .rtf files contained in a directory structure like:
patient_data/patient1/2007_07_11/test1.rtf
where there are many patient directories such as patient1, patient2 etc
and many date directories such as 2007_07_11, 2007_07_09 etc
and there may be many .rtf files per patient and date combination.
What I would like to do is create new unique names for each .rtf file
based on the directory names: eg patient1_2007_07_11.test1.rtf
and put them into a new directory named patient_files.
I have checked out File::Find and tested the following script.
It lists all the files OK as expected like test1.rtf, test2.rtf etc
It merely replaces "_" with " " just as a test script.
However I cannot figure out how to do a rename for what
I would like the new file names to be namely in the
form of: patient1_2007_07_11.test1.rtf
Any help appreciated!, Cheers Peter
#!/usr/bin/perl
use warnings;
use strict;
use File::Find;
my $dir = '/patient_data/patient';
find(\&underscores, $dir);
sub underscores {
next if -d $_;
next if /^\./;
next unless /_/;
my $new_name = $_;
$new_name =~ s/_/ /g; # just for testing!
chdir($File::Find::dir);
rename($_, $new_name) or die $!;
print "$new_name \n";
}
------------------------------
Date: Wed, 14 Nov 2007 21:47:12 -0800 (PST)
From: "throwaway43054@gmail.com" <throwaway43054@gmail.com>
Subject: Repeating element string parsing and iteration
Message-Id: <80d62017-0f06-4ae4-b62b-0b37d9607433@c29g2000hsa.googlegroups.com>
Hi all! Noob to perl here...
I have widget with X sections, each having Y dimensions. The amount of
sections is dynamic, but amount of dimensions per section is static
(let's say it is always 3 dimensions per section).
I have a scalar which is a comma-delimited string of numeric values
representing values for all the combinations of section and
dimensions, such as:
$data = "value1,value2,value4,value5,value6,value7, ..."
So the first three values belong to first section, values 4-6 belong
to second section and so on.
I also have an array with names of the sections.
@sections= ("A, B, C, D");
I also have names for the dimenstions:
@dim_names = ("Xpos", "Ypos", "Zpos")'
I want to build a hash such as:
%section_data = qw/
"A-Xpos" => "value1",
"A-Ypos" => "value2",
"A-Zpos" => "value3",
"B-Xpos" => "value4",
"B-Ypos" => "value5",
...
...
/;
I'm not really sure how to tackle this. I was thinking of maybe doing
nested loops for section names and dimension names, chipping away at
@data using somehting like /\G.,?/g, but that seem a bit awkward and I
would love to know a better way. Any help is much appreciated.
Abstract code samples would be great! Thanks in advance!
------------------------------
Date: Thu, 15 Nov 2007 07:31:42 GMT
From: "John W. Krahn" <krahnj@telus.net>
Subject: Re: Repeating element string parsing and iteration
Message-Id: <473BF5BE.A51328A4@telus.net>
"throwaway43054@gmail.com" wrote:
>
> I have widget with X sections, each having Y dimensions. The amount of
> sections is dynamic, but amount of dimensions per section is static
> (let's say it is always 3 dimensions per section).
>
> I have a scalar which is a comma-delimited string of numeric values
> representing values for all the combinations of section and
> dimensions, such as:
> $data = "value1,value2,value4,value5,value6,value7, ..."
> So the first three values belong to first section, values 4-6 belong
> to second section and so on.
>
> I also have an array with names of the sections.
> @sections= ("A, B, C, D");
>
> I also have names for the dimenstions:
> @dim_names = ("Xpos", "Ypos", "Zpos")'
>
> I want to build a hash such as:
> %section_data = qw/
> "A-Xpos" => "value1",
> "A-Ypos" => "value2",
> "A-Zpos" => "value3",
> "B-Xpos" => "value4",
> "B-Ypos" => "value5",
> ...
> ...
> /;
>
> I'm not really sure how to tackle this. I was thinking of maybe doing
> nested loops for section names and dimension names, chipping away at
> @data using somehting like /\G.,?/g, but that seem a bit awkward and I
> would love to know a better way. Any help is much appreciated.
> Abstract code samples would be great! Thanks in advance!
Something like (UNTESTED):
my @fields = split /,/, $data, -1;
my %section_data;
for my $section ( @sections ) {
for my $dim_name ( @dim_names ) {
$section_data{ "$section-$dim_name" } = shift @fields;
}
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 15 Nov 2007 08:49:35 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Repeating element string parsing and iteration
Message-Id: <pan.2007.11.15.07.45.18@rtij.nl.invlalid>
On Wed, 14 Nov 2007 21:47:12 -0800, throwaway43054@gmail.com wrote:
> Hi all! Noob to perl here...
>
Hi,
> I want to build a hash such as:
> %section_data = qw/
You don't want qw her, just an opening parenthesis.
> "A-Xpos" => "value1",
> "A-Ypos" => "value2",
> "A-Zpos" => "value3",
> "B-Xpos" => "value4",
> "B-Ypos" => "value5",
> ...
> ...
> /;
>
>
> I'm not really sure how to tackle this. I was thinking of maybe doing
> nested loops for section names and dimension names, chipping away at
> @data using somehting like /\G.,?/g, but that seem a bit awkward and I
> would love to know a better way. Any help is much appreciated. Abstract
> code samples would be great! Thanks in advance!
Your direction is sound. Something like (untested):
my @data = split(/,/, $data);
my %section_data;
for my $section = (@sections) {
for my $dim = (@dim_names) {
$section_data{"$section-$dim"} = shift @data;
}
}
Or shorter:
my @data = split(/,/, $data);
my %section_data;
for my $section = (@sections) {
$section_data{"$section-$_"} = shift @data
for (@dim_names);
}
Any shorter would be obfuscation IMO.
HTH,
M4
------------------------------
Date: Thu, 15 Nov 2007 08:52:49 +0000
From: Justin Fletcher <gerph@gerph.org>
Subject: Re: sleep/fork/shell/SIGCHLD interaction problem
Message-Id: <Pine.LNX.4.63.0711150850550.4685@buttercup.gerph.org>
On Mon, 12 Nov 2007, Ben Morrow wrote:
>
> Quoth xhoster@gmail.com:
>> Justin Fletcher <gerph@gerph.org> wrote:
>>>
>>> I'm having a problem trying to get a simple program to respond the way
>>> that I expect. The basic premise is thus :
>>>
>>> 1. Fork a child.
>>> 2. Sleep for a while.
>>> 3. Do other stuff.
>>>
>>> This seems pretty simple, and I have a SIGCHLD handler which will catch
>>> my forked process if it exits. I thought everything was fine. Then I
>>> found that is I press ctrl-Z to suspend the parent whilst I'm running the
>>> program and then background it, it hangs.
>>
>> I find that this only occurs if I hit ctrl-Z from the keyboard. If I
>> send the process the TSTP signal via some other means, it doesn't happen.
>> I know that shells often respond to ctrl-Z, ctrl-C, etc, by sending signals
>> to entire process groups, rather than just the main process. I don't
>> exactly how this leads to the observed phenomena, though.
>
> SIGCHLD is sent to the parent whenever a child changes status. So when
> you press ctrl-Z, the whole process group is signalled, the child is
> stopped, and the parent gets a SIGCHLD. When the process group is
> resumed (bg or fg) the parent gets another SIGCHLD: since it hasn't
> responded to the first yet (because it was stopped), this is not
> usually apparent.
>
> If the OP really doesn't want SIGCHLDs when a child stops, he can
> install the signal handler explicitly with sigaction and SA_NOCLDSTOP
> (under systems which support that). Since one must assume that any
> number of children may have exitted when handling SIGCHLD anyway,
> including 0 in 'any number' is generally easier.
Thanks for your (everyone on this group) help! I hadn't appreciated that
SIGCHLD was delivered for all the information signals, or that there might
be multiple children present.
The explanations given have helped me resolve the odd hangs I've been
getting. Yay :-)
--
Gerph <http://gerph.org/>
... Over the hills and far away there's a place that's heaven.
------------------------------
Date: Thu, 15 Nov 2007 05:22:50 -0800 (PST)
From: Tim <TimKnoll@gmail.com>
Subject: Two Perl programming questions
Message-Id: <441c7317-87db-42fa-ad32-b19665c22761@l22g2000hsc.googlegroups.com>
I'm just starting out with Perl and I have two questions:
1) I want to be able to read a file and populate an HTML drop-down
list using Perl. How can I do this? I've found a Perl example to
read the contents of a text file and populate an array like this:
$data_file="SomeInput.txt";
open(DAT, $data_file) || die("Could not open file!");
@raw_data=<DAT>;
close(DAT);
The data is in the raw_data array. How can I return this value back
to HTML?
2) I want to be able to read a directory structure on the server and
use the directory names to populate an HTML dropdown list using Perl.
How can I do this?
Thank you in advance for any help. I greatly appreciate it.
Tim.
------------------------------
Date: Thu, 15 Nov 2007 07:24:37 GMT
From: "John W. Krahn" <krahnj@telus.net>
Subject: Re: Use of uninitialized value in concatenation
Message-Id: <473BF415.C81DD2EA@telus.net>
Ben Morrow wrote:
>
> Quoth gil <gil.kovary@gmail.com>:
> > when running Perl in "-w" mode, I get the following warning line:
> >
> > "Use of uninitialized value in concatenation (.) or string at ./
> > check_log.pl line 177, <DAT> line 261."
> >
> > when line 177 is:
> >
> > "if ($$ref =~ /^\[(\d+?)\/(\d+?)\/(\d+?)\s+?(\d+?):(\d+?):(\d+?)$
> > \]/)"
>
> Presuming this shouldn't be wrapped, the important part of this is
>
> /$\]/
>
> which is *not* an attempt to match a dollar followed by a square bracket
> but an attempt to interpolate $\ followed by an invalid close-character-
> class.
You got the first part right but because there is no
open-character-class the ']' is just a normal character.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 15 Nov 2007 11:20:49 +0000
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: using a function in map?
Message-Id: <13joasi8e7hgp9b@corp.supernews.com>
I'm doing this:
my @new_data = map { myfunc($_) } @old_data;
the body of myfunc is quite significant, and
this has worked well for me so far. The arrays
are arrays of complex data structures.
However, a change in requirment means that I now
what to be able to remove some of the elements
of old_data (in other words, not have them appear in @new_data).
But (as far as I can tell) there is NO value
returnable by myfunc that will do this for me.
If myfunc returns undef, I simply get an undef
in @new_data.
Advice on how to proceed welcome.
BugBear
------------------------------
Date: Thu, 15 Nov 2007 11:24:32 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: using a function in map?
Message-Id: <87k5ojpx8v.fsf@hacking.dk>
bugbear <bugbear@trim_papermule.co.uk_trim> writes:
> If myfunc returns undef, I simply get an undef
> in @new_data.
If undef otherwise is an invalid return valu you can just remove them
with grep. Then you will have something like:
my @new = grep { defined $_ } map { mynewfunc $_ } @old
//Makholm
------------------------------
Date: 15 Nov 2007 11:38:14 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: using a function in map?
Message-Id: <slrnfjobt5.qnk.abigail@alexandra.abigail.be>
_
bugbear (bugbear@trim_papermule.co.uk_trim) wrote on VCLXXXIX September
MCMXCIII in <URL:news:13joasi8e7hgp9b@corp.supernews.com>:
"" I'm doing this:
""
"" my @new_data = map { myfunc($_) } @old_data;
""
"" the body of myfunc is quite significant, and
"" this has worked well for me so far. The arrays
"" are arrays of complex data structures.
""
"" However, a change in requirment means that I now
"" what to be able to remove some of the elements
"" of old_data (in other words, not have them appear in @new_data).
""
"" But (as far as I can tell) there is NO value
"" returnable by myfunc that will do this for me.
""
"" If myfunc returns undef, I simply get an undef
"" in @new_data.
""
"" Advice on how to proceed welcome.
If you want myfunc not to return anything, then don't return anything.
Noone is keeping a gun to your head to actually put an expression after
'return', is there?
Abigail
--
my $qr = qr/^.+?(;).+?\1|;Just another Perl Hacker;|;.+$/;
$qr =~ s/$qr//g;
print $qr, "\n";
------------------------------
Date: Thu, 15 Nov 2007 04:07:04 -0800 (PST)
From: Paul Lalli <mritty@gmail.com>
Subject: Re: using a function in map?
Message-Id: <1c0e472f-535f-4a06-bd6e-cec1747b5ac1@w73g2000hsf.googlegroups.com>
On Nov 15, 6:38 am, Abigail <abig...@abigail.be> wrote:
> _
> bugbear (bugbear@trim_papermule.co.uk_trim) wrote on VCLXXXIX September
> MCMXCIII in <URL:news:13joasi8e7hgp9b@corp.supernews.com>:
> "" what to be able to remove some of the elements
> "" of old_data (in other words, not have them appear in
> "" @new_data).
> ""
> "" But (as far as I can tell) there is NO value
> "" returnable by myfunc that will do this for me.
> ""
> "" If myfunc returns undef, I simply get an undef
> "" in @new_data.
> If you want myfunc not to return anything, then don't return
> anything.
>
> Noone is keeping a gun to your head to actually put an expression
> after 'return', is there?
To add to what Abigail is saying: an empty 'return;' will return
undef in scalar context, but will return the empty list in a list
context. Contrasting, 'return undef;' will return undef in scalar
context, and a list containing undef in list context.
The map{} in your expression is evaluating your function in a list
context, and so if you want to return 'nothing', you need an empty
list. Hence, the empty 'return;' statement.
Paul Lalli
------------------------------
Date: Thu, 15 Nov 2007 12:29:33 +0000
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: using a function in map?
Message-Id: <13joetdgvkc1qa6@corp.supernews.com>
Paul Lalli wrote:
> On Nov 15, 6:38 am, Abigail <abig...@abigail.be> wrote:
>> _
>> bugbear (bugbear@trim_papermule.co.uk_trim) wrote on VCLXXXIX September
>> MCMXCIII in <URL:news:13joasi8e7hgp9b@corp.supernews.com>:
>
>> "" what to be able to remove some of the elements
>> "" of old_data (in other words, not have them appear in
>> "" @new_data).
>> ""
>> "" But (as far as I can tell) there is NO value
>> "" returnable by myfunc that will do this for me.
>> ""
>> "" If myfunc returns undef, I simply get an undef
>> "" in @new_data.
>
>> If you want myfunc not to return anything, then don't return
>> anything.
>>
>> Noone is keeping a gun to your head to actually put an expression
>> after 'return', is there?
>
> To add to what Abigail is saying: an empty 'return;' will return
> undef in scalar context, but will return the empty list in a list
> context. Contrasting, 'return undef;' will return undef in scalar
> context, and a list containing undef in list context.
>
> The map{} in your expression is evaluating your function in a list
> context, and so if you want to return 'nothing', you need an empty
> list. Hence, the empty 'return;' statement.
Perfect answer;
Thanks to both.
BugBear
------------------------------
Date: Thu, 15 Nov 2007 09:45:31 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Why is Errno.pm on CPAN
Message-Id: <87sl37q1tw.fsf@hacking.dk>
Is there any good reason to have Errno.pm at CPAN as an ordinary
module and not just part of core?
Both the cpan version and the core version tests that the Config.pm
the module was build with and used with is compatible. But this means
that the following steps breaks you perl installation at least on
linux:
1. install perl
2. install Errno.pm from CPAN
3. upgrade linux kernel
4. reinstall perl
The version check it self is sane and probably the best portable
check, but at least on linux it is a bit to strong.
But why would you install Errno from CPAN?
//Makholm
------------------------------
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 1035
***************************************