|
Nevermind what I said. Low reading comprehension.
|
# ? Feb 12, 2008 21:02 |
|
|
# ? May 21, 2024 17:50 |
|
Yes! Awesome, I've got a beginner's perl book which devotes one paragraph to getopt::long and doesn't mention the configure option. So basically anything extra will cause ARGV to have an option set, yes yes yes, thank you v. much.
|
# ? Feb 12, 2008 21:31 |
|
Kidane posted:Yes! Awesome, I've got a beginner's perl book which devotes one paragraph to getopt::long and doesn't mention the configure option. So basically anything extra will cause ARGV to have an option set, yes yes yes, thank you v. much. Try running "perldoc Getopt::Long" in your shell, and you should get way more than you ever wanted to know about Getopt::Long. It'll work for any installed module, and you can also look up built-in functions with "perldoc -f functioname". "perldoc perldoc" gives you documentation on perldoc itself.
|
# ? Feb 13, 2008 17:02 |
|
Okay, I've been trying to get the code Triple Tech and Speed Frog suggested to work but I just cannot get my head around it. I guess the main problem is I'm not entirely sure what I'm doing with the code that works. This is what I understand of the code I have: code:
code:
code:
code:
Then the code loops again back to the start of the 'while' function, starting on the next row in the samplefile. Okay, so the code you guys suggested is kind of swamping me. This is me trying to understand what is going on. code:
code:
code:
code:
So I tried the following code: code:
ARRAY(0x8f602c) ARRAY(0x8f6050) ARRAY(0x8f6080) ARRAY(0x8f60b0) ARRAY(0x8f60e0) ARRAY(0x8f6110) ARRAY(0x8f6140) Etc. etc. etc. I'm at a loss
|
# ? Feb 21, 2008 14:37 |
|
ProvostZak posted:
By the way, this is pretty terrible. One, you should always be using warnings and strict. Two, doing file operations PER element, that's crazy. You should just buffer everything into a data structure, and then at the end of your script, dump/render it to a file. ProvostZak posted:
Close. Arrays in scalar context evaluate is the length of the array. So when we say double is less than array, we mean are there at least two elements in the array. Or three. Actually, the base for double and triple are moving targets, but since the words array isn't being modified, it's effectively the same thing... "Are there two or three elements still remaining from our current point of interest?" ProvostZak posted:
Eh this is pretty rough to understand. It would be better to say $i++ on one line, and last if $i > @words on another. The plus one-ness happens first as a side effect. Then, you read the expression. "Stop the loop if we've exceeded the length of the array." ProvostZak posted:
I guess you didn't get to references yet. We were giving you each set of doubles as one unit. You know how arrays store stuff, like a group of many individual things? And when we talk about a set of doubles, you can think about it as two individual numbers, or one package of two numbers. What we did was give you the doubles as single packages each. So... You have to unpackage them, technically, dereference them. code:
|
# ? Feb 21, 2008 15:41 |
|
I've been using Catalyst for an app at work recently and I really like the regular expression matching for Controller routines...code:
|
# ? Feb 21, 2008 17:03 |
|
Here's a good example of why I shouldn't be allowed near Perl's inner workings: autobox::Closure::Attributes Other than being a neat trick, it is a concise example of how to use really powerful tools you don't see every day:
|
# ? Feb 21, 2008 20:13 |
|
Sartak posted:Here's a good example of why I shouldn't be allowed near Perl's inner workings: autobox::Closure::Attributes 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.
|
# ? Feb 21, 2008 22:43 |
|
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 |
|
genericadmin 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. code:
code:
|
# ? Feb 21, 2008 23:11 |
|
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 |
|
genericadmin posted:Interesting, I'd not realized a closure differed from an anonymous sub based on it encapsulating data from a higher scope. Yep, that's what makes them so powerful. Take this example. Each instance of the function returned by create_counter gets its own $count. code:
How about some imaginary function (delete_with_callback) that invokes your callback for a list of files, and you return true for files you want to delete, and false for files you want to keep. However, the function returns the count of files that were deleted, but not the filenames. And you want to tell the user what you deleted. Here's how I'd do it: code:
genericadmin posted: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? Oh, I totally wouldn't use this for regular objects. It's more a proof of concept than anything. However, on the very very small chance you need to get/set a closure's variables directly, this may be less painful than using PadWalker directly. For debugging, perhaps.
|
# ? Feb 22, 2008 00:57 |
|
Anyone familiar with DBIx::Class here? I'm still trying to figure out how it all works, but I'm having an issue using update_or_create. Every time I run it, I get an invalid syntax error from MySQL. code:
code:
Any ideas? Puck42 fucked around with this message at 21:45 on Feb 28, 2008 |
# ? Feb 28, 2008 21:42 |
|
Puck42 posted:
The word 'index' is a MySQL reserved word, so: code:
|
# ? Feb 29, 2008 03:22 |
|
yeah... that was the problem. I feel like an idiot now. No idea how I forgot all about that.
|
# ? Feb 29, 2008 03:27 |
|
edit: nm
|
# ? Feb 29, 2008 14:44 |
|
I need some help with Catalyst exception handling. I have some error checking in my model that causes a die() to raise. I need to catch that somewhere else and depending on the view they have selected, give a different error page. That is, I have two views - JSON view for AJAX stuff and TT2 view for regular HTML. If it's HTML, sure, show the default error page for now, if view == JSON then put an error message in the JSON output so it doesn't break their browser. Here's my Root controller's end method: code:
Log output: code:
Ideas?
|
# ? Feb 29, 2008 21:07 |
|
Essentially, I'm trying to match one array against another. Here is what I've got:code:
Intermediate Perl states: "While the grep is running, it shadows any existing value in $_, which is to say that grep borrows the use of this variable but puts the original value back when it's done." My interpretation is that I needn't worry about copying $_ into an intermediate variable, but I will probably try that just in case. Kidane fucked around with this message at 12:10 on Mar 7, 2008 |
# ? Mar 7, 2008 12:06 |
|
Kidane posted:Essentially, I'm trying to match one array against another. Here is what I've got: I found your description of the problem a bit confusing to be honest. So, assuming I haven't entirely misunderstood you, might the following do what you want? code:
magimix fucked around with this message at 12:27 on Mar 7, 2008 |
# ? Mar 7, 2008 12:21 |
|
magimix posted:I found your description of the problem a bit confusing to be honest. So, assuming I haven't entirely misunderstood you, might the following do what you want? I considered using a hash but the sub started swelling up and I'd like to keep this portion of my code to as few lines as possible.
|
# ? Mar 7, 2008 12:23 |
|
Kidane posted:Yes, that's exactly what I'm trying to do. I'd say worry about the functional aspect of your code for now, rather than its line-count. I created a hash of php_installed_modules so that I could iterate through php_available_modules once only, and do a single hash-lookup for each element therein. Your original code has you iterating though php_installed_modules twice for every element in php_available_modules.
|
# ? Mar 7, 2008 12:26 |
|
magimix posted:I'd say worry about the functional aspect of your code for now, rather than its line-count. I created a hash of php_installed_modules so that I could iterate through php_available_modules once only, and do a single hash-lookup for each element therein. code:
Thanks a lot for your quick response!
|
# ? Mar 7, 2008 12:41 |
|
Kidane posted:You're right, of course. I've never used map before so I was shying away from it. My original code (before I tried using grep) looked like this I'm still got a nagging doubt that I'm missing something. Anyway, would the following also do what you want? code:
|
# ? Mar 7, 2008 12:44 |
|
magimix posted:I'm still got a nagging doubt that I'm missing something. Anyway, would the following also do what you want? PHP modules already installed (from php -m): code:
code:
Kidane fucked around with this message at 12:55 on Mar 7, 2008 |
# ? Mar 7, 2008 12:52 |
|
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 |
|
genericadmin posted: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()). I ended up throwing an eval{ }; around the call and got it working with my custom error handling. Okay, another Catalyst question... I have a method triggered that runs in the background(I enabled multi-threading on my Catalyst app) that takes a little bit of time to perform and has multiple actions it performs. I would like to inform the user of the current status of this method. Here's the code that I have... code:
code:
code:
So then I have this method to check the status... code:
What would you do to get around this? I could write the status to a file locally and read from that but that seems to go against the Catalyst-way.
|
# ? Mar 7, 2008 16:49 |
|
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 |
|
genericadmin posted: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. We can't have a JobQueue because multiple people are allowed to trigger this action to happen at once and that is perfectly fine and expected. With a JobQueue, it is feasible that things might get out of order and new data could be stamped on with old data - the way it's set up now, it will throw an error if multiple people trigger actions that step on eachother, which is intended. So I need to find a way of doing this without a slow Queue. It needs to allow multiple requests from different people at once...
|
# ? Mar 7, 2008 22:02 |
|
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
|
# ? Mar 10, 2008 15:22 |
|
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 |
|
genericadmin posted:Sessions are implemented as plugins (last I had seen anyway), so you are bound by the plugin implementation and the various Catalyst phases. For what it's worth, using Cache::FastMmap and $c->cache->get and set worked.
|
# ? Mar 11, 2008 00:58 |
|
Stupid question... Is there a way to print to stdout without updating the cursor? For example if I wanted to display a percentage done indicator, or even just a spinning | to show that the program is thinking, is there a way to do this? My intuition tells me that it's not but I figured I might as well ask (Google was no help).
|
# ? Mar 12, 2008 11:21 |
|
Kidane posted:Stupid question... This looks like what you want: http://outflux.net/software/shorts/perl/Idle
|
# ? Mar 12, 2008 12:22 |
|
dagard posted:This looks like what you want: Thanks!
|
# ? Mar 12, 2008 12:52 |
dagard posted:This looks like what you want:
|
|
# ? Mar 12, 2008 15:06 |
|
syphon^2 posted:Hey that's really cool. How would one handle multiple-line "interactive" scripts then? The carriage return let's you re-draw the current line, but what if you need to re-draw the PREVIOUS line(s)? I think that's getting to the point where you need to start worrying about the terminal-specific means of moving the cursor around. (Or you can cheat and just hardcode the appropriate ANSI escape sequences, but that's bad.) The low-level interface to the underlying terminal control sequences is handled by Term::Cap, which seems to be bundled with Perl: http://www.perl.com/doc/manual/html/lib/Term/Cap.html But you don't want to use that unless you're feeling adventurous and masochistic. It's a lot easier to use a nice wrapper like Term::Screen (which you'll have to grab off CPAN): http://search.cpan.org/~jstowe/Term-Screen-1.03/Screen.pm Term::Screen, Term::ReadKey, and Term::ANSIColor was enough for me to do an asteroid clone using ASCII characters. I can't remember why I skipped using Term::Screen's key handling code and instead went with Term::ReadKey.
|
# ? Mar 12, 2008 16:19 |
|
See also Curses, if (any of) you are interested in a "full-screen" terminal application like vim or NetHack.
|
# ? Mar 13, 2008 01:03 |
|
I'm trying to write a one liner to validate that all the *.yml files it finds can be properly parsed... Here's what I came up with: code:
It only gets two arguments, which I can check with: code:
code:
edit: closer code:
code:
perl one liners are fun but I write them like a regular script ashgromnies fucked around with this message at 15:02 on Mar 14, 2008 |
# ? Mar 14, 2008 14:53 |
|
How about this?code:
|
# ? Mar 14, 2008 17:01 |
|
|
# ? May 21, 2024 17:50 |
|
genericadmin posted:How about this? Awesome, thanks! How is it you know everything? I went with this to exclude files that start with a "."... there were these "._.*.yml" files that seemed to be Mac OS X binary temp files that contained no valid YAML serialization: code:
ashgromnies fucked around with this message at 20:19 on Mar 14, 2008 |
# ? Mar 14, 2008 18:01 |