|
my $results = $dbh->selectall_arrayref('select * from players where name = ?', undef, $name); As long as the query isn't too complex and does some simple filling in the blanks kind of stuff, that's the way you would use the database handle. Notice there are convenience methods off of the handle. You shouldn't really have to prepare/execute queries for super simple apps.
|
# ? Mar 27, 2009 17:41 |
|
|
# ? May 21, 2024 14:22 |
|
So basically the whole function could be replaced by justcode:
|
# ? Mar 27, 2009 18:07 |
|
well you still need to connect (and disconnect) to the DB, but yeah.
|
# ? Mar 27, 2009 18:14 |
|
Yeah, I guess. You might have a stray single quote at the end of that function. I suggest looking at the documentation for DBI to see what the various fetch convenience methods are, as well as controlling how you want the data returned back to you (hashes or arrays for each row). Also, that's a pretty nasty looking query. Consider refactoring out the SUM for fun, or just storing it in a phrasebook somewhere. Or abstracting the select statement with a view.
|
# ? Mar 27, 2009 18:16 |
|
Triple Tech posted:Well, he would have to have a shallow execute, like perl -MTeX::Hyphen -e 1. You don't need to execute anything, just using the -M flag will compile the module and will drop an error if it doesn't compile properly or isn't found. It will however sit around indefinitely if it successfully compiles, so yeah.
|
# ? Mar 27, 2009 18:24 |
|
Thanks for the fast replies, you guys are great. Just two more things about DBI, I only have code:
|
# ? Mar 27, 2009 18:32 |
|
Crazy how you'd ask considering the block of code you posted earlier shows that a database handle comes from the connect method off DBI. The driver is implicit to the connection string you provide.
|
# ? Mar 27, 2009 19:05 |
|
Triple Tech posted:Crazy how you'd ask considering the block of code you posted earlier shows that a database handle comes from the connect method off DBI. The driver is implicit to the connection string you provide. I'm very new to both Perl and DBI, do you mean the DBI connect method can take more parameters to detail the location of the SQL server? When I'm using MS' ODBC driver in C# the connection string looks more like "driver="MySQL ODBC driver";port=3306;server=localhost; database=db;user=user;password=password". In the code I posted those first three are missing, can I insert them elsewhere OR do I need to do something involving DBD::MYSQL somewhere?
|
# ? Mar 27, 2009 20:16 |
|
It's in the documentation for DBI, right under the heading connect. It's pretty much in the same.
|
# ? Mar 27, 2009 20:39 |
|
One more question - I've got the GD module installed so I can do some work with image files. It works fine except for jpeg support, which I've been trying to get working all day with no luck, it's driving me crazy. It seems gdlib won't install with jpeg support. I've installed jpeg6b properly, and when I run configure for gdlib it seems to recognize this: quote:** Configuration summary for gd 2.0.34: Before I installed jpeg6b it had said no for jpeg support, so it seems to have found the new libraries. Then I do make and make install, which seem to work fine, but gdlib-config still tells me it has no jpeg support, and I get no jpeg support in perl after reinstalling GD. Any ideas?
|
# ? Mar 28, 2009 03:41 |
|
Wow, I am having a bitch of a time returning the absolute path of files in my web-root. Let's say I want to upload/read a file on my server at /home/clinton/webroot/proj/cont. This would correspond to the web-directory http://localhost/proj/cont. Everything I try, Perl just keeps returning the scripts current directory as '.' which is completely useless when it's not relative to anything. Trying to turn this into an absolute path just returns /, my root directory, instead of /home/clinton/webroot/proj. When I try to upload files to /home/clinton/webroot/proj/cont/$filename it works great, but uploading files to cont/$filename vanishes the file into oblivion.* I have tried everything in File::Spec and CWD, and it all doesn't work. I've googled around for absolute file paths perl and those seem to be the only recommendations I can find. How do I make this code portable, so that I don't need to hardcode the directory Apache is hosting the files from? I'm pulling my hair out. *edit: Actually, I just created a folder called /cont (in the root directory of my whole OS), and files uploads there when I don't specify an absolute path. And here is how I've set up apache, from my httpd.conf: code:
Gary Mitchell fucked around with this message at 00:47 on Mar 29, 2009 |
# ? Mar 29, 2009 00:42 |
|
Gary Mitchell posted:I have tried everything in File::Spec and CWD, and it all doesn't work. I've googled around for absolute file paths perl and those seem to be the only recommendations I can find. That's really strange. What does this give you? code:
|
# ? Mar 29, 2009 00:52 |
|
From the console? It just returns the directory I run it from:code:
|
# ? Mar 29, 2009 01:03 |
|
What about print Cwd::abs_path('.') from your script?
|
# ? Mar 29, 2009 01:18 |
|
Sartak posted:What about print Cwd::abs_path('.') from your script? This is honestly a fresh, stock install of Perl and Apache on Ubuntu 8.10. And I can't find anyone else with my problem anywhere, although it's pretty hard to specify "." or "/" as a useful search term on Google. I might end up just assuming that relative paths isn't broken on other machines, get it working, change all the paths, and submit it untested. But that would suck balls. Gary Mitchell fucked around with this message at 01:27 on Mar 29, 2009 |
# ? Mar 29, 2009 01:25 |
|
Gary Mitchell posted:From the console? It just returns the directory I run it from: What if you do this on your server? And like I said, it's probably using chdir. To see if that's the issue, use chdir yourself: code:
|
# ? Mar 29, 2009 02:03 |
|
Oh holy poo poo. I moved onto another problem I was having with my .htaccess files and, after fixing that, this problem solved itself! And for clarification the console is on my server, I'm serving the file to myself from localhost. But now it's cleared up! Sartak, thank you so much for your time! edit: Uh, actually, no it didn't. Hold on, I'm figuring out if it was the CHDIR that temporarily fixed my prob edit2: Screw it. I've uploaded the files to my website, and have opened them through FTP in my text editor (yey KDE KIOSlaves!). Identical workflow, but now everything works the way it should. I'll see if the problem persists after I upgrade to Jaunty in April. I do thank you for your help, though! Gary Mitchell fucked around with this message at 03:05 on Mar 29, 2009 |
# ? Mar 29, 2009 02:15 |
|
I submitted a talk to YAPC::NA in Pittsburgh. It's about extending Moose for applications. Metaprogramming is so good. I won't know until the end of April whether it's accepted, but considering Moose's popularity I'm sure I'll be giving this talk. Is anyone else planning to attend or better yet give a talk?
|
# ? Mar 31, 2009 05:53 |
|
It looks like my vacation plans for this year fell through, so the week of YAPC is actually free. I wonder if I should go now...
|
# ? Mar 31, 2009 12:59 |
|
Are any of you guys Catalyst whores? I think my company is set on using it but god it feels so ghetto... And I have a question about implementing multiple views.
|
# ? Mar 31, 2009 19:53 |
|
Don't ask to ask man. Just ask. If someone knows it they'll answer.
|
# ? Mar 31, 2009 19:55 |
|
That was bad form, I agree. In Catalyst, how exactly do multiple Views work? My impression was that the controller should be agnostic to what view the application is currently running under, and that the templates are dependencies of the View. Such that if I change the view to something else with one line of code, I can change all the templating behavior implicitly. Is this not the case with Catalyst? I find the documentation to be thin and full of errors; it's quit irksome. And sort of embarassing since I blindly extolled its virtues without looking under the hood.
|
# ? Mar 31, 2009 22:45 |
|
As of 5.7007, calling $c->view() will honour the default_view setting in your config before checking $c->stash->{current_view} and then walking through the list of loaded View classes: http://search.cpan.org/~mramberg/Catalyst-Runtime-5.71001/lib/Catalyst.pm#$c-%3Eview($name) So yes, that's the case. You may set up content-type/accept sniffing in your end method and jump out to the appropriate view, e.g. TT, JSON or Email, for example.
|
# ? Apr 1, 2009 01:23 |
|
Also, if you're using Catalyst::Action::RenderView, which gets enabled by default with the end controller in Root, it will only try to call a view's process() method if no HTTP body has been defined, so you can jump out to an arbitrary view from a given controller method, if you have to.
|
# ? Apr 1, 2009 01:25 |
|
Edit: Nevermind, think I've got there with Win32::Services. Flamadiddle fucked around with this message at 12:26 on Apr 6, 2009 |
# ? Apr 6, 2009 11:49 |
|
I'm plotting some graphs for a project that I have to present tomorrow, and I'm having trouble with line graphs where the intervals of data aren't evenly spaced; it plots the range [0,0.5] in the same amount of space as [0.5,0.6]. Is there a way to make the plotting spaced out as it should be? I'm sure it's obvious but I can't see it in the man page. Got it, turns out that x_tick_number has to be defined. Dijkstracula fucked around with this message at 21:58 on Apr 6, 2009 |
# ? Apr 6, 2009 21:32 |
|
Riddle me this: why does php outperform perl in this nsieve test twelve-fold: http://shootout.alioth.debian.org/gp4/benchmark.php?test=nsieve&lang=perl&id=2 http://shootout.alioth.debian.org/gp4/benchmark.php?test=nsieve&lang=php&box=1 I converted the perl version from lists to strings like the php version, and it made it two seconds slower, so that can't be it.
|
# ? Apr 7, 2009 22:55 |
|
That implementation is gay. Looking at the C implementation, I'm going to assume these aren't out to prove how a certain data structure performs (array access), but to just solve the problem. You'd use a bit vector with vec(). (See Computing primes) Edit: Ugh, who wrote that Perl submission. It's so different from the PHP one. Triple Tech fucked around with this message at 23:06 on Apr 7, 2009 |
# ? Apr 7, 2009 23:03 |
|
Triple Tech posted:That implementation is gay. Looking at the C implementation, I'm going to assume these aren't out to prove how a certain data structure performs (array access), but to just solve the problem. You'd use a bit vector with vec(). (See Computing primes) There's a seperate version with bitsets for each language.
|
# ? Apr 7, 2009 23:13 |
|
Catalyst 5.8000_07 hit CPAN today. Apparently a production-ready release will be made this week if no more blockers show up during testing. Time to start porting our existing apps over to Catamoose!
|
# ? Apr 14, 2009 10:54 |
|
atomicstack posted:Catalyst 5.8000_07 hit CPAN today. Apparently a production-ready release will be made this week if no more blockers show up during testing. Time to start porting our existing apps over to Catamoose! I think this will be the impetus to get me to finally start using Moose. Cool!
|
# ? Apr 14, 2009 14:50 |
|
I've been using Catalyst lately for an internal project (inventory tracking for my group of system administrators), and while I love it, I seem to be google-blind on one thing. Query caching. Example: You're looking at an audit page, where you see the last 30 changes. Each row of the audit log is generating another hit against the 'users' table to pull out username, display name, email address, etc. Ideally, I'd like something that, either in Catalyst or TT2, I can go 'ok, for this page, this render, cache everything' Would I have to roll my own? (doable), or is there something I'm just too blind to see?
|
# ? Apr 17, 2009 04:05 |
|
Caching aside, have you set up your indexing properly? I don't know that much about DBs and what have you but the least you could do is make naive calls to your database as smooth as possible and then investigate caching afterwards.
|
# ? Apr 17, 2009 04:15 |
|
dagard posted:Ideally, I'd like something that, either in Catalyst or TT2, I can go 'ok, for this page, this render, cache everything'
|
# ? Apr 17, 2009 04:24 |
|
dagard posted:I've been using Catalyst lately for an internal project (inventory tracking for my group of system administrators), and while I love it, I seem to be google-blind on one thing. Query caching. I haven't done much with it, but you could use Catalyst::Plugin::Cache. An example could look something like this (taken straight from the docs): code:
|
# ? Apr 17, 2009 04:29 |
|
I'm writing an IRC bot that manages a card game. I was annoyed with how much work it would be to have the bot reset its state once the game was over, fresh for a new game. I put off this semi-necessary feature for a while, until tonight. Since I wrote the IRC bot with Moose, so resetting state turned out to be as easy as:code:
Attributes that should persist across games (such as the connection to the IRC server) do not get reinitialized because they declare no clearer. Filburt Shellbach fucked around with this message at 08:14 on Apr 18, 2009 |
# ? Apr 18, 2009 08:12 |
|
KiokuDB is pretty rad. Set up a test cluster of memcachedb machines and am writing a backend using libmemcached to see how much better/worse it is than CouchDB, which seemed to support about 1000 transactions/sec with replication enabled. Using MooseX::Declare makes it really weird to write Perl-but-not-Perl.
|
# ? Apr 19, 2009 10:29 |
|
I have been super bored this weekend and started working on an Gtk+ irc client in perl. My main goal is to be compatible with Colloquy styles, which consist of html, css, and an xslt file. I am using WebKit for the HTML view, which is also what Colloquy uses. It is pretty neat, because there is a great Colloquy style that can do inline images, as well as inline audio (via the <audio> element.) Here is a large screenshot I've got everything working, but now I am going back and re-writing it with Moose. It is a bit of a pain, but I can already see it becoming more readable and easier to update.
|
# ? Apr 19, 2009 19:11 |
|
What's the most efficient way to do multiple substitutions at once? There's lots of information online about doing multiple matches at once, but I can't find anything about substitutions. For example, is it possible to do something like this: code:
|
# ? Apr 20, 2009 02:28 |
|
|
# ? May 21, 2024 14:22 |
|
mit_senf posted:What's the most efficient way... Does it really matter? Try benchmarking a hash lookup with the /e switch. s/foo|bar/lookup($1)/ge (untested)
|
# ? Apr 20, 2009 02:55 |