[32757] in Perl-Users-Digest
Perl-Users Digest, Issue: 4021 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 28 05:17:37 2013
Date: Wed, 28 Aug 2013 02:17:07 -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, 28 Aug 2013 Volume: 11 Number: 4021
Today's topics:
approach to calculating pay <cartercc@gmail.com>
Re: approach to calculating pay <hjp-usenet3@hjp.at>
Re: approach to calculating pay <cartercc@gmail.com>
Re: approach to calculating pay <uri@stemsystems.com>
Re: filemask to regex <gravitalsun@hotmail.foo>
Re: filemask to regex <ben.usenet@bsb.me.uk>
Re: filemask to regex <rweikusat@mobileactivedefense.com>
Re: filemask to regex <gravitalsun@hotmail.foo>
Re: filemask to regex <gravitalsun@hotmail.foo>
Re: filemask to regex <ben.usenet@bsb.me.uk>
Re: filemask to regex <rweikusat@mobileactivedefense.com>
Re: filemask to regex <rvtol+usenet@xs4all.nl>
Re: filemask to regex <rweikusat@mobileactivedefense.com>
Re: korean character sets <ben.usenet@bsb.me.uk>
Re: korean character sets <cal@example.invalid>
Re: Need suggestions to improve code <xhoster@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 27 Aug 2013 06:31:56 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: approach to calculating pay
Message-Id: <b5b32937-2ac8-4a86-81d9-175172bc3294@googlegroups.com>
This isn't strictly Perl question, but I've implemented this in Perl, and w=
ill re-implement it in Perl.
I have several contracts to build about five times a year. Among other prov=
isions, the 'contract price' is one of the provisions. While some are negot=
iated (and therefore beyond my ken) most can be calculated. I have built a =
function to calculate the pay, to which I pass about nine different paramet=
ers, and it returns a discrete integer, the 'contract price.' Rather than d=
escribe it, there is some semi-pseudo code below. As you will note, it cons=
ists of a large number (almost 100) of if-elsif statements.
Question: can someone recommend a better approach?
Thanks, CC.
my %contracts =3D get_contract_info_from_database();
foreach my $contract (keys %contracts)
{
#initialize about 20 different variables that constitute the contract ter=
ms
my ($site, $rank, $experience, $ftptstat, $jobtype, $level ... ) =3D pars=
e_row_from_hash($contracts{$contract);
$contract_price =3D calculate_contract_price($site, $rank, $experience, $=
ftptstat, $jobtype, $level ...);
#build and print each contract
}
sub calculate_contract_price
{
my ($site, $rank, $experience, $ftptstat, $jobtype, $level ... ) =3D @_;
my $contract_price =3D 0;
if ($jobtype eq 'a')
{
if ($level =3D=3D 1)
{
if ($rank eq 'A')
{
# etc for the rest of the nine parameters until, at the bottom, I have this=
:
# $contract_price =3D $hours * $production * 1288;
# (1288 constitutes the approved price for the work to be performed at the
# particular level, rank, site, time status, job type, etc.
}
elsif ($rank eq 'B')
{
}
elsif ($rank eq 'C')
{
}
else { warm "ERROR in rank, $rank\n"; }
}
elsif ($level =3D=3D 2)
{
}
elsif ($level =3D=3D 3)
{
}
else { warn "ERROR in level: $level\n"; }
}
elsif ($jobtype eq 'b')
{
}
elsif ($jobtype eq 'b')
{
}
else { warn "ERROR in jobtype: $jobtype\n";
return $contract_price;
}
------------------------------
Date: Tue, 27 Aug 2013 20:48:58 +0200
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: approach to calculating pay
Message-Id: <slrnl1pt50.2p6.hjp-usenet3@hrunkner.hjp.at>
On 2013-08-27 13:31, ccc31807 <cartercc@gmail.com> wrote:
> This isn't strictly Perl question, but I've implemented this in Perl, and will re-implement it in Perl.
>
> I have several contracts to build about five times a year. Among other provisions, the 'contract price' is one of the provisions. While some are negotiated (and therefore beyond my ken) most can be calculated. I have built a function to calculate the pay, to which I pass about nine different parameters, and it returns a discrete integer, the 'contract price.' Rather than describe it, there is some semi-pseudo code below. As you will note, it consists of a large number (almost 100) of if-elsif statements.
Please keep your lines at about 72 characters. Long lines are hard to
read.
> Question: can someone recommend a better approach?
>
> Thanks, CC.
>
> my %contracts = get_contract_info_from_database();
> foreach my $contract (keys %contracts)
> {
> #initialize about 20 different variables that constitute the contract terms
> my ($site, $rank, $experience, $ftptstat, $jobtype, $level ... ) = parse_row_from_hash($contracts{$contract);
> $contract_price = calculate_contract_price($site, $rank, $experience, $ftptstat, $jobtype, $level ...);
> #build and print each contract
> }
>
> sub calculate_contract_price
> {
> my ($site, $rank, $experience, $ftptstat, $jobtype, $level ... ) = @_;
> my $contract_price = 0;
> if ($jobtype eq 'a')
> {
> if ($level == 1)
> {
> if ($rank eq 'A')
> {
> # etc for the rest of the nine parameters until, at the bottom, I have this:
> # $contract_price = $hours * $production * 1288;
> # (1288 constitutes the approved price for the work to be performed at the
> # particular level, rank, site, time status, job type, etc.
> }
One obvious solution is a table, possibly with wildcards if not all
combinations are different:
my @rules =
(
{
site => 's1',
rank => 'A'
experience => 'high',
ftptstat => '*', # don't care
jobtype => 'a',
level => 1,
...
price => 1288.
}
);
sub calculate_contract_price {
my ($site, $rank, $experience, $ftptstat, $jobtype, $level ... ) = @_;
for my $rule (@rules) {
if (($rule->{site} eq '*' || $site eq $rule->{site}) &&
($rule->{rank} eq '*' || $rank eq $rule->{rank}) &&
($rule->{experience} eq '*' || $experience eq $rule->{experience}) &&
...
) {
return $hours * $production * $rule->{price};
}
}
}
Of course doing the same check on many variables implies that they
should be put into a common data structure, e.g. a hash:
sub calculate_contract_price {
my ($param) = @_;
RULE: for my $rule (@rules) {
for my $p (keys $param) {
next RULE unless ($rule->{$p} eq '*' || $param->{$p} eq $rule->{$p};
}
return $hours * $production * $rule->{price};
}
}
(WARNING: Untested code)
Of course that table can also be stored in a database, which means that
a non-programmer could edit it.
hp
--
_ | Peter J. Holzer | Fluch der elektronischen Textverarbeitung:
|_|_) | | Man feilt solange an seinen Text um, bis
| | | hjp@hjp.at | die Satzbestandteile des Satzes nicht mehr
__/ | http://www.hjp.at/ | zusammenpat. -- Ralph Babel
------------------------------
Date: Tue, 27 Aug 2013 13:23:15 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: approach to calculating pay
Message-Id: <a9d7cfe4-989b-4967-9369-a17137b649d5@googlegroups.com>
On Tuesday, August 27, 2013 2:48:58 PM UTC-4, Peter J. Holzer wrote:
> Please keep your lines at about 72 characters. Long lines are hard to
> read.
Yes, I'll try.
> One obvious solution is a table, possibly with wildcards if not all
> combinations are different:
One problem is that I have a flat algorithm for one kind of job (method) an=
d a decision tree for another method of job, and I'm trying to integrate th=
e approach. Another problem is that the data has a lot of errors, and I nee=
d to be able to dynamically test the data. Running it through some kind of =
cleaning up routine is more trouble than it's worth, since I just throw the=
bad data away, i.e., the contract is trashed. Still another problem is tha=
t some kinds of jobs have the metric built in, while others are a multiple =
of some metric.
But ... you have given me an idea which might work. I'll build two hashes, =
one for the piece work and the other for the flat rate, that might look lik=
e below. I can then freeze the hash and load it every time I call it, or pe=
rhaps put it into a flat file and reload the hash every time.
my (%pieces, %flatrate);
$pieces{level1}{experience1}{certification1}{size1} =3D 672;
$pieces{level1}{experience1}{certification1}{size2} =3D 1524;
$pieces{level1}{experience1}{certification1}{size3} =3D 2286;
...
$pieces{level2}{experience2}{certification2}{size1} =3D 927;
$pieces{level2}{experience2}{certification2}{size2} =3D 1854;
$pieces{level2}{experience2}{certification2}{size3} =3D 2781;
$flatrate{level1}{size1} =3D 125;
$flatrate{level1}{size2} =3D 100;
$flatrate{level1}{size3} =3D 50;
$flatrate{level2}{size3} =3D 200;
...
A big part of finding a solution to a problem is being able to articulate i=
t to another person. I find that explaining it clearly so that another pers=
on can understand the problem forces me to clarify it in my own mind, and s=
ome times the solution is self evident.
I appreciate your help. I won't work on this until October, but I'll rememb=
er to update this thread with the results.
CC.
------------------------------
Date: Tue, 27 Aug 2013 19:13:05 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: approach to calculating pay
Message-Id: <87zjs2vibi.fsf@stemsystems.com>
>>>>> "c" == ccc31807 <cartercc@gmail.com> writes:
c> my (%pieces, %flatrate);
c> $pieces{level1}{experience1}{certification1}{size1} = 672;
c> $pieces{level1}{experience1}{certification1}{size2} = 1524;
c> $pieces{level1}{experience1}{certification1}{size3} = 2286;
OOOOF!!
$pieces{level1}{experience1}{certification1} = {
size1 => 672,
size2 => 1524,
size3 => 2286,
} ;
learn to remove redundancy. in the above case it is faster, easier to
write and much easier to read.
you can make a nested data tree for the keys in there as well. if it
gets too deep and complex, assign some of the lower nodes into scalars
and assign those into the parent tree. this is basic perl data
structures. you should never see lines with those dup hash lookups in
each one.
uri
------------------------------
Date: Mon, 26 Aug 2013 01:19:15 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: filemask to regex
Message-Id: <kvdvt4$2gnq$1@news.ntua.gr>
Στις 25/8/2013 7:52 μμ, ο/η Rainer Weikusat έγραψε:
> George Mpouras <gravitalsun@hotmail.foo> writes:
>> I want to convert a OS filemask with possible wildcards to regex
>> What to you think of the following approach
>>
>> $mask = "??-media*.wm?";
>> $mask=~s|\*\.\*|\*|g; # *.* -> *
>> $mask=~s|\.|\\.|g; # . -> \.
>> $mask=~s|\?|.|g; # ? -> .
>> $mask=~s|\*|.*?|g; # * -> .*?
>> $mask=~s/(\(|\)|\+|\^|\[|\]|\{|\}|\$|\@|\%)/\\$1/g; #escape ()+^[]{}$@%
>> $mask = qr/^$mask$/i;
>
> I think I would again prefer to do a part-by-part lexical analysis of
> the input, mainly because this means that quotemeta can be used to
> quote metacharacters in the 'text' parts:
>
> ------------------
> sub xlate_tin_pattern
> {
> my $out;
>
> for ($_[0]) {
> /\G(\?+)/gc && do {
> $out .= '.' x length($1);
> redo;
> };
>
> /\G\*+/gc && do {
> $out .= '.*?';
> redo;
> };
>
> /\G([^?*]+)/g && do {
> $out .= quotemeta($1);
> redo;
> };
> }
>
> return $out;
> }
>
> print(xlate_tin_pattern($_), "\n") for @ARGV;
>
very good !
but the line
/\G(\?+)/gc && do { $out .= '.' x length($1); redo };
it fries my brain.
So I think I stick with the equivelant f1()
print xlate_tin_pattern('@s??im..pl%e.???a'), "\n";
print f1('@s??im..pl%e.???a'), "\n";
sub xlate_tin_pattern
{
my $out;
for ($_[0]){
/\G(\?+)/gc && do { $out .= '.' x length($1); redo };
/\G\*+/gc && do { $out .= '.*?'; redo };
/\G([^?*]+)/g && do { $out .= quotemeta($1); redo }}
$out
}
sub f1
{
$out=$_[0];
$out=~s/([^?*]+)/\Q$1\E/g;
$out=~s|\?|.|g;
$out=~s|\*+|.*?|g;
$out
}
------------------------------
Date: Sun, 25 Aug 2013 23:50:26 +0100
From: Ben Bacarisse <ben.usenet@bsb.me.uk>
Subject: Re: filemask to regex
Message-Id: <0.92c23a5f4b67ff2d25b0.20130825235026BST.87eh9hfkr1.fsf@bsb.me.uk>
Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
> George Mpouras <gravitalsun@hotmail.foo> writes:
>> I want to convert a OS filemask with possible wildcards to regex
>> What to you think of the following approach
>>
>> $mask = "??-media*.wm?";
>> $mask=~s|\*\.\*|\*|g; # *.* -> *
>
> [...]
>
>> $mask=~s|\*|.*?|g; # * -> .*?
>
> This sequence of conversion is wrong because it will translate *.* to
> .*?, ie, something which matches a string with not . in it.
I think that may be deliberate. I was going to ask "what OS>", but when
I saw that, I remembered that in MS-DOS (and maybe others), *.* means
all files. Similarly X*.* means all file beginning with X. (The reason
being that the . is not in the file name, just in the presentation of
it, though I still think that's a weak argument.)
I'm not saying the translation is correct -- I can't remember all of
MS-DOS's rules, and it's likely to be wrong of the target is not an
MS-DOS-like OS.
--
Ben.
------------------------------
Date: Mon, 26 Aug 2013 09:51:19 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: filemask to regex
Message-Id: <87sixwygvs.fsf@sapphire.mobileactivedefense.com>
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
>> George Mpouras <gravitalsun@hotmail.foo> writes:
>>> I want to convert a OS filemask with possible wildcards to regex
>>> What to you think of the following approach
>>>
>>> $mask = "??-media*.wm?";
>>> $mask=~s|\*\.\*|\*|g; # *.* -> *
>>
>> [...]
>>
>>> $mask=~s|\*|.*?|g; # * -> .*?
>>
>> This sequence of conversion is wrong because it will translate *.* to
>> .*?, ie, something which matches a string with not . in it.
>
> I think that may be deliberate. I was going to ask "what OS>", but when
> I saw that, I remembered that in MS-DOS (and maybe others), *.* means
> all files. Similarly X*.* means all file beginning with X. (The reason
> being that the . is not in the file name, just in the presentation of
> it, though I still think that's a weak argument.)
'DOS filenames'' (and very likely VMS filenames as well) are not plain
strings but consist of two components, a 'name' part and a 'type'
part, and because of this, *.* means 'all names and all types', ie
'every file'. If the input these patterns are supposed to be matched
against is really a list of 'DOS filenames', translating *.* to .*\..*
(or .+\..+) instead of .* (or .+) will make no difference because the
extension is always going to be there. But when it was just a list of
strings, making '*.*' match both abc and abc.def is IMHO
counterintuitive. It also precludes some possibly useful applications
such as 'match everything which has an extension'.
------------------------------
Date: Mon, 26 Aug 2013 11:52:49 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: filemask to regex
Message-Id: <kvf512$qn8$1@news.ntua.gr>
Στις 26/8/2013 1:50 πμ, ο/η Ben Bacarisse έγραψε:
>
> I'm not saying the translation is correct -- I can't remember all of
> MS-DOS's rules, and it's likely to be wrong of the target is not an
> MS-DOS-like OS.
>
yes you are corrrect it was intented, at windows the *.* means * !
but the Rainer aproach at his other answer is very clever and correct
------------------------------
Date: Mon, 26 Aug 2013 12:24:13 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: filemask to regex
Message-Id: <kvf6ru$vdm$1@news.ntua.gr>
if we forget the windows at bash there is also the interesting range
operator !
ls -l somefile{01,02,03,07}
ls -l somefile{01..05}
------------------------------
Date: Mon, 26 Aug 2013 13:25:20 +0100
From: Ben Bacarisse <ben.usenet@bsb.me.uk>
Subject: Re: filemask to regex
Message-Id: <0.9d9ee4fc0e114626b04d.20130826132520BST.87mwo4d4gf.fsf@bsb.me.uk>
Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>> Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
>>> George Mpouras <gravitalsun@hotmail.foo> writes:
>>>> I want to convert a OS filemask with possible wildcards to regex
>>>> What to you think of the following approach
>>>>
>>>> $mask = "??-media*.wm?";
>>>> $mask=~s|\*\.\*|\*|g; # *.* -> *
>>>
>>> [...]
>>>
>>>> $mask=~s|\*|.*?|g; # * -> .*?
>>>
>>> This sequence of conversion is wrong because it will translate *.* to
>>> .*?, ie, something which matches a string with not . in it.
>>
>> I think that may be deliberate. I was going to ask "what OS>", but when
>> I saw that, I remembered that in MS-DOS (and maybe others), *.* means
>> all files. Similarly X*.* means all file beginning with X. (The reason
>> being that the . is not in the file name, just in the presentation of
>> it, though I still think that's a weak argument.)
>
> 'DOS filenames'' (and very likely VMS filenames as well) are not plain
> strings but consist of two components, a 'name' part and a 'type'
> part, and because of this, *.* means 'all names and all types', ie
> 'every file'. If the input these patterns are supposed to be matched
> against is really a list of 'DOS filenames', translating *.* to .*\..*
> (or .+\..+) instead of .* (or .+) will make no difference because the
> extension is always going to be there.
I don't follow. If I get a list of DOS file names using, say, DIR,
those with no extension have no dot. .*\.\* won't match them but .*
will. You can write a file with no extension as "XYZ." as well as "XYZ"
but, IIRC, many programs dropped the '.' if there was no extension.
> But when it was just a list of
> strings, making '*.*' match both abc and abc.def is IMHO
> counterintuitive. It also precludes some possibly useful applications
> such as 'match everything which has an extension'.
I must be missing your point because I don't follow this either. The
DOS way to match names with an extension was to write *.?*, and the
suggested translation will work for that.
--
Ben.
------------------------------
Date: Mon, 26 Aug 2013 19:56:47 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: filemask to regex
Message-Id: <87k3j8b7rk.fsf@sapphire.mobileactivedefense.com>
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
>> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>>> Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
>>>> George Mpouras <gravitalsun@hotmail.foo> writes:
>>>>> I want to convert a OS filemask with possible wildcards to regex
>>>>> What to you think of the following approach
>>>>>
>>>>> $mask = "??-media*.wm?";
>>>>> $mask=~s|\*\.\*|\*|g; # *.* -> *
>>>>
>>>> [...]
>>>>
>>>>> $mask=~s|\*|.*?|g; # * -> .*?
>>>>
>>>> This sequence of conversion is wrong because it will translate *.* to
>>>> .*?, ie, something which matches a string with not . in it.
>>>
>>> I think that may be deliberate. I was going to ask "what OS>", but when
>>> I saw that, I remembered that in MS-DOS (and maybe others), *.* means
>>> all files. Similarly X*.* means all file beginning with X. (The reason
>>> being that the . is not in the file name, just in the presentation of
>>> it, though I still think that's a weak argument.)
>>
>> 'DOS filenames'' (and very likely VMS filenames as well) are not plain
>> strings but consist of two components, a 'name' part and a 'type'
>> part, and because of this, *.* means 'all names and all types', ie
>> 'every file'. If the input these patterns are supposed to be matched
>> against is really a list of 'DOS filenames', translating *.* to .*\..*
>> (or .+\..+) instead of .* (or .+) will make no difference because the
>> extension is always going to be there.
>
> I don't follow. If I get a list of DOS file names using, say, DIR,
> those with no extension have no dot. .*\.\* won't match them but .*
> will. You can write a file with no extension as "XYZ." as well as "XYZ"
> but, IIRC, many programs dropped the '.' if there was no extension.
I was under the not entirely correct expression that 'DOS filenames'
always had an extension. They actually do but the extension may be
blank. Text about the actual matching rules:
http://blogs.msdn.com/b/oldnewthing/archive/2007/12/17/6785519.aspx
Perl implementation of that which uses - instead of spaces in order to
show the 'trailing empty characters'
-----------------------
sub make_dos_pattern
{
my ($out, $pos);
$out = '-' x 11;
$pos = 0;
for (split(//, $_[0])) {
/\./ && do {
substr($out, 8) = '---';
$pos = 8;
next;
};
/\*/ && do {
substr($out, $pos) = '?' x (11 - $pos);
$pos = 11;
next;
};
if ($pos < 11) {
substr($out, $pos, 1) = $_;
++$pos;
}
}
return $out;
}
print(make_dos_pattern($_), "\n") for @ARGV;
----------------------
Such a pattern is then matched against a DOS 'directory entry' whose
'name' part consists of an 8 byte 'name field' and a 3 byte
'type/extension field'. The actual name parts are padded with spaces
until the end of their field if necessary. The . isn't part of the name
at all but switches from the name field to the type field when
'internal names' are created based on user input.
It may be possible to create a regex with equivalent matching
behaviour but not with a simple-minded translation. Defining some set
of 'alternate matching rules', eg ? ::= ., * ::= .*, makes IMHO more
sense here.
[...]
>> But when it was just a list of strings, making '*.*' match both abc
>> and abc.def is IMHO counterintuitive. It also precludes some
>> possibly useful applications such as 'match everything which has an
>> extension'.
>
> I must be missing your point because I don't follow this either. The
> DOS way to match names with an extension was to write *.?*, and the
> suggested translation will work for that.
According to the article the link points to, there is no 'DOS WAY' to
match only files with non-blank extensions.
------------------------------
Date: Mon, 26 Aug 2013 21:32:25 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: filemask to regex
Message-Id: <521bad49$0$15926$e4fe514c@news2.news.xs4all.nl>
On 24/08/2013 16:03, George Mpouras wrote:
> I want to convert a OS filemask with possible wildcards to regex
> What to you think of the following approach
>
> $mask = "??-media*.wm?";
> $mask=~s|\*\.\*|\*|g; # *.* -> *
> $mask=~s|\.|\\.|g; # . -> \.
> $mask=~s|\?|.|g; # ? -> .
> $mask=~s|\*|.*?|g; # * -> .*?
> $mask=~s/(\(|\)|\+|\^|\[|\]|\{|\}|\$|\@|\%)/\\$1/g; #escape ()+^[]{}$@%
> $mask = qr/^$mask$/i;
Also checkout `perldoc -f glob`.
--
Ruud
------------------------------
Date: Tue, 27 Aug 2013 12:59:00 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: filemask to regex
Message-Id: <87li3ns5tn.fsf@sapphire.mobileactivedefense.com>
Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
[...]
> I was under the not entirely correct expression that
[...]
Personal remark which seems appropriate here: Except when tightly
supervised, my mind has a tendency to invert things, as can be seen
here where I thought 'under the impression' and thus - without
noticing that - typed 'under the expression'. It's been a while since
I accidentally implemented an algortihm doing the exact opposite of
what it was supposed to do, but these days, I spend more time thinking
about the code I'm planning to write and less typing away and hashing
stuff out as the need arises which is probably the reason for
that. But it still happens fairly often in 'ordinary text'.
------------------------------
Date: Sun, 25 Aug 2013 23:29:33 +0100
From: Ben Bacarisse <ben.usenet@bsb.me.uk>
Subject: Re: korean character sets
Message-Id: <0.2ce7dc95669b209fa469.20130825232933BST.87k3j9flpu.fsf@bsb.me.uk>
Cal Dershowitz <cal@example.invalid> writes:
> On 08/24/2013 06:32 AM, Ben Bacarisse wrote:
>> Cal Dershowitz <cal@example.invalid> writes:
>
>>>> Why do you think this is a Perl question? It is more likely to be a PHP
>>>> one, so a PHP group might be better.
>>>
>>> [x-posted to c.l.php]
>>>
>>> I find that many applications are mixtures. For example, I would not
>>> use php to template a php page. The topic here is the perl templating
>>> of php and is topical in both these groups.
>>
>> Your previous post had no Perl and no Perl question. You now
>> cross-post to a PHP group and all I can find is some Perl code and a
>> report that you've fixed the PHP issue.
>>
>> I'll remove comp.lang.php since I see nothing PHP related here.
>
> Alright, but it basically amounted to you suggesting it and then
> unsuggesting it.
Yes, you got me. The message I replied to had not one line of Perl in
it. It did talk about PHP, linked to several .php URLs, and it
contained a reference to some PHP template files. The only questions in
it were a general one ("Why can't I get this right?") and one about HTML
meta charset declarations. But I see now it was about Perl.
This:
> I get you pretty well, but I'm a little stuck. Now I think I'm
> drawing a blank on the printf statement.
>
> Use of uninitialized value $caption in printf at ./russian1.pl line 109.
Talking your code and clipping it to a file suggests that line 109 is
the one before the printf. Did you post what you are running?
<snip>
> I thought I was figuring it out, but don't get why it cats nothing:
>
> http://merrillpjensen.com/pages/utf_1.php
I am not sure what anyone can do with this.
--
Ben.
------------------------------
Date: Wed, 28 Aug 2013 01:17:33 -0700
From: Cal Dershowitz <cal@example.invalid>
Subject: Re: korean character sets
Message-Id: <Pf2dnZ3PtIWDL4DPnZ2dnUVZ_qidnZ2d@supernews.com>
On 08/25/2013 03:29 PM, Ben Bacarisse wrote:
> Cal Dershowitz <cal@example.invalid> writes:
> This:
>> I get you pretty well, but I'm a little stuck. Now I think I'm
>> drawing a blank on the printf statement.
>>
>> Use of uninitialized value $caption in printf at ./russian1.pl line 109.
>
> Talking your code and clipping it to a file suggests that line 109 is
> the one before the printf. Did you post what you are running?
I did, but I want to get away from that for now.
>
> <snip>
>> I thought I was figuring it out, but don't get why it cats nothing:
>>
>> http://merrillpjensen.com/pages/utf_1.php
>
> I am not sure what anyone can do with this.
>
I think my machine or my brain wasn't working. This is from the
workplace 'sunday'. What I find myself wanting is to do is be able to
make these substitutions with more dynamic data. For example, I always
want to see the place and the date that something was written, because
the recycling of old news this way is a plague on social media in
particular.
So when perl creates this, I want it to be able to populate [ % written
%] with the current date. I was otherwise playing around with php dates.
$ pwd
/home/sites/migrate/sunday/php_template_stuff
$ ./vogon1.pl
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="/css/grass2.css"/>
<title>Tasks</title>
</head>
<body>
<?php
$b = time ();
print date("m/d/y",$b) . "<br>";
print date("D, F jS",$b) . "<br>";
print date("l, F jS Y",$b) . "<br>";
print date("g:i A",$b) . "<br>";
print date("r",$b) . "<br>";
print date("g:i:s A D, F jS Y",$b) . "<br>";
?>
<div class="wrapper">
<h3>, </h3>
<h1>Management-intensive endeavors</h1>
$ ./vogon1.pl
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="/css/grass2.css"/>
<title>Tasks</title>
</head>
<body>
<?php
$b = time ();
print date("m/d/y",$b) . "<br>";
print date("D, F jS",$b) . "<br>";
print date("l, F jS Y",$b) . "<br>";
print date("g:i A",$b) . "<br>";
print date("r",$b) . "<br>";
print date("g:i:s A D, F jS Y",$b) . "<br>";
?>
<div class="wrapper">
<h3>, </h3>
<h1>Management-intensive endeavors</h1>
$ cat vogon1.pl
#!/usr/bin/perl
use strict;
use warnings;
use Template;
my $tt = Template->new();
my $input = "header_center.txt";
my $vars = {
title => 'Tasks',
headline => 'Management-intensive endeavors',
};
$tt->process($input, $vars) || die $tt->error();
$
which results in the output first shown, which goes to stdout, which
doesn't really help too much.
http://merrillpjensen.com/pages/sunday_1.php
Q1) How can I do an end-around here, so that I can make my own
substitutions (without the Template process method) with something like
[% place %], given that I have a hash already defined with 'place' as a
key and the associated value is the one to be substituted, like this:
site => {
domain => 'http://nothing.com/',
language => 'russian',
place => 'Oakland',
},
Thanks for your comment,
--
cal
------------------------------
Date: Mon, 26 Aug 2013 18:58:01 -0700
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: Need suggestions to improve code
Message-Id: <kvh8fh$cbm$1@dont-email.me>
On 08/24/13 01:01, SSS Develop wrote:
> Hello,
>
> I am working on some data crunching/migration of data. Data is in
> postgresql database.
>
> The rows of data from where I am reading are more than 20 milions.
> While working on this data with normal (linear way) it is taking more
> than 2 days time to handle this data :(
That is 11 records per second, which seems to be astonishing slow. Why
is it so slow? Figure that out. Then either fix it, or use that
knowledge to do parallelization in an appropriate way.
>
> I thought of using Parrallel::ForkManager Perl module. Please help
> me optimize/improve following program.
>
> ------------- use strict; use warnings use DBI; use
> Parallel::ForkManager;
>
>
> my $MAX = 100;
$MAX of 100 seems awfully high, unless you have remarkable hardware.
"The beatings will continue until morale improves."
> my $pm = Parallel::ForkManager->new($MAX);
>
>
> my $dbh = DBI->connect( "DBI:Pg:dbname=" . 'postgres' . ";host=" .
> '192.168.1.1', "postgres", "postgres" ) or die DBI->errstr;
>
> my $query = $dbh->prepare("select id from secrete_records");
>
> $query->execute();
>
>
> while ( my $record = $query->fetchrow_hashref() ) {
>
> my $pid = $pm->start and next;
>
> # creating new Database connection
> my $dbh_internal = DBI->connect(
> "DBI:Pg:dbname=" . 'postgres' . ";host=" . '192.168.1.1', "postgres",
> "postgres" ) or die DBI->errstr;
You are creating a new connection for every record. While that
shouldn't take nearly 100 ms per connection and so it might not be rate
limiting in your case, it is still going to be pretty inefficient.
Alas, Parallel::ForkManager doesn't facilitate anything else, so maybe
ForkManager isn't the right thing to use.
> my $query_internal = $dbh_internal("select id, record_one, record_two
> from secrete_records where id=?")
Syntax error.
> $query_internal->execute($record);
execute does not accept a hash reference.
>
> Note:
>
> I am creating multiple connections with Database ($dbh,
> $dbh_internal). Not sure if that's required. I tried to use one
> connection but it trows error. Its related to SSL :( though I am not
> using database connection in SSL mode.
>
>
>
> Any other ways to handle such large number of data in Perl?
2 million is a fairly small number, not a large number. Figure out
*why* it is so slow, then speed it up.
Xho
------------------------------
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 4021
***************************************