• pbean (unregistered)
    Comment held for moderation.
  • Machtyn (unregistered)

    well... that's one way to do it.

    But, really... why not just get the time that the application was started, count the msec since it was started, then calculate date time from that? Much more efficient than write/read to disk!

  • WthyrBendragon (unregistered)

    Somebody needs to try their workaround from the command prompt before implementing it in code.

    Behavior of the date command varies across OS's and even between versions of OS's in the same family.

    On Windows XP the date command first responds with The current date is: Thu 12/30/2010

    then prompts the user for the new date.

    Redirecting this output without the /T switch will cause the system to wait, blindly, until somebody intervenes the prompt.

    Linux, Mac, Sparc, i Series users... your mileage may vary.

  • steenbergh (cs)

    Another infamous date: 12-12-2006. A customer of ours had the URLS of their web-app encoded. When requesting a certain report for the date 12-12-2006 the (.Net) system would deny the request and IIS would give the most cryptic message I ever saw.

    Turned out the encoded combination of the report name and the date resulted in a string of which .Net thought it was a hack-attempt. The hack was denied.

    We only found this out on december the 13th, and given the low impact and huge changes needed to work around this, the issue remained unresolved...

  • WthyrBendragon (unregistered) in reply to pbean

    <quote><THEDATE>? How can you while through that, what does it even do? </quote>

    In Perl - this has the effect of "While I can still read a next line from this file handle do the following:"

  • WthyrBendragon (unregistered) in reply to pbean
    Comment held for moderation.
  • wtf (unregistered)
    The Article:
    Sure, it's pretty easy to reference the DateTime module...
    "Reference" is a verb, not a noun. When are you people going to get you're language strait.
  • Ike (unregistered) in reply to pbean
    Comment held for moderation.
  • 3rd Ferguson (unregistered)

    For me the biggest thing about this that doesn't make sense is having the same process write out the date file and then immediately read it. As a slave to batch processing I have a process that writes the current date to a one row two column database table and then lots of other processes that use the date as a parameter. On occasions when I need to run my batches for a business date that's not the same as the calendar date (e.g., this Saturday when long-running year-end processes still need to think it's 2010) I can just not run the "set current date" process and let all the others think it's still yesterday.

  • H.P. Lovecraft (unregistered) in reply to wtf
    wtf:
    The Article:
    Sure, it's pretty easy to reference the DateTime module...
    "Reference" is a verb, not a noun. When are you people going to get you're language strait.

    this troll is the least funny, yet most common... why bother?

  • schrandal wartz (unregistered)

    The real WTF is being an idiot, and not using backticks, like:

    $date = date;

  • Anonymous Bastard (unregistered) in reply to schrandal wartz

    I don't think he got to that chapter in his "Perl for Dummies" book yet....

  • schrandal wartz (unregistered)

    ...or, for the "do it in one line" minded:

    ($month, $day, $year) = split("/", date +%D);

  • JustSomeGuy (unregistered)

    The first poster complains about Perl? What a waste. So let me be the first to say "Frist!". Also, if you're going to program in Perl, learn Perl (e.g. the localtime() function or at least backticks, anyone?).

  • Shondoit (cs)

    I actually used a similar thing in QBasic, back in the days.

    Granted I was learning myself programming and as I recall there wasn't proper date manipulation in QB. Either that, or I hadn't learned it yet.

    Of course, it was a home brew program, used to log the login and logout time.

    Ah, the good ol' days.

  • unekdoud (unregistered)

    Since you asked:

    <THEDATE> turns FILE_NOT_FOUND into False.

  • Shachar Shemesh (unregistered)

    From my command line prompt: $ date ה' דצמ 30 16:39:49 IST 2010

  • K (unregistered) in reply to steenbergh
    steenbergh:
    Turned out the encoded combination of the report name and the date resulted in a string of which .Net thought it was a hack-attempt.
    .Net may be bad, but I have a hard time believing it is that broken.
  • schmitter (unregistered)

    I am not a programmer. Can someone please explain why a language would be created that does not have time/date functions?

  • Jack (unregistered)

    People seriously bash perl* when PHP still exists in this universe?

    *) There was only one language

  • JH (unregistered) in reply to schmitter

    C doesn't have time/date functions.

    Like Perl, it does have libraries available which provide time/date functions.

  • JH (unregistered) in reply to Shachar Shemesh
    Shachar Shemesh:
    From my command line prompt: $ date ה' דצמ 30 16:39:49 IST 2010

    In fairness, sometimes you're coding in an environment where locale and host OS is known. I've written Perl that was intended to run only on our own AIX servers. Efforts to make it portable to other systems would have been wasted effort.

    Usually you want to use date modules from CPAN -- but I've had situations where backticks around GNU date was fastest way to implement a requirement (GNU date is awesome at parsing arbitrary date formats).

  • steenbergh (cs) in reply to K
    K:
    steenbergh:
    Turned out the encoded combination of the report name and the date resulted in a string of which .Net thought it was a hack-attempt.
    .Net may be bad, but I have a hard time believing it is that broken.

    It's four year ago now, and it was .Net 1.1, so I can't quite recall the actual message text and I don't think the newer platforms still suffer from this, but yes, that was (and probably still is) the issue. As said before, it needed some very specific circumstances.

  • JH (unregistered) in reply to pbean
    Comment held for moderation.
  • Kiss me I'm Polish (cs)

    Can't blame the guy. He's probably not a programmer, and all he needed was a quick script. Or maybe he hadn't used Perl in a long time, and didn't find it necessary to relearn the language. It's somewhat useless to read a 450 page book about a programming language, when you need only a 5 lines script. Especially an ugly language. Of course he could have thought of something slightly easier, and somewhat less inspired by Rube Goldberg. And even maybe he could have pondered the possibility of a date handling set of routines built into the language.

  • frits (cs) in reply to schmitter
    schmitter:
    I am not a programmer. Can someone please explain why a language would be created that does not have time/date functions?

    That would be more of a library role, rather than an integral part of a programming language. For example, the DateTime struct in .Net can be used in VB.Net, C#, C++, or J# (What's that?).

  • EatenByAGrue (unregistered) in reply to Jack
    Jack:
    People seriously bash perl* when PHP still exists in this universe?

    My guess is they bash Perl because they haven't had to contend with anything significant in sed or awk. Not that PHP is great or anything: it's handy for some web-based stuff, but it's way way too easy to write really bad code in it that kinda appears to work.

  • TGV (cs) in reply to unekdoud
    unekdoud:
    Since you asked:

    <THEDATE> turns FILE_NOT_FOUND into False.

    +100!

  • jdw (unregistered) in reply to schrandal wartz
    schrandal wartz:
    The real WTF is being an idiot, and not using backticks, like:

    $date = date;

    Definitely this. It's fine to use the OS's date feature if you're 100% certain of the formatting of the returned value, which, in many cases, you will be, due to your script being intended for a very specific location/OS/etc.

    But, not just dumping the return value of the OS command into a variable; rather, writing it to a file, then opening and reading from the self-same file? lolwut?

  • by (unregistered) in reply to K
    K:
    steenbergh:
    Turned out the encoded combination of the report name and the date resulted in a string of which .Net thought it was a hack-attempt.
    .Net may be bad, but I have a hard time believing it is that broken.

    Please elaborate what you mean by "bad". Like how VB.Net is worse than C#?

    Get educated then make comments...

  • ObiWayneKenobi (cs) in reply to Jack
    Jack:
    People seriously bash perl* when PHP still exists in this universe?

    Even PHP is better than this rubbish. Now, I appreciate the great strides that Perl made for us web developers in ages long past; many modern scripting languages like Python and Ruby pay homage to Perl and use some similar functionality but easier to understand, but this snippet of code makes me violently sick with its strange quirks and syntax.

  • Abstraction Elimination (unregistered) in reply to pbean
    Comment held for moderation.
  • coderdan (cs) in reply to WthyrBendragon
    WthyrBendragon:
    Somebody needs to try their workaround from the command prompt before implementing it in code.

    Behavior of the date command varies across OS's and even between versions of OS's in the same family.

    On Windows XP the date command first responds with The current date is: Thu 12/30/2010

    then prompts the user for the new date.

    Redirecting this output without the /T switch will cause the system to wait, blindly, until somebody intervenes the prompt.

    Linux, Mac, Sparc, i Series users... your mileage may vary.

    ummm isn't the WTF that one would ever run PERL on XP? LOL

  • Rob (unregistered)

    There is no WTF in the code. It follows the Perl rule that there is more than one way to do it.

  • davee123 (unregistered)
    Comment held for moderation.
  • JH (unregistered) in reply to ObiWayneKenobi
    Comment held for moderation.
  • boog (cs)

    Well? Did he later remove the temp file or not?

    The suspense is killing me.

  • coderdan (cs) in reply to Abstraction Elimination
    Abstraction Elimination:
    pbean:
    Please allow me to say that "TRWTF is Perl". Seriously, look at this:
    while (<THEDATE>) 
    {
      chop;
      @datevals = split(/ /,$_);
    }

    <THEDATE>? How can you while through that, what does it even do? chop;? @datevals = split(/ /,$_);?

    I know quite a number of programming languages, and when I see a new one I can generally figure out what a piece of code does. But Perl always knows how to surprise me over and over again with pieces of code which you just can't seem to figure out unless you explicitly know Perl.

    In my eyes that makes it a bad language (or perhaps all other languages are bad, not looking like Perl?).

    Let me explain this to you, it's really rather simple in a different language:

    import Data.List
    import System.Cmd
    import System.IO
    chop = filter (/= '\n')
    f' [] [] = Nothing
    f' x y = Just (x, if null y then y else tail y)
    split' = unfoldr . ((uncurry f') .) . (span . (/=))
    c' h = hGetLine h >>= (return . split' ' ' . chop)
    main = system "date >/tmp/the.date" >> withFile "/tmp/the.date" ReadMode c' >>= print

    Captcha: populus, which I'm being a vox of.

    Ok, what language is that?

  • JH (unregistered) in reply to boog
    boog:
    Well? Did he later remove the temp file or not?

    The suspense is killing me.

    It gets overwritten each time the routine runs, since the filename is constant. I wonder whether the accuracy of the date is sufficiently important that the race condition in concurrent execution is a problem.

  • Pedantic (unregistered)

    He should have used backticks with a Discordian date.

    ddate - converts Gregorian dates to Discordian dates

    $date = ddate;

    $ ddate Today is Prickle-Prickle, the 72nd day of The Aftermath in the YOLD 3176

  • lazy perl guy (unregistered) in reply to pbean
    Comment held for moderation.
  • Anonymous (unregistered) in reply to Abstraction Elimination
    Abstraction Elimination:
    import Data.List
    import System.Cmd
    import System.IO
    chop = filter (/= '\n')
    f' [] [] = Nothing
    f' x y = Just (x, if null y then y else tail y)
    split' = unfoldr . ((uncurry f') .) . (span . (/=))
    c' h = hGetLine h >>= (return . split' ' ' . chop)
    main = system "date >/tmp/the.date" >> withFile "/tmp/the.date" ReadMode c' >>= print

    Wow. How could anyone else say Perl has bad sytax after seeing this?

  • Ross (unregistered) in reply to davee123
    davee123:
    For instance, this is legal do-nothing code:

    perl -ne '} $^X -v; {' *

    Scary, huh? Who would honestly look at that and NOT run away screaming?

    Well, rather than run away screaming, I'm going to ask what it does. It does look intriguing.

    But today's WTF is a great example of someone learning Perl BADLY, and taking advantage of Perl's powerful scripting abilities without bothering to learn the Right Way(tm).
    I thought one of Perl's biggest credos was "there's more than one way to do it"?
  • mc (unregistered) in reply to pbean
    pbean:
    Please allow me to say that "TRWTF is Perl".
    Yeah, and that's probably why the author of the article took care to add a full description in human language of what the code actually does... :D
  • schrandal wartz (unregistered) in reply to Anonymous

    Haskell FTW!!!

  • JH (unregistered) in reply to Ross

    [quote user="Ross"][quote user="davee123"] I thought one of Perl's biggest credos was "there's more than one way to do it"? [/quote]

    Yes, but some ways are better than others, and some ways are just plain bad.

  • frits (unregistered)

    This comment was originally posted January 11th, 2007.

  • Fred (unregistered) in reply to coderdan
    coderdan:
    ummm isn't the WTF that one would ever run PERL on XP? LOL
    ummm isn't the WTF that one would ever run XP? LOL

    FTFY

  • moz (unregistered) in reply to coderdan
    coderdan:
    ummm isn't the WTF that one would ever run PERL on XP? LOL
    Sometimes XP is all you have. I'm sure there's even been the odd time when a Perl program on XP successfully wrote to '/tmp/the.date'.
  • Eevee (unregistered)
    Comment held for moderation.

Leave a comment on “Classic WTF: A Date of Infamy”

Log In or post as a guest

Replying to comment #:

« Return to Article