Co-worker's third attempt at formatting a date...



  • my $date;
    ...
    my $i = -1;
    my @time = map { $_ += (++$i == 0 ? 1900 : ($i == 1 ? 1 : 0)); } @{[reverse @{[localtime(str2time($date))]}[0..5]]};
    print sprintf("%04d/%02d/%02d %02d:%02d:%02d\n",@time);

    Why he didn't use POSIX::strftime, the world will never know.



  • Does he not even realize that every current high-level (i.e. higher than C) language has some sort of basic date handling classes/functions? Or is he one of those people that still believes Perl should be a write-once-read-never language?



  • That looks almost exactly like the way my co-workers like to use Perl to extract date/timestamps into arrays and then use sprintf to put them back together....



  • @Dragnslcr said:

    Does he not even realize that every current high-level (i.e. higher than C) language has some sort of basic date handling classes/functions? Or is he one of those people that still believes Perl should be a write-once-read-never language?

     Even C has date/time formatting functions.
     



  • My favourite bit is:

    @{[...]}

    i.e. make an array/list into an arrayref, and then immediatly dereference it back to an array.



  • I think he believes in write-once, read never....



  • @SpoonMeiser said:

    My favourite bit is:



    @{[...]}

    i.e. make an array/list into an arrayref, and then immediatly dereference it back to an array.

     

    You must have missed the $_ += bit... Remember that $_ is actually an alias for the value... so he's modifying the temporary array, too.


Log in to reply