- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Please allow me to say that "TRWTF is Perl". Seriously, look at this:
<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?).
Admin
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!
Admin
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.
Admin
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...
Admin
<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:"
Admin
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].
Admin
Admin
Admin
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.
Admin
this troll is the least funny, yet most common... why bother?
Admin
The real WTF is being an idiot, and not using backticks, like:
$date =
date
;Admin
I don't think he got to that chapter in his "Perl for Dummies" book yet....
Admin
...or, for the "do it in one line" minded:
($month, $day, $year) = split("/",
date +%D
);Admin
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?).
Admin
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.
Admin
Since you asked:
<THEDATE> turns FILE_NOT_FOUND into False.
Admin
From my command line prompt: $ date ה' דצמ 30 16:39:49 IST 2010
Admin
Admin
I am not a programmer. Can someone please explain why a language would be created that does not have time/date functions?
Admin
People seriously bash perl* when PHP still exists in this universe?
*) There was only one language
Admin
C doesn't have time/date functions.
Like Perl, it does have libraries available which provide time/date functions.
Admin
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).
Admin
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.
Admin
... is possibly the archetypal Perl program. It's in chapter one of any Perl book.
Admin
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.
Admin
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?).
Admin
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.
Admin
Admin
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?
Admin
Please elaborate what you mean by "bad". Like how VB.Net is worse than C#?
Get educated then make comments...
Admin
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.
Admin
Let me explain this to you, it's really rather simple in a different language:
Captcha: populus, which I'm being a vox of.
Admin
ummm isn't the WTF that one would ever run PERL on XP? LOL
Admin
There is no WTF in the code. It follows the Perl rule that there is more than one way to do it.
Admin
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:
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:
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:
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
Admin
It is as Larry Wall wanted it to be.
The equivalent to:
... could, in some hypothetical C/Java-like language be:
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.
Admin
Well? Did he later remove the temp file or not?
The suspense is killing me.
Admin
Ok, what language is that?
Admin
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.
Admin
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
Admin
yeah, this is way to verbose. It should have been:
the default arguments for split are /\s+/ and $_.
Admin
Wow. How could anyone else say Perl has bad sytax after seeing this?
Admin
Admin
Admin
Haskell FTW!!!
Admin
[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.
Admin
This comment was originally posted January 11th, 2007.
Admin
FTFY
Admin
Admin
TRWTF, of course, is using chop() instead of chomp().
And, really, using a tempfile at all. The whole thing would be better written as: