|
Subotai posted:You should listen to Randal Schwartz over Damian Conway any day. *shakes fist at Damian Conway* So why are you posting here and not in the Smalltalk thread?
|
# ¿ Aug 4, 2008 18:21 |
|
|
# ¿ May 21, 2024 17:04 |
|
Have a look at Getopt::Whatever and Getopt::Casual, I bet one of those will do what you need.
|
# ¿ Aug 6, 2008 22:50 |
|
While in general you're certainly right (map { ... ? ... : () } is useful), in this case your code can be written as:code:
|
# ¿ Aug 27, 2008 15:15 |
|
I'd say that's acceptable. Symbolic references are forbidden by use strict because it's so easy to screw up in subtle ways with them, if they're allowed everywhere. In your case, the symbolic reference very obvious and deliberate, so it's okay. As a comment on your design, each $dbh should be replaced by a dbh method. Globals are a universal evil.
|
# ¿ Aug 28, 2008 23:03 |
|
syphon^2 posted:Is this the best way to sort hashrefs alphabetically (well, ASCI-betically)? Yes.
|
# ¿ Aug 29, 2008 17:41 |
|
Never.
|
# ¿ Sep 3, 2008 22:01 |
|
I was asked out of band for clarification. I never use direct hash access (outside of accessors of course). This was true even before I started using Moose for every class.
|
# ¿ Sep 3, 2008 22:07 |
|
Subotai posted:There is no need to try and abstract the internal data members of a class from itself. Your class will get more complicated. Having layers of abstraction will ease that evolution.
|
# ¿ Sep 3, 2008 22:33 |
|
Subotai posted:I for one find it much more of a pain in the rear end to have to write a function to access a data member in a class that I already have access to. If you're writing all of your accessors, yeah I can see how it would be too annoying to do regularly. I just do has foo => (is => 'rw'); of course.. Use Moose, Class::Accessor::Fast, Class::Accessor::Complex, Object::Tiny, I don't care! It is too much of a pain to define new and every accessor for every class. Subotai posted:Unless you really think you might have to go back and redo how or the information in the class is stored or handled, and it is too much work to actually change the hash in the places you use it, then go ahead and write an accessor function. I believe it mainly will be a waste of time, involve extra code that doesn't need to be there, and make the code harder to debug. The key here is to work with Perl's strengths. $self->accssesor is an error. $self->{accssesor} is a bitch to debug. Subotai posted:He is talking about a simple class in Perl. It shouldn't be something you turn into a monolithic piece of code. He probably shouldn't have any use for accssesor functions internally. It's a balancing act. The more complex your class becomes, the more you'll want the encapsulation. For me, the tipping point is when I bless.
|
# ¿ Sep 3, 2008 22:51 |
|
That sort of thing is called dynamic scope. It was popular before (the much saner) lexical scope was invented. Perl supports it with the local operator.
|
# ¿ Sep 17, 2008 07:05 |
|
Paradox posted:This cleanup is an implementation detail and should be hidden from the user if at all possible. Perhaps you want an END block. code:
Also, if you're doing OO, then the method called DESTROY will be called just before an object's memory is freed. If you really need to respond to a signal then I guess just install the signal handler.
|
# ¿ Sep 23, 2008 06:21 |
|
satest4 posted:$ echo 'END { warn "Dying!\n" } kill("TERM", -$$)' |perl That works, so it looks like we're.. Suffering from buffering
|
# ¿ Sep 23, 2008 20:42 |
|
Just a reminder that Devel::NYTProf is incredible. Tim Bunce gave a very informative Devel::NYTProf talk about what it does, how it does it, and how it's better than the others (which all kinda suck in different ways)
|
# ¿ Oct 4, 2008 18:17 |
|
I have a commit bit to Devel::NYTProf now, so if anybody wants to help support Windows, feel free to talk to me here or wherever. Triple Tech posted:Edit: I've been asked to do a really informal presentation on Lua to a group of Perl programmers, but I still want to take it seriously. Aside from generic "learn other languages" benefits, what can learning Lua give Perl programmers? Lua is actually very similar to Perl. Both provide high-level, orthogonal features. The biggest difference would be Lua's data structure: the table. They're like a hash and an array. Lua has metatables as well, which are actually very much like Perl's tying mechanism (running custom code when you get, set, etc. values in a variable). The feature is saner, and used a lot more in libraries, in Lua than in Perl. I can't think of any specific things that would help a Perl programmer though. I really like Lua, I just wish it had the CPAN.
|
# ¿ Oct 8, 2008 03:12 |
|
Triple Tech posted:Maybe I'm being too idealistic (probably) but if I was developing a sort of Perl tool, a meta-program if you will, I would have concentrated on making it work on the language level and not use any OS-level stuff. I'm sure it'll work fine on Windows once this one system call is figured out. It's not all going to come crashing down to support Windows. Besides, this kind of library really has to be built into the interpreter, not on top of it, so it'll be sensitive to different OSes.
|
# ¿ Oct 8, 2008 03:28 |
|
Typically I build a list of all the items, then use join ", ", @items to make sure there are commas only between items. If you have to process iteratively, then you can do something like: code:
code:
|
# ¿ Oct 12, 2008 02:41 |
|
local::lib is worth having a look at. It manages all the environment twiddling to let CPAN install into your home dir, and having Perl find it.
|
# ¿ Oct 25, 2008 22:55 |
|
There's going to be another Frozen Perl in Minneapolis on February 7th. I'll be there. I've submitted a talk for Devel::REPL and Carp::REPL that will probably be accepted (though I won't find out until November 20th). Anyone else planning on going?
|
# ¿ Oct 30, 2008 05:38 |
|
If you're logged into the conference site you can see something like this in your main page: (Since the conference I'm browsing from is Frozen Perl 2009 it doesn't link it)
|
# ¿ Oct 30, 2008 06:01 |
|
It is almost pure perl. It depends on PadWalker to get (and set!) lexical information for the entire stack. PadWalker is implemented in C but it's so loving useful that it may eventually get cored. The only other tricky bit is hooking into die. You can do this by sticking a code reference in $SIG{__DIE__} and it'll be run before the program aborts. code:
|
# ¿ Oct 31, 2008 02:34 |
|
ShoulderDaemon's way is probably best. It's the clearest which is the most important thing for code. Anyway, the operator you're looking for is splice. Here's how you can use it: code:
|
# ¿ Oct 31, 2008 23:00 |
|
Triple Tech posted:It's a shame that Devel::NTYProf doesn't work on Windows. 2.07, released today, does!
|
# ¿ Nov 1, 2008 20:21 |
|
Voltaire posted:[9,8,7,6,5,4,3,2,1,0] == [0,1,2,3,4,5,6,7,8,9] This doesn't work; equality for array references just checks if they point to the same array. You need to iterate over the elements. This seems terribly obtuse for a homework question. Job interview?
|
# ¿ Nov 9, 2008 21:48 |
|
What exactly do they forbid or allow? I ask out of curiosity; I'm not going to post a solution for you. The task is yours alone.
|
# ¿ Nov 9, 2008 22:05 |
|
ashgromnies posted:&is_palindrome($str) You do know that & is no longer required on function calls right?
|
# ¿ Nov 11, 2008 04:27 |
|
leedo posted:$string eq join '', split //, reverse $string reverse in scalar context will reverse the characters in the string. So just $string eq reverse $string is enough.
|
# ¿ Nov 14, 2008 21:30 |
|
Now you suck a little less. We're all always learning. Don't sweat it.
|
# ¿ Nov 14, 2008 21:36 |
|
I bet it's because Perl has to keep track of the value of $[, which controls the first index of an array. Then again, the perlvar doc says $[ has a compile-time effect. I'd still bet on it though. $#array is defined as the index of the last element of array @array, so must respect $[. scalar @array is defined as the number of elements in @array and can ignore $[.
|
# ¿ Nov 21, 2008 22:18 |
|
For those of you going to Frozen Perl (Triple Tech, you are, right?), I'm going to be giving two talks. My Devel::REPL/Carp::REPL talk was accepted, and now I'm also giving the Intro to Moose talk. It's going to be held in Minneapolis on Saturday, February 7th. If anything on the schedule piques your interest, come by and learn something!
|
# ¿ Nov 25, 2008 04:23 |
|
Lembark may be a dork but his Signal::StackTrace is handy. edit: I use it to find where my code is infinitely looping. A life saver every couple of months. Filburt Shellbach fucked around with this message at 04:44 on Nov 25, 2008 |
# ¿ Nov 25, 2008 04:39 |
|
Double negatives kick rear end
|
# ¿ Nov 26, 2008 04:22 |
|
Are you loving kidding me? Go take a programming course, go read a book, anything. You're wasting our time with retard questions.
|
# ¿ Nov 26, 2008 05:28 |
|
I hope you get the job buddy
|
# ¿ Nov 26, 2008 05:52 |
|
Maintain a separate hash of filenames you've seen thus far. Skip files you've seen.
|
# ¿ Dec 1, 2008 07:56 |
|
Set::Object probably has better memory and speed performance than hashes.
|
# ¿ Dec 1, 2008 08:03 |
|
Sets have fewer operations. You can add or remove items, and check if an item is in the set. Hashes have to do more work, tracking a value for each item. Though hashes are optimized as gently caress in Perl, sets can easily be made even faster.
|
# ¿ Dec 1, 2008 08:40 |
|
See perldoc -f system. I will not recommend the use of do EXPRESSION here (or anywhere ever).
|
# ¿ Dec 3, 2008 01:05 |
|
fyreblaize posted:sort{$a <=> $b}@x; cmp compares two strings, which is what you want. Because the default comparator for sort is cmp, just sort @x is all you need. edit: Oh, it's not really clear what you're actually trying to do. You're assigning the hash %results to the list @x which flattens the hash structure. Maybe sort { $results{$b} <=> $results{$a} } keys %resluts? Filburt Shellbach fucked around with this message at 03:38 on Dec 6, 2008 |
# ¿ Dec 6, 2008 03:35 |
|
For god's sakes read it!
|
# ¿ Dec 10, 2008 03:38 |
|
|
# ¿ May 21, 2024 17:04 |
|
Your time is worth more than the computer's. Design the program well; don't worry about function or method call overhead until it actually becomes a problem (and it hopefully never will). The term I've heard for what Triple Tech is describing is decoupling.
|
# ¿ Dec 16, 2008 22:15 |