[32822] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4087 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 29 09:09:36 2013

Date: Fri, 29 Nov 2013 06:09:03 -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           Fri, 29 Nov 2013     Volume: 11 Number: 4087

Today's topics:
    Re: STDOUT beginner problem <derykus@gmail.com>
        What date was so many months and years before <gravitalsun@foo.com>
    Re: What date was so many months and years before <news@lawshouse.org>
    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 03:47:36 -0800
From: Charles DeRykus <derykus@gmail.com>
Subject: Re: STDOUT beginner problem
Message-Id: <l79ut2$aip$2@speranza.aioe.org>

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". Even though 
deadlock is still a danger, the following seemed to work well even with 
large html strings:

   use IPC::Run qw/run/;

   my @cmd = ('html2text');
   my $html = ....;
   run( \@cmd, \$html, \my $text);
   say $text;


-- 
Charles DeRykus


------------------------------

Date: Fri, 29 Nov 2013 13:57:00 +0200
From: George Mpouras <gravitalsun@foo.com>
Subject: What date was so many months and years before
Message-Id: <l79vd4$2gbq$1@news.ntua.gr>

#I want the calendar date of any number of years/months before.
# Currently I use the following, but maybe there is a better way.



use strict;
use warnings;
use Time::Local 'timelocal_nocheck';


my $Months = 21;
my $Years  = 4;


my $startfrom	= $^T;
$Years		+= int $Months / 12;
$Months		= $Months % 12;
my @STARTFROM	= localtime $startfrom;
my $d		= $STARTFROM[3];
my $m		= 0;
my $y		= 0;

	if ( $Months <= $STARTFROM[4] )
	{
	$y = $STARTFROM[5] - $Years;
	$m = $STARTFROM[4] - $Months
	}
	else
	{
	$m = 12 - $Months + $STARTFROM[4];
	$y = $STARTFROM[5] - $Years - 1
	}

my $max_month_days = How_many_days_have_a_month(1+$m, 1900+$y);
$d                 = $max_month_days if $d > $max_month_days;
my $backtime       = Time::Local::timelocal_nocheck(@STARTFROM[0..2], 
$d, $m, $y);



print "epoch : $backtime\n";
print "human : ", scalar(localtime $backtime) ,"\n";










#   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
}


------------------------------

Date: Fri, 29 Nov 2013 13:10:00 +0000
From: Henry Law <news@lawshouse.org>
Subject: Re: What date was so many months and years before
Message-Id: <JuadndkQI6G1DwXPnZ2dnUVZ8sudnZ2d@giganews.com>

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

-- 

Henry Law            Manchester, England


------------------------------

Date: Fri, 29 Nov 2013 05:51:03 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: What date was so many months and years before
Message-Id: <cl6h99h74db8k0p8rikqc0orjvg4kcdjm4@4ax.com>

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: 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 4087
***************************************


home help back first fref pref prev next nref lref last post