• pbean (unregistered)

    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?).

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

  • (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
    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?).

    A) This has the effect of "While I can still read a next line from this filehandle do so and perform the following:

    B) While working in [language] I generally find it a good idea to know something about [language].

  • 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
    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?).

    what mean quite? not loud? i speak lot language and i no wat dey says but engrish alway suprizes

  • 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?).

  • (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).

  • (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
    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(/ /,$_);?

    while(<FILEHANDLE>) {
      chop;
      do something with $_;
    }
    

    ... is possibly the archetypal Perl program. It's in chapter one of any Perl book.

  • (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.

  • (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.

  • (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...

  • (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
    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.

  • (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)

    For the record, I've been a Perl programmer for the last 11 years. I wish I had a lot of my early code to submit to TDWTF, because I'm sure it'd be great.

    Re: Perl, it's a powerful tool. You can use it for good or for evil. A lot of people treat Perl like Voldemort (dangerous to even speak its name!), but I generally find that it's because the code that they've been exposed to uses some sort of obfuscated code and/or Perl wizardry. I don't think it's all that much better or worse of a language in itself-- but it's DEFINITELY got some of the highest potential to LOOK confusing.

    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? 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).

    Here at my company, we're surrounded by these things. When I got here, our code was FULL of this snippit:

    $today = `date +%Y%m%d` ;
    chomp $today ;
    

    In fact, some still linger... They say that on cold nights, you can still hear the sound of their 'chomps'.

    A better, pure-Perl way to do it is more like:

    @lt = localtime;
    $today = sprintf("%04d%02d%02d,$lt[5]+1900,$lt[4]+1,$lt[3]");
    

    And better still is to just break down and use the Date::Time library.

    We also still have one group that refuses to use the standard Perl-approved method of reading directories. Instead, they do something like this:

    @files = `ls -1 *.complete`;
    

    And you can guess what's happened on more than one occasion when the shell returns "too many matches" for the wildcarded *.complete string. But they don't want to screw with it because it's worked for so long, and hey, it's much easier to type.

    Anyway, like most programming languages, Perl is dangerous when it falls into the wrong hands.

    DaveE

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

    Even PHP is better than this rubbish. (...) but this snippet of code makes me violently sick with its strange quirks and syntax.

    It is as Larry Wall wanted it to be.

    The equivalent to:

    while(<THEDATE>) {
      chop;
      @x = split(/ /, $_);
    }
    

    ... could, in some hypothetical C/Java-like language be:

    while(String line = dateFile.readLine()) {
       line = line.stripLineEnding();
       String[] x = line.split(" ");
    }
    

    The Perl is terser because it uses Perl's built in <> syntax for filehandle reads, the "special" variable $, implicit use of $ as the argument to chop(), and the 'cute' function name "chop".

    But this is because Wall wanted Perl to be idiomatic. Again this is as basic a Perl pattern as "while(c=getchar())" in C.

    In this case, the programmer shouldn't have used a temporary file. But reading a file is a common thing to want to do, and this pattern is ubiquitous in Perl.

    Indeed, the programmer probably did it this way because he knew how to read a file -- it being such a common Perl pattern -- and hadn't encountered backticks.

  • (cs)

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

    The suspense is killing me.

  • (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
    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?).

    yeah, this is way to verbose. It should have been:

    @datevals = split;
    

    the default arguments for split are /\s+/ and $_.

  • 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)

    TRWTF, of course, is using chop() instead of chomp().

    And, really, using a tempfile at all. The whole thing would be better written as:

    open my $datefh, '-|', 'date'
        or die "help date is not installed";
    chomp(my $line = <$datefh>);
    my @datevals = split /\s+/, $line;
    close $datefh;

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

Log In or post as a guest

Replying to comment #333169:

« Return to Article