Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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...
    5. 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...
  3. #2

    Default 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

  4. #3

    Default Re: PHP vs Perl

    Shortest :) Seriously. Can someone show me?
    Thanks,
    J

    > : How many lines?
    > How many do you want?
    John Taylor-Johnston Guest

  5. #4

    Default 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

  6. #5

    Default 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

  7. #6

    Default Re: PHP vs Perl

    John Taylor-Johnston wrote:
    > Can this be done in Perl?
    Yes.
    > How many lines?
    If you are concerned about number of code 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

  8. #7

    Default Re: PHP vs Perl

    "John Taylor-Johnston" <taylorjo@collegesherbrooke.qc.ca> wrote:
    > Comparison study. Can this be done in Perl? How many lines?
    Perhaps this horrible code will give you a clue :-)

    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

  9. #8

    Default 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:
    > 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");
    > }
    > ?>
    >
    Almost exactly the same:

    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

  10. #9

    Default Re: PHP vs Perl

    "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.

    Pete


    Peter Cooper Guest

  11. #10

    Default 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:
    > "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.
    Well, I think it's cool -- but I'm biased; I wrote it. :-)

    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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139