[Israel.pm] Perl signature - TTW (time to weekend)

Srikanth Madani srikanth.madani at vodafone.com
Wed Mar 17 10:29:23 PST 2004


Hi everyone,

I'm thinking of writing a JAPH. I had a look at a relevant presentation
http://ucan.foad.org/~abigail/Perl/Talks/Japhs/ which states some
'guidelines' for writing JAPHs.


I have the following two ideas:

1. To print the number of seconds till the weekend.

2. To print the number of days till my birthday [or other event of universal
significance ;-)]
I don't think there's any way of putting this in a signature. I had a look
at http://datetime.perl.org/index.html and even a program seems pretty
non-trivial.


I worked on the first one, and produced the following code:
> perl -e'($p,$i,$n,$k,$f,$l,$o,$y,$d,$s)=(localtime,"The weekend is
");print+qq($s);$o>4?print"here!\n":print+435660-86400*$o-3600*$n-60*$i-$p,"
seconds away!\n"'

Which produces:
	The weekend is 207539 seconds away!

I tried some data-hiding, and :
#!/usr/local/bin/perl
$_="87 69S69E75C69S78
68A32W73A83Y32!";($p,$i,$n,$k,$f,$l,$o,$y,$d,$s)=(localtime,join'',map(chr,s
plit/\D/));$o>4?print$s,HERE:print$s,435660-86400*$o-3600*$n-60*$i-$p,join''
,split/\d+/

This works fine in the script, but on the command line it fails and gives me
the message:

> perl -we '$_="87 69S69E75C69S78
68A32W73A83Y32!";($p,$i,$n,$k,$f,$l,$o,$y,$d,$s)=(localtime,join'',map(chr,s
plit/\D/));$o>4?print$s,HERE:print$s,435660-86400*$o-3600*$n-60*$i-$p,join''
,split/\d+/'
Not enough arguments for join at -e line 1, near "join,"
Not enough arguments for join at -e line 1, near "join,"
Execution of -e aborted due to compilation errors.

What am I doing wrong here?

Would love to have your suggestions on this.


Thanks,
Srikanth Madani
The day after tomorrow is the third day of the rest of your life.
(now you know why I want a JAPH :-)



ps: The original (unobfuscated) code looks like this:

_____________Perl code starts_________________________________
#!/usr/local/bin/perl -w
use strict;
use diagnostics;

my $epoch = time;
#Number of non-leap seconds since the epoch.
#(The epoch was at 00:00 January 1, 1970 GMT.)

my @time_array = localtime  $epoch;
my $wday = $time_array[6];
my $hour = $time_array[2];
my $min = $time_array[1];
my $sec = $time_array[0];

if ($wday > 4) {
        print "\nThe weekend is here! :-)\n";
} else {
        my $days_left = 4 - $wday;
        my $hours_left = $days_left * 24;
        $hours_left = $hours_left + (24 - $hour);
        my $mins_left = $hours_left * 60;
        $mins_left = $mins_left + (60 - $min);
        my $secs_left = $mins_left * 60;
        $secs_left = $secs_left + (60 - $sec);
        print "\nThe weekend is $secs_left seconds away!\n";
}
_____________Perl code ends_________________________________




More information about the Perl mailing list