- 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
Before or after? No, don't answer that. It just had to be said.
Admin
However, "it's" is shorthand for "it is", while the possessive case is written "its". It's one of the many little quirks of the English language. I would guess (not being one) that this is one of the things a native speaker would learn in elementary school.
Admin
Not anymore. :(
Doom. How apropos. Bwahahahaha
Admin
Possibly it does have some element of rocket science in it, since a reasonably intelligent person such as you is unaware that "one's" does have an apostrophe in it.
Admin
Admin
ok, thanks a lot. now the cognitive dissonance is going to have me boggle-eyed and slack-jawed all day.
Admin
Just remember Strong Bad's song!
o/~ Oh, if it's supposed to be posessive, then it's just i-t-s/But, if it's supposed to be a contraction then it's i-t-apostrophe-s! Scalawag! o/~
Admin
If you didn't know about perlfunc, you could read the perl man page, which directs you to many resources including perlfunc. If you didn't know about the man page, you could read the perl FAQ which directs you to the man page, as well as the perldoc perl page in case you don't have man installed. (The perldoc perl page also directs you to perlfunc.)
So yeah, if you're just blindly hammering on the keyboard, you're not going to find the reference material you need, but if you have 12 seconds to look for the information in one of several different ways, you'll find what you need.
Or you can be a copy/paste cargo cult programmer, and end up featured on this site.
Admin
your_prompt> perldoc -f -s
HTH
Admin
ObRuby:
mysize = File.new(filename).stat.size
I gave up Perl for Ruby. It's worth the performance drop to be able to avoid Perl syntax, and the performance thing will be addressed in 1.9 anyway...
Admin
First of all, by using >0 instead of >=0, you make this class worthless with streams that are open and still transmitting data -- network streams, for example. Second, you miss entirely the point that this still requires you to copy the bytes into memory and then write them. Java provides four gazillion classes, and they don't have one to abstract this process for the programmer?
Those classes work in the opposite direction than you typically want. Normally you're looking to take something from an InputStream, and put it out to an OutputStream. These classes take everything written to the output and provide it to the input. Also, if you use them both in a single thread, you could make the entire universe collapse on itself. Or maybe you'll just deadlock your thread; I don't know, I stopped paying attention.Admin
http://www.perl.org/ links to Online Documentation, and to FAQs. Perhaps from the FAQ page you could learn about perlfaq2: Obtaining and Learning about Perl and ask Where can I get information on Perl?. It would tell you about http://perldoc.perl.org/, among other things. And if you have a copy of the Llama book or the Camel book from O'Reilly, you'll find some assistance there as well. And if you read 'man perl', it says
and then presents you with an index to a variety of topics, including perlfunc.Now, I realize that there are a variety of valid complaints against Perl, but a) you honestly cannot expect to be able to sit down in front of a programming language and know everything you need to know in five minutes, so you should expect a need to consult with at least minimal documentation, and b) there are a wide variety of ways to stumble upon the proper documentation. I have no respect for programmers who would claim that this is an undue burden upon them.
Admin
that's called PHP -- and if you want to talk about what sucks, go look at the PHP ref docs for a while. Bottom line, if you're going to write in any language, at least have the decency to scan a language reference to get a feel for the types of functions, operators, etc.
Admin
Admin
Admin
Otherwise, it had to be a backup script to be statting that many files at once.
Admin
It's wide use does not mean that it doesn't suck. It's wide use is because it's been around for long enough, and prior to better languages that have come along since.
So, just 'cause it's used on X number of web sites, does NOT mean you should use it for yours.
Admin
Not true. Perl is a language that supports scripting, true. It does not impose scripting.
I have Perl programs that run to the thousands of lines, in which there are fewer than 10 lines in the global namespace [things like use directives], and no single sub that can not be viewed in its entirety in a single screen.
It's not the tool, it's the design decisions made by those using the tool.
Admin
rjnewton wins this thread.
The end.
Admin
What's wrong with a 24 hour perl script run? If it's doing a lot of IO (like reading the whole file and flushing the cache in order to get its size), then going to C won't be much faster.
for a 2G file, the piped command could take 10-20 seconds to complete. 500 calls to it = about 75 minutes.
Admin
This is actually fine, because when "9112cra" is interpreted in a numeric context, the letters will be dropped. It's only a problem if your filename begins with digits or the letter 'e', and since no one ever does that, there can't possibly be any problem. :D
Admin
Bzzzt. Sorry, try again:
If reading from a network socket which does not have any data available, read() will block.
Admin
You're right. I'm thinking of SocketChannel's read, not InputStream's.
Admin
The secret? I'm smart enough to know that I don't know everything, so I, uh, read the fucking manual instead of jumping in and assuming I would know how to do everything without having to learn.
I think that gives me the right to sneer.
Admin
This is supposed to be more intuitive? Do you really believe "stat" is more transparent to the average newbie than "-s" is?
That's like giving up herpes for rabies.
I tried Ruby once, and liked the syntax even less than Perl's. Pretending that everything should be an object is stupid - numbers are abstract concepts, not objects. And treating things like string literals as objects is just plain ugly.
Admin
I've got a password cracker that will take just shy of 14 months to exhaust all reasonable passwords for older *nix systems. Would you consider a 75-minute speedup to be worthwhile?
Admin
No, you'll have to read a real manual - especially for perl. If you try to google for it, you'll end up with answers from a bunch of wannabe's saying "I know the answer to this problem, but it's way below my skills to give you the answer." or "I found this problem solved after 2 sleepless weeks, and I'm not going to give you the answer such quick" ...
I call such boardmembers of any programming board or even newsgroup the RTFM BASTARDS ;) ... They'll never give you any helpful answer.
BTW. I'm always wondering about the energy such BASTARDS invest to write lengthy articles why not to give the answer ...
Admin
Lurk moar.
Admin
Well, as mentioned before, with Perl and File::stat you could write
$mysize = stat($filename)->size
and that looks quote similar to your code. OTOH, in Ruby you could also do it like this:
mysize = test(?s, filename)
Admin
This is proof that programmers should be shot on sight, and the ones who survive should be promoted to super-geekdom. Too many "programmers" are just imbeciles who read the first chapter of "Sams Teach yourself Minesweeper in 24 hours" and got their certificate. Any half-wit with any experience using ANY language would look for a file size function as one of the first steps of learning a new language. Frig even MS Batch files can fetch the file size, how ghetto is that ?
Admin
Some of Perl's shortcut test operators evolved from shell test operators and the test command.
And, if you prefer a more verbose way, someone has already mentioned that you can use the stat function.
What the hell is wrong with being concise, anyway? It's not my problem that you can't read it and can't take the time to learn.
Admin
Actually, it won't work for file sizes over 8 digits.
Perl will happily turn "9112cra" into the number 9112 as soon as you try to do a numeric operation on it. Don't believe me, try this:
or
There are also several versions of wc out there. The one included with Solaris 10 puts the number in an 8-character field padded with spaces (if it <= 8 digits). Thus for any file with a size <= 8 digits work perfectly with this particular wc.
Admin
So what you're saying is that a reasonable search query turned up not one but two ways to do it on the very first result, plus it has the exact perldoc commands you should type if you want more information.
OMG PERL IS HARD LIEK U CANT GUESS THE FNUCTIONS PERL IS THE REAL WTF
Admin
perl inexperience is beside the point. the code is bad in any language.
a coder's inner "ridiculously inefficient" alarms should go off when they see this kind of code. O(n^2) alarms. alarms that tell you that this only ok if you do it once in a while.
even if the coder was using bash, he'd have to sense the evil caused by this piece of code. somewhere deep in his gut, some voice should be telling him, "there has got to be a better way."
The multiplication of the code indicates that the coder had no idea what the runtime cost of this code was. or perhaps didn't care.
Admin
[snip] diaphanein: If that's the only set you consider, then yes. There are (other) scripting languages that don't suck, that aren't cryptic, that don't inherently lend themselves unreadable, unmaintainable code.
Sure, but do they have the advantages perl has? -regular expressions -C-like syntax for easy adoption -large user base -large installed base on random machines
The only one that comes close is Python, which isn't any more maintainable or readable than Perl.
I've been programming in Perl for close to 10 years and I have yet to see code that I can't read except for an obfuscation contest.
[/snip]
I agree. If you take the time to LEARN how to use a language, it is not "mysterious" or "non-intuitave" to use. It is only difficult to read or maintain if you are a "one language wonder" and the language you know is not the one in use...
Admin
That, and CPAN.
Admin
PERL...
The problem I have with perl is that its conciseness is confusing. If I needed to edit perl on a daily or even weekly basis, I might look into 'just finding the documentation' and then reading it, rereading it, trying it, failing, and trying again to understand what it's supposed to be doing. So, for me, it's not a problem of finding how to write something (I can do that!) but a problem of trying to decipher what others' 'simply concise' code actually means.
So: writing in perl...easy reading perl...difficult maintaining perl...can be really difficult or really easy!
Oh, on an aside: I hate Python.
Admin
I confess to using that. Not because I think that it's the best way,but because it's quicker to type than using perl's built-in. However, I wouldn't use it on a production system.
Admin
www.yalla-casablanca.com
Admin
PHP sucks for some reasons but its popularity is not hard to understand ... a PHP application is easy to deploy (easier than with Perl, Python, Java, whatever), it is cheap to deploy because of PHP's nature (compared to Java and .NET which are quite expensive), the PHP interpreter has a reasonable speed, it can be easily extended by C modules ... thus it can connect to a wide variety of services, there are countless of open-source applications and framerworks already built for it ... and put simply ... It Gets The Job Done in most cases.
PHP is quite a mature, stable and robust platform for web apps ... and if you can't see that from your ivory tower that doesn't mean the rest of us are blind too.
Admin
Admittedly, I did have to do a bit of digging to locate strftime() the first time I wanted it, but I wouldn't consider it that much slower to type... I guess having to add the use() to your preamble makes it forgivable. ;]
But not, as you say, on production systems.
Admin
I'm sure you are a joy to work with. We can only hope that whoever inherits your code knows about thedailywtf.
Admin
Hold your horses man, "man perl" will refer the reader to "man perlfunc".
Admin
Indeed, I lose. "One's" isn't a personal possessive, it's an indefinite possessive.
But it must be somewhere between middle school & rocket science.
Admin
or even better:
$filesize = filesize($file);
Admin
I would say he was ignorant of hashes, but he used them at the start of every script to grab the CGI parameters. He also used a whopping 4 subroutines in the 2 dozen scripts I've rebuilt. One script included an entire cut & paste of the tax calc code 4 times.
Admin
I really liked this thread, nice how folks come up with an example in there favorite language.
From experience i can tell: if a job falls in all other environments, it can be done in perl.
When switching between languages, switching to perl takes the most adjustment of one's mind.
one's ... every board has it's Captain Pedantic.
The end.
Admin
Admin
Yes, that stuff about being faster is clearly bollocks. :P
Admin
Hear, hear!