Ask a Question related to PERL Miscellaneous, Design and Development.
-
John Taylor-Johnston #1
PHP vs Perl
Comparison study. Can this be done in Perl? How many lines?
<?php
$display_start = "2003-09-01";
$display_end = "2003-09-31";
echo "testing<br>";
$stuff = "$display_start - $display_end<br>";
if((date("Y-m-d") >= $display_start) && (date("Y-m-d") <= $display_end)){
print($stuff);
}else{
echo "Date expired: ".date("Y-m-d");
}
?>
John Taylor-Johnston Guest
-
Off Topic: Active Perl Native Windows / cygwin perl
I have both activestate windows native perl installed and the default cygwin perl. How can I have the cygwin shell use the windows perl rather... -
Control a non-perl image viewer from perl script
Below is a (non-finished) script that trys to run a linux viewer called eog (eye of gnome) in a script that will eventually allow me to power thru... -
Re : Installing CPAN Perl Modules with Activestate Perl 5. v5.8
Hi, In the process of trying to get perl modules installed, I downloaded over 300 Activestate specific perl modules and they work fine (of the ones... -
Effeciency question - perl scripts v's perl exe's
Max Adams wrote: The only existing Perl compiler is part of perl. Anything else is just a packager that puts a perl, required modules, and the... -
Designing Interfaces with Perl and Perl APIs
Hi, I am a long date perl programmer, and from time to time, I am having the same trouble: - To design interfaces for a self contained... -
Jay Tilton #2
Re: PHP vs Perl
John Taylor-Johnston <taylorjo@collegesherbrooke.qc.ca> wrote:
: Comparison study. Can this be done in Perl?
Yes.
: How many lines?
How many do you want?
Jay Tilton Guest
-
John Taylor-Johnston #3
Re: PHP vs Perl
Shortest :) Seriously. Can someone show me?
Thanks,
J
> : How many lines?
> How many do you want?John Taylor-Johnston Guest
-
Charlton Wilbur #4
Re: PHP vs Perl
>>>>> "JTJ" == John Taylor-Johnston <taylorjo@collegesherbrooke.qc.ca> writes:
JTJ> Comparison study. Can this be done in Perl? How many lines?
JTJ> <?php
JTJ> $display_start = "2003-09-01";
JTJ> $display_end = "2003-09-31";
JTJ> echo "testing<br>";
JTJ> $stuff = "$display_start - $display_end<br>";
JTJ> if((date("Y-m-d") >= $display_start)
JTJ> && (date("Y-m-d") <= $display_end))
JTJ> { print($stuff); }else{ echo "Date expired:
JTJ> ".date("Y-m-d"); } ?>
It's about as complex in Perl as it is in PHP, and you can even take
the same approach. Here's a hint: perldoc POSIX, look for strftime.
Charlton
--
cwilbur at chromatico dot net
cwilbur at mac dot com
Charlton Wilbur Guest
-
Jay Tilton #5
Re: PHP vs Perl
In future, please don't top-post replies.
John Taylor-Johnston <taylorjo@collegesherbrooke.qc.ca> wrote:
: > : How many lines?
: > How many do you want?
:
: Shortest :)
Be careful. Those are golfing words. :)
: Seriously. Can someone show me?
PHP has an advantage with that nice date() function. The strftime()
function in Perl's mountainous POSIX module has similar capabilities.
use POSIX 'strftime';
($display_start, $display_end) = ("2003-09-01", "2003-09-31");
print "testing<br>",
($n=strftime '%Y-%m-%d', localtime) ge $display_start
&& $n le $display_end
? "$display_start - $display_end<br>"
: "Date expired: $n";
Jay Tilton Guest
-
Purl Gurl #6
Re: PHP vs Perl
John Taylor-Johnston wrote:
Yes.> Can this be done in Perl?
If you are concerned about number of code lines,> How many lines?
you should not be programming. Appears you are
equating "less lines" with "better code." This is
very rarely true, indicating you still have much to
learn about programming.
> $display_start = "2003-09-01";
> $display_end = "2003-09-31";> if((date("Y-m-d") >= $display_start) && (date("Y-m-d") <= $display_end)){
Your parameters are less than adequate.
You are making a mountain out of a mole hill.
Using your stated parameters, you only need to range
test the last two characters of each variable. Only
range displayed by your parameters, is one to thirty-one,
inclusively.
Give this thought, as you should.
1 <= (current day) <= 31
first_day_month <= current_day <= last_day_month
Purl Gurl
Purl Gurl Guest
-
Peter Cooper #7
Re: PHP vs Perl
"John Taylor-Johnston" <taylorjo@collegesherbrooke.qc.ca> wrote:
Perhaps this horrible code will give you a clue :-)> Comparison study. Can this be done in Perl? How many lines?
use Time::Local;
my $a = timelocal (0,0,0, 1, 8, 103);
my $b = timelocal (59,59,23, 30, 8, 103);
if ((time > $a) && (time < $b)) { print "x"; }
I personally do not advise using the POSIX functions, as Perl is
cross-platform (read: works on non-POSIX platforms too). Convert times to
and from epoch time using Time::Local and localtime/gmtime, etc.. or use
Time::Piece objects (more elegant, and more code).
Pete
Peter Cooper Guest
-
Eric J. Roode #8
Re: PHP vs Perl
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
John Taylor-Johnston <taylorjo@collegesherbrooke.qc.ca> wrote in
news:3F593E88.23029739@collegesherbrooke.qc.ca:
$display_end)){> Comparison study. Can this be done in Perl? How many lines?
>
> <?php
> $display_start = "2003-09-01";
> $display_end = "2003-09-31";
>
> echo "testing<br>";
>
> $stuff = "$display_start - $display_end<br>";
>
> if((date("Y-m-d") >= $display_start) && (date("Y-m-d") <=Almost exactly the same:> print($stuff);
> }else{
> echo "Date expired: ".date("Y-m-d");
> }
> ?>
>
use Time::Format;
$display_start = "2003-09-01";
$display_end = "2003-09-31"; # Did you really mean 30?
print "testing<br>";
$stuff = "$display_start - $display_end<br>";
if(($time{"yyyy-mm-dd"} ge $display_start) && ($time{"yyyy-mm-dd"} le
$display_end)){
print($stuff);
}else{
print "Date expired: $time{'yyyy-mm-dd'}";
}
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBP1ojomPeouIeTNHoEQJG0ACgzFDEgt5E5GRmj8v5hR+mW8 vDH34AoPEB
FD85q2Q0QrCTqtNXQZE0tTPn
=3Hkg
-----END PGP SIGNATURE-----
Eric J. Roode Guest
-
Peter Cooper #9
Re: PHP vs Perl
"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote:
Very cool, never knew about this module before (there's always new ones> Almost exactly the same:
>
> use Time::Format;
hiding around the corner, I find!). I'll have to check this one out.
Pete
Peter Cooper Guest
-
Eric J. Roode #10
Re: PHP vs Perl
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
"Peter Cooper" <newsfeed@boog.co.uk> wrote in news:bjfbai$if621$1@ID-
194358.news.uni-berlin.de:
Well, I think it's cool -- but I'm biased; I wrote it. :-)> "Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote:>>> Almost exactly the same:
>>
>> use Time::Format;
> Very cool, never knew about this module before (there's always new ones
> hiding around the corner, I find!). I'll have to check this one out.
Thanks for your kind words, Peter.
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBP1tvrGPeouIeTNHoEQIupwCg9wvIhFb8N+2y7QVEBIw4Or Odc7sAn2h9
df2wE++VyKBuGL6ZhsaAeotJ
=r65E
-----END PGP SIGNATURE-----
Eric J. Roode Guest



Reply With Quote

