|
ashgromnies posted:What the hell is a closure? I read your example and didn't understand WTF was going on and I'm most of my way through a CS degree. A reference to a subroutine that carries scoped data. code:
Very powerful and useful concept. Also, regarding the "closure as object" concept, don't forget that you can bless function references.
|
# ¿ Feb 21, 2008 22:59 |
|
|
# ¿ May 2, 2024 12:06 |
|
Sartak posted:It's even more than that. To have a closure, the variable has to be defined outside of the function. In CSey words, it needs to be a "free variable" in the scope of the function. Interesting, I'd not realized a closure differed from an anonymous sub based on it encapsulating data from a higher scope. quote:
I'm curious why you chose to incur the overhead of AUTOLOAD and bring in PadWalker to accomplish this. Why not use a hash reference? If you really want accessors, you could define a simple object, or even bless the hash into Class::Accessor::Fast and attach some.
|
# ¿ Feb 22, 2008 00:38 |
|
Puck42 posted:
The word 'index' is a MySQL reserved word, so: code:
|
# ¿ Feb 29, 2008 03:22 |
|
ashgromnies posted:I need some help with Catalyst exception handling. Catalyst's error handling is horrible. Remember that if you are in a controller dispatch, exceptions get wrapped to Catalyst errors (which I absolutely hate). By default Catalyst will check $c->error at the end of a request and show its goofy error page. To override the default error handler, you need to check $c->error yourself (usually in MyApp::end()). code:
|
# ¿ Mar 7, 2008 16:33 |
|
What are you accomplishing by using threads? It seems like a job queue might be a better fit for what you are trying to do. Have the worker update the job status as it processes it, then just let your Catalyst action query the job status. This has the benefit of being asynchronous. Also, in this statement: code:
code:
|
# ¿ Mar 7, 2008 20:29 |
|
ashgromnies posted:So no one knows how to get around the fact that Catalyst writes out session variables at the end of the request? I tried using a Cache, that didn't work either Sessions are implemented as plugins (last I had seen anyway), so you are bound by the plugin implementation and the various Catalyst phases. The intent of a "session" is to preserve state between HTTP messages, not within one request, so it should not be an issue when the session state is committed. I suspect you may be using the wrong tool for the job, but to be honest I'm not sure I'm correctly discerning exactly what you are wanting to do (maybe that's why others are not responding). Adding threading to an application greatly affects how MVC should be applied.
|
# ¿ Mar 10, 2008 21:06 |
|
How about this?code:
|
# ¿ Mar 14, 2008 17:01 |
|
yaoi prophet posted:It's only run-time checking, of course, but it's an interesting (ab)use of subroutine attributes. Isn't it sad that there are so many modules like this on CPAN? There are tons and tons of attempts to add things to the language to make it seem modern and sane. I think it was a big mistake to set perl adrift to work on parrot and perl6. There's some cool stuff out there, like Moose, but the fact that it needs to exist is a red flag. And the problem with all of this run-time compensation is that it really does take its toll on performance with heavy use (and I'm of the opinion that you either use it everywhere or not at all). Plus it adds to module dependency hell. For example, to install Catalyst you basically become a CPAN mirror... it's horrible.
|
# ¿ Mar 20, 2008 18:38 |
|
poofactory posted:x_amount => "12.23", The "12.23" is a string literal. So is "Amount". Your $Amount is a scalar variable, which is a thing that holds whatever value is assigned to it. Whenver you say $Amount, perl treats it as "the value stored in $Amount". When a scalar variable appears in a double-quoted string (like the last line above) it will be evaluated, meaning its value is replaced into the string at the position it occurs. You don't need the quotes in your above code ("$Amount" and $Amount are the same here). Also, I'm not sure what's going on in the rest of your script, but something has to assign a value to $Amount before it will be useful to you. In your case, you want to assign it the data from the HTTP request form input. How you do that depends on what perl modules you are using to work with request data.
|
# ¿ Apr 2, 2008 18:59 |
|
German Joey posted:http://search.cpan.org/~davecross/Symbol-Approx-Sub-2.06/ Oh god. Every time I see a module like this I laugh until I realize there are probably people using it in production.
|
# ¿ Apr 4, 2008 17:15 |
|
Catalyst started off great, but it has become a gigantic bloated pig. The whole project went into the woods after a while. I've looked at all the perl frameworks at length, and I can't say I like any of them anymore. What I'd really like to see is something that very efficiently processes the HTTP request of an environment (CGI, mod_perl, etc) into some object, and a fast url->action mapper. That's the only parts of a framework I find I actually want. The rest is all crap from CPAN (and I do mean crap). quote:Continuity... Continuity is a neat idea, but it's not extremely useful since its going to have much steeper memory requirements than the traditional approach. That's a bad thing in a perl environment.
|
# ¿ Apr 6, 2008 18:32 |
|
Triple Tech posted:I tried jamming the substr's into a list (@array = substr, substr, substr), that made it slow. The col_width technique that heeen posted wouldn't work because each column is different. And I'm pretty sure using a regexp would be universally slower than unpack or substr. I'm not following your description of the data. I think you are saying: 1.3 million records, each record has 160 fields, and you know the width of each field? You should be able to smoke through that. Are the fields all text or are some binary? Is the data in a flat file? How are you reading from that (seek/read I hope)? quote:Edit: I also tried pushing them onto a stack instead of having Perl make that temp list, but it was still slow. I can't believe scalars are so much faster than arrays... You're probably doing this already, but make sure you are using array references and not pouring data through list context needlessly. Here's why: code:
code:
|
# ¿ Apr 7, 2008 21:16 |
|
TiMBuS posted:I went hunting today, and I concur. All I really want are sessions handled for me, a pluggable, easy to manage template system and automatic dispatching. Oh and the ability to specify different methods of dispatch handling. And sessions and templating are (rightly) not even provided by the framework. I think people go in this progression of "acknowledge anarchy -> adopt framework -> learn patterns -> rewrite large chunks of framework -> wonder why they need a framework". And don't even get me started on template systems.
|
# ¿ Apr 7, 2008 21:24 |
|
Khorne posted:How do I convert an a4 value in perl (DWORD) to a string, or at least a decimal/hexadecimal number that I can pad some how? Check out pack() and unpack(). code:
|
# ¿ Apr 8, 2008 01:55 |
|
Zombywuf posted:I find your requirements strange and disturbing. URL->action mapping is not a strange thing to want at all. It is much more inline with HTTP to make application requests by path than by query string, and having a good URL structure is very important for things like Google indexing. TiMBuS posted:Template Toolkit and Mason forgot what the hell a template was a long time ago. Yeah, both of these could be put out to pasture. They are mostly relics of the big transition to embedded scripting many years ago, back when ASP and PHP first really caught on. Now the fad is frameworks. I wonder what's next after that fizzles. It's amazing that Perl has managed not to change at all during any of this.
|
# ¿ Apr 8, 2008 02:08 |
|
permanoob posted:It isn't dying and open RETURNS no. I just tried printing and dieing the $dest_file value. Print outputs the correct file name it should be writing to. Die is killing the script with It sounds like the open() at line 100 is simply not being reached. Is the print statement on line 102 ever outputting anything? Try putting a print statement after line 56 to see if you ever make it that far. The script looks pretty error-prone, so you may just want to break out the debugger.
|
# ¿ Apr 9, 2008 00:55 |
|
SpeedFrog posted:Don't really like constant.pm... the lack of (easy) interpolation and all the edge-cases requiring &s or ()s make the cure worse than the disease. Because that Readonly module is going to be really slow. The whole point of constant.pm is that the compiler will inline the data (because it is a sub) and creates no symbol table entry. It's more like a pre-processor constant the way C constants are. The syntax is retarded, I agree, but it's a very important module.
|
# ¿ Apr 29, 2008 15:40 |
|
ashgromnies posted:
I'm in a rush and not familiar with SOAP or this module, so sorry for posting, but two things to check.... 1) $elem may not be getting what you think (list of individual nodes), and you're dumping that here via list context. How about using the SOAP::Data->name('thing')->value(); form instead? 2) I think you are wanting to supply SOAP::Data->name("history") with a list of "pointHistory" nodes, but it looks like you are supplying just one with @credit_arr as its value/children. Either way, bust out Data::Dumper, check out what is going into $elem & @credit_arr and have a look at the SOAP::Lite source and make sure those methods expect/return what you expect. I only glanced, but the docs seem to suck.
|
# ¿ May 23, 2008 04:31 |
|
LightI3ulb posted:Does anyone know of any modules that would allow me to receive mail and work with the attachments? The ones I've found on google are typically just for sending. Are you talking about a module to interface POP3 or IMAP protocol to access mail attachments? Sending mail is SMTP, storage and access of mail are other animals in a different part of the zoo.
|
# ¿ May 23, 2008 20:09 |
|
I had no idea Vim had built-in perl support (and ruby/python). I have absolutely no idea how I've not heard of it before. Run a perl regex on each of lines 10-20. Since $_ is set to value of the line being examined, both lines below are the same: code:
Vim exposes some of its innards to the perl interpreter. This will print the perl version as a message on the Vim console: code:
code:
|
# ¿ Jul 8, 2008 21:32 |
|
MrHyde posted:What's the difference between the all-caps filehandles and just using a scalar variable? Perl uses something called a "typeglob" (a "GV" internally) to keep track of things defined in a package for a given name. The "things" can be scalars, arrays, hashes, filehandles, formats, subs, etc. Think of a typeglob as "all things in this package with this name". The typeglob is what allows you to have both $foo and @foo and %foo and a filehandle named foo. Perl uses context to determine what type of thing you refer to. code:
Now let's get really weird. In the same script, add: code:
Want more? You can use * to refer directly to a typeglob. code:
Anyway, the reason a bareword filehandle is frowned upon is that you are creating a thing of a certain type by implied context in package scope. Using a scalar reference is more explicit and has lexical scope.
|
# ¿ Jul 12, 2008 19:44 |
|
open implies the '<' mode if none is specified. It won't ever clobber existing files unless specifically instructed to do so.
|
# ¿ Jul 12, 2008 19:52 |
|
Triple Tech posted:Goodness, I didn't know this was crit Perl time... Anyway, scalars are far, far superior to filehandles (symbol thingies?) because they will automatically close when the scalar goes out of scope. And, filehandles are global in scope (generally bad) while scalars, defined with my(), are the most limited in scope. Note that open assigns a filehandle reference to a scalar if passed. The scalar is not a filehandle. quote:Small/limited scope is good. (edit: totally wrong, ignore me)
|
# ¿ Jul 12, 2008 19:58 |
|
Sartak posted:That's not true. Sorry about that... I never use my that way so it just looked wrong. code:
|
# ¿ Jul 12, 2008 20:56 |
|
Sartak posted:I've got one more for you! Right, I thought someone above was saying that using the two-arg form with no mode was bad because it could clobber an existing file. Also... does anyone in this thread do much XS?
|
# ¿ Jul 13, 2008 03:55 |
|
quote:I've done some XS I hooked $SIG{__WARN__} to call pstack and was able to answer my own question. I wasn't handling an undef SV* properly.
|
# ¿ Jul 13, 2008 20:26 |
|
Is anyone familiar with how fields.pm performs since the 5.009 changes? I don't have a perl > 5.8.8 anywhere to test. These are benchmark results for 5.8.5 for creating vanilla objects and accessing an instance attribute. no_fields: simple bless({}, $class) constructor restricted hash: same, but uses Hash::Util::lock_keys() after bless fields_untyped: constructor has "my $self = shift" fields_typed: constructor has "my MyClass $self = shift" code:
code:
|
# ¿ Jul 17, 2008 05:10 |
|
checkeredshawn posted:I appreciate the advice, Erasmus Darwin, but to clarify, I'm trying to shorten the script. I figured I could find some module that would help me better compare the data, but I've failed to find any such module through cpan. Shorter? This is only three lines and creates a structure with the comparisons you want... code:
|
# ¿ Jul 18, 2008 00:21 |
|
|
# ¿ May 2, 2024 12:06 |
|
TiMBuS posted:wat It is. I had @compare{keys(%different_hash)} there before and changed it. But values would be better because it is faster than a slice.
|
# ¿ Jul 18, 2008 15:34 |