[32823] in Perl-Users-Digest
Perl-Users Digest, Issue: 4088 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Dec 1 21:09:41 2013
Date: Sun, 1 Dec 2013 18:09: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 Sun, 1 Dec 2013 Volume: 11 Number: 4088
Today's topics:
Re: STDOUT beginner problem <rweikusat@mobileactivedefense.com>
UNIX shell tools <framstag@rus.uni-stuttgart.de>
Re: UNIX shell tools <rvtol+usenet@xs4all.nl>
Re: UNIX shell tools <damien.wyart@free.fr>
Re: What date was so many months and years before <gravitalsun@foo.com>
Re: What date was so many months and years before <gravitalsun@foo.com>
Re: What date was so many months and years before <rweikusat@mobileactivedefense.com>
Re: What date was so many months and years before <rweikusat@mobileactivedefense.com>
Re: What date was so many months and years before <gamo@telecable.es>
Re: What date was so many months and years before <jurgenex@hotmail.com>
Re: What date was so many months and years before <gamo@telecable.es>
Re: What date was so many months and years before <gamo@telecable.es>
Re: What date was so many months and years before <jurgenex@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 29 Nov 2013 17:18:24 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: STDOUT beginner problem
Message-Id: <8761rbnn33.fsf@sable.mobileactivedefense.com>
Charles DeRykus <derykus@gmail.com> writes:
> On 11/26/2013 10:40 AM, Rainer Weikusat wrote:
>> mat.krawczyk@gmail.com writes
>>> ...
>>> open(HTML2TEXT, "| /usr/bin/html2text ") || die "html2text failed: $!\n";
>>> $text = print HTML2TEXT $html;
>>> close HTML2TEXT;
>>> print $text;
>>>
>>> but $text is empty and output is directed to STDOUT.
>>
>> Output is to stdout because you didn't redirect it somewhere
>> else. Generally, the built-in 'pipe open' can't do what you want (write
>> data to some process and read its output back). IPC::Open2 can do that,
>> although using that is not as straight-forward as it seems (there's a
>> chance that both processes deadlock because both wait for data written
>> by the other). One way to deal with that is to use select and switch
>> between reading and writing as required. Another reasonably easy way
>> would be to use three processes, one which reads the output from the
>> external command, a 2nd which runs it and a 3rd which feeds input to it.
>> ...
>
> The IPC::Open3 docs (Open2 is just a wrapper) now mention IPC::Run as
> "having better error handling and facilities than Open3".
Judging from the documentation, this is a particulary ghastly example of
feeping creatureism. There are 56 open bug reports, among them one where
the author inadvertently used a wrong function because he apparently
didn't know the name of the correct one and couldn't be bothered to
read the documentation,
https://rt.cpan.org/Public/Bug/Display.html?id=42885
That's not particularly confidence-inspiring, especially considering
that the 'benefit' is not having to write an odd dozen lines of code.
------------------------------
Date: Sat, 30 Nov 2013 09:19:46 +0000 (UTC)
From: Ulli Horlacher <framstag@rus.uni-stuttgart.de>
Subject: UNIX shell tools
Message-Id: <l7caji$op0$1@news2.informatik.uni-stuttgart.de>
I have written some UNIX shell tools which substitute or extend the
classical tools:
http://fex.rus.uni-stuttgart.de/fstools/
For example fpg is a grep which accepts perl regexp.
As a perl programmer, I am always confused which regexp syntax other
programs have. I want perl regexps everywhere :-)
My own most used tools are:
l list files
clp command line perl
fpg perl grep
zz generic clipboard
xx generic internet clipboard
Maybe you are interested.
--
Ullrich Horlacher Informationssysteme und Serverbetrieb
Rechenzentrum IZUS/TIK E-Mail: horlacher@tik.uni-stuttgart.de
Universitaet Stuttgart Tel: ++49-711-68565868
Allmandring 30a Fax: ++49-711-682357
70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/
------------------------------
Date: Sat, 30 Nov 2013 11:05:21 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: UNIX shell tools
Message-Id: <5299b862$0$15953$e4fe514c@news2.news.xs4all.nl>
On 2013-11-30 10:19, Ulli Horlacher wrote:
> I have written some UNIX shell tools which substitute or extend the
> classical tools:
>
> http://fex.rus.uni-stuttgart.de/fstools/
>
> For example fpg is a grep which accepts perl regexp.
> As a perl programmer, I am always confused which regexp syntax other
> programs have. I want perl regexps everywhere :-)
Many greps support -P (for PCRE), but since 'ack' I hardly ever use grep
anymore.
For example, to find issues in a full code base:
ack -a '^\s*return [^!(]\S* or\b'
which with grep would (be slow and) look like:
grep -rP '^\s*return [^!(]\S* or\b' .
- - - - - - - - - - - - - - - - - - - - - - - - - - -
To install ack:
cpan App::Ack
http://beyondgrep.com/install/
- - - - - - - - - - - - - - - - - - - - - - - - - - -
For speed, I also use 'git grep' a lot.
git grep -P '^\s*return [^!(]\S* or\b'
https://www.google.co.uk/search?q=%22git+grep%22
--
Ruud
------------------------------
Date: Sat, 30 Nov 2013 11:12:59 +0100
From: Damien Wyart <damien.wyart@free.fr>
Subject: Re: UNIX shell tools
Message-Id: <5299ba2b$0$3430$426a34cc@news.free.fr>
* "Dr.Ruud" <rvtol+usenet@xs4all.nl> in comp.lang.perl.misc:
> Many greps support -P (for PCRE), but since 'ack' I hardly ever use
> grep anymore.
There is also ag, which is often noticeably faster than ack:
https://github.com/ggreer/the_silver_searcher
--
DW
------------------------------
Date: Fri, 29 Nov 2013 16:51:36 +0200
From: George Mpouras <gravitalsun@foo.com>
Subject: Re: What date was so many months and years before
Message-Id: <l7a9ki$9st$1@news.ntua.gr>
Στις 29/11/2013 15:10, ο/η Henry Law έγραψε:
> On 29/11/13 11:57, George Mpouras wrote:
>> #I want the calendar date of any number of years/months before.
>
> Here's a useful web site:
>
> http://search.cpan.org/search?query=date+calculation
The same with Date::Manip
use Date::Manip;
my $date = new Date::Manip::Date;
$date->parse("epoch $^T");
$date->parse('-4:-21:0:0:0:0:0');
print $date->printf('%d %b %Y %H:%M');
: )
------------------------------
Date: Fri, 29 Nov 2013 17:18:04 +0200
From: George Mpouras <gravitalsun@foo.com>
Subject: Re: What date was so many months and years before
Message-Id: <l7ab64$du2$1@news.ntua.gr>
Στις 29/11/2013 15:51, ο/η Jürgen Exner έγραψε:
> George Mpouras <gravitalsun@foo.com> wrote:
>> #I want the calendar date of any number of years/months before.
>> # Currently I use the following, but maybe there is a better way.
>
> Is there anything wrong with Date::Calc?
>
> [long, awkward code snipped]
>
> jue
>
Date::Calc is also fine.
this is happening when you do not take the correct turn early
------------------------------
Date: Fri, 29 Nov 2013 16:09:03 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: What date was so many months and years before
Message-Id: <87eh5znqao.fsf@sable.mobileactivedefense.com>
Jrgen Exner <jurgenex@hotmail.com> writes:
> George Mpouras <gravitalsun@foo.com> wrote:
>>#I want the calendar date of any number of years/months before.
>># Currently I use the following, but maybe there is a better way.
>
> Is there anything wrong with Date::Calc?
>
> [long, awkward code snipped]
Replacing a small amount of 'awkward code' with a large amount of
'awkward code' isn't necessarily an improvement.
------------------------------
Date: Fri, 29 Nov 2013 16:29:48 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: What date was so many months and years before
Message-Id: <87a9gnnpc3.fsf@sable.mobileactivedefense.com>
George Mpouras <gravitalsun@foo.com> writes:
> #I want the calendar date of any number of years/months before.
> # Currently I use the following, but maybe there is a better way.
[...]
> # How_many_days_have_a_month(MONTH, YEAR)
> # MONTH 1 .. 12
> # YEAR e.g. 1970
> #
> sub How_many_days_have_a_month
> {
> my $month = $_[0];
> my $year = $_[1];
> my $days;
> my $leap_year;
>
> if ($year % 4)
> {
> $leap_year=0
> }
> elsif ($year % 100)
> {
> $leap_year=1
> }
> elsif ($year % 400)
> {
> $leap_year=0
> }
> else
> {
> $leap_year=1
> }
>
> if ($month == 1) {$days = 31}
> elsif ($month == 2) {$days = $leap_year ? 29 : 28}
> elsif ($month == 3) {$days = 31}
> elsif ($month == 4) {$days = 30}
> elsif ($month == 5) {$days = 31}
> elsif ($month == 6) {$days = 30}
> elsif ($month == 7) {$days = 31}
> elsif ($month == 8) {$days = 31}
> elsif ($month == 9) {$days = 30}
> elsif ($month == 10) {$days = 31}
> elsif ($month == 11) {$days = 30}
> elsif ($month == 12) {$days = 31}
> $days
> }
--------
sub leap_year
{
return 0 if $_[0] & 3;
return !!($_[0] % 100 || !($_[0] % 400));
}
sub days_per_month
{
my ($m, $y) = @_;
return 28 + leap_year($y)
if $m == 2;
return 30 + (($m & 1) ^ ($m >= 8));
}
print(days_per_month($ARGV[0], $ARGV[1]), "\n");
--------
A long time ago, someone wrote on USENET that 'mathematics has to be
taught to people so that they learn to think'. I'll wonder if the poor
sod ever figures out that 'written tests' teach people how to copy
someone else's solution unnoticed ...
------------------------------
Date: Sun, 01 Dec 2013 00:57:01 +0100
From: gamo <gamo@telecable.es>
Subject: Re: What date was so many months and years before
Message-Id: <l7du0f$bac$1@speranza.aioe.org>
El 29/11/13 17:29, Rainer Weikusat escribi:
> --------
> sub leap_year
> {
> return 0 if $_[0] & 3;
> return !!($_[0] % 100 || !($_[0] % 400));
> }
>
>
> sub days_per_month
> {
> my ($m, $y) = @_;
>
> return 28 + leap_year($y)
> if $m == 2;
>
> return 30 + (($m & 1) ^ ($m >= 8));
> }
>
> print(days_per_month($ARGV[0], $ARGV[1]), "\n");
> --------
>
This seems excellent. How would you implement delta_days?
TIA
------------------------------
Date: Sat, 30 Nov 2013 16:50:10 -0800
From: Jrgen Exner <jurgenex@hotmail.com>
Subject: Re: What date was so many months and years before
Message-Id: <2n1l99dn37l8gcgrha7n840ptru8c3elna@4ax.com>
gamo <gamo@telecable.es> wrote:
>How would you implement delta_days?
use Data::Calc;
$Dd = Delta_Days($year1,$month1,$day1,
$year2,$month2,$day2);
jue
------------------------------
Date: Sun, 01 Dec 2013 07:55:30 +0100
From: gamo <gamo@telecable.es>
Subject: Re: What date was so many months and years before
Message-Id: <l7emh3$nc5$1@speranza.aioe.org>
El 01/12/13 01:50, Jrgen Exner escribi:
> gamo <gamo@telecable.es> wrote:
>> How would you implement delta_days?
>
> use Data::Calc;
> $Dd = Delta_Days($year1,$month1,$day1,
> $year2,$month2,$day2);
>
>
> jue
>
Yes, thanks, I tryed that before and I encounter
extrange results.
http://www.telecable.es/personales/gamo/price.pl
Particulary with this function and Time_Date.
Maybe the differences are caused by the format
of the time: UTC then, CET now.
Best regards
------------------------------
Date: Sun, 01 Dec 2013 09:09:33 +0100
From: gamo <gamo@telecable.es>
Subject: Re: What date was so many months and years before
Message-Id: <l7eqru$v7j$1@speranza.aioe.org>
El 01/12/13 00:57, gamo escribi:
> El 29/11/13 17:29, Rainer Weikusat escribi:
>> --------
>> sub leap_year
>> {
>> return 0 if $_[0] & 3;
>> return !!($_[0] % 100 || !($_[0] % 400));
>> }
>>
>>
>> sub days_per_month
>> {
>> my ($m, $y) = @_;
>>
>> return 28 + leap_year($y)
>> if $m == 2;
>>
>> return 30 + (($m & 1) ^ ($m >= 8));
>> }
>>
>> print(days_per_month($ARGV[0], $ARGV[1]), "\n");
>> --------
>>
>
> This seems excellent. How would you implement delta_days?
>
> TIA
>
Here's all what my brain could make, using wour subs:
sub delta_days{
my ($d1, $m1, $y1, $d2, $m2, $y2) = @_;
my $delta =0;
my $ystep =1;
$ystep = -1 if $y1>$y2;
for (my $i=$y1; $i!=$y2; $i += $ystep) {
$delta += (365+leap_year($i))*$ystep;
}
my $mstep = 1;
$mstep = -1 if $m1>$m2;
for (my $j=$m1; $j!=$m2; $j += $mstep){
$delta += days_per_month($j)*$mstep;
}
$delta += ($d2-$d1);
return $delta;
}
TIA
------------------------------
Date: Sun, 01 Dec 2013 01:00:09 -0800
From: Jrgen Exner <jurgenex@hotmail.com>
Subject: Re: What date was so many months and years before
Message-Id: <k7ul99taa5j9mv38mkmono7td58hgkledo@4ax.com>
gamo <gamo@telecable.es> wrote:
>El 01/12/13 01:50, Jrgen Exner escribi:
>> gamo <gamo@telecable.es> wrote:
>>> How would you implement delta_days?
>>
>> use Data::Calc;
>> $Dd = Delta_Days($year1,$month1,$day1,
>> $year2,$month2,$day2);
>
>Yes, thanks, I tryed that before and I encounter
>extrange results.
>
>http://www.telecable.es/personales/gamo/price.pl
>
>Particulary with this function and Time_Date.
>Maybe the differences are caused by the format
>of the time: UTC then, CET now.
Well, if your dates are in different time zones then obviously your are
asking for trouble. So standardize to whatever single time zone you
prefer.
And when you do have your dates in some normalized format, then just
convert both into seconds since the epoch, compute the difference, and
divide by 24*60*60.
This is close enough for all practical purposes because when your output
unit is days then you don't care about leap seconds or hours
added/removed by summer time.
jue
------------------------------
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 4088
***************************************