|
German Joey posted:the more complicated a parsing method can handle, the slower it'll be. quote:the main question i have for your coworker then is: why do you need something more powerful than a regex for parsing a loving log file? and why do you need something more efficient? how big is this file, in the gigabytes?
|
# ? Jun 14, 2008 17:47 |
|
|
# ? May 21, 2024 18:23 |
|
Regex question: How the hell do I remove weird ASCII characters? Like upside-down question marks. I've tried a copy and paste, and that doesn't work. I've tried "\xBF", which is the hex code, and that doesn't work either. It just won't match the drat things.
|
# ? Jun 18, 2008 14:29 |
|
Have you tried making an inverted character class? "Substitute all NOT A-Z..."
|
# ? Jun 18, 2008 14:39 |
|
Triple Tech posted:Have you tried making an inverted character class? "Substitute all NOT A-Z..." I had to do this like a year ago. It was ALOT easier to do exactly this; only allow what you need.
|
# ? Jun 18, 2008 23:29 |
|
Strict 9 posted:Regex question: How the hell do I remove weird ASCII characters? Like upside-down question marks. I've tried a copy and paste, and that doesn't work. I've tried "\xBF", which is the hex code, and that doesn't work either. It just won't match the drat things. Upside down question marks are not ASCII. Why do you need to remove them? Usually when I've seen code that does this kind of thing, it's doing something wrong.
|
# ? Jun 19, 2008 00:20 |
|
The "upside down question mark" is probably your editor/terminal/whatever program's way of indicating that there is an unsupported character of some sort there (wide unicode character in a terminal expecting 7bit ASCII or latin-1). You should examine the data in hex and see what it really is, it may be iso-8859 of some form, or unicode.
|
# ? Jun 19, 2008 01:31 |
|
How can I NOT store the path for the files I put in a zip archive? In other words, when you open the zip file, each file has a path of abc/def (see $myDir below). I don't want a user extracting the zip and having it generate the directories abc/def. I just want it to extract to a directory equaling the filename of the zip. For what it's worth, here's the code- code:
|
# ? Jun 19, 2008 02:35 |
|
yaoi prophet posted:The "upside down question mark" is probably your editor/terminal/whatever program's way of indicating that there is an unsupported character of some sort there (wide unicode character in a terminal expecting 7bit ASCII or latin-1). You should examine the data in hex and see what it really is, it may be iso-8859 of some form, or unicode. Unicode is not a character encoding.
|
# ? Jun 19, 2008 10:36 |
|
Yeah, I meant UTF-8.
|
# ? Jun 19, 2008 12:13 |
|
mister_gosh posted:How can I NOT store the path for the files I put in a zip archive? Your code doesn't run for me, but there is a second parameter to addFiles which can specify the name of the zip in the file. I.e do $zip->addFile( $file,$file_name_without_directories ) http://search.cpan.org/dist/Archive-Zip/lib/Archive/Zip.pm#Zip_Archive_Member_Operations
|
# ? Jun 19, 2008 13:55 |
|
mister_gosh posted:How can I NOT store the path for the files I put in a zip archive? From the Archive::Zip documentation, it appears that addFile will also accept a new name for the file once it's added. Keep in mind "filename" for zips includes their path, so you should be able to do: code:
code:
|
# ? Jun 19, 2008 13:56 |
|
fansipans posted:Which is funny, because I already had those two URLs open in my browser Haha, thanks guys! I saw the new name parameter but dismissed it immediately because I wanted the name to be the same in the zip file (duh!)...I hadn't considered that the filename I was passing in was the full name, it makes sense now.
|
# ? Jun 19, 2008 14:28 |
|
I'm really confused as to why my script keeps giving me the errors DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at ./tmcseed.pl line 24. DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at ./tmcseed.pl line 38. on my code code:
|
# ? Jun 19, 2008 15:00 |
|
Your code makes my mind hurt. Have you just tried writing my $sth = $dbh->do($sql) or die; instead? I'm not intimate with DBI but that's how I've always done it and I haven't had any problems.
|
# ? Jun 19, 2008 15:17 |
|
What's headache-inducing?
|
# ? Jun 19, 2008 15:33 |
|
There's a lot of unnecessary punctuation, not enough whitespace, and the SQL is hard to read.
|
# ? Jun 19, 2008 15:42 |
|
I might be flying off in totally the wrong direction, but can MySQL actually handle multiple active statements on a single database handle? I've always found I couldn't execute a second statement on a DB handle without first fetching or discarding the result-set of the previously executed statement.
|
# ? Jun 19, 2008 15:51 |
|
magimix posted:I might be flying off in totally the wrong direction, but can MySQL actually handle multiple active statements on a single database handle? Yeah, I've done it a ton of times.
|
# ? Jun 19, 2008 16:04 |
|
LightI3ulb posted:I'm really confused as to why my script keeps giving me the errors Also, use placeholders: my $rows = $dbh->prepare("INSERT INTO foo (bar) VALUES (?)")->execute("this replaces the question mark");
|
# ? Jun 19, 2008 16:16 |
|
See, that's the strangest part. I checked the return values from the executes, and it gave me the number of rows it returned just like it was actually working, but still giving me execute errors.
|
# ? Jun 19, 2008 16:30 |
Can anyone share a really simple method of timing my code? I want to see how long certain code takes (in milliseconds), but can't find a clear, easy way to do this. I've tinkered around with time(), localtime(), Time::HiRes, and Benchmark. I'm basically looking for something that'll do this... code:
|
|
# ? Jun 19, 2008 18:17 |
|
I've honestly almost always just used Time::HiRes for things like that. Something like:code:
|
# ? Jun 19, 2008 18:37 |
|
Yes, Time::HiRes is a great way to time certain parts of code. I've been throwing results in a hash so I can time different items like:code:
|
# ? Jun 19, 2008 19:07 |
|
magimix posted:I might be flying off in totally the wrong direction, but can MySQL actually handle multiple active statements on a single database handle? Yes and no. MySQL itself doesn't seem to support this, but library trickery makes it seem like it works. By default, the entire result set is streamed to the DBI library at execute time. This is "mysql_store_result" mode. Because the whole result set is cached at the client before any fetches occur, MySQL never sees more than one query going on at a time. This isn't a good solution when you want to iterate very large data sets that don't fit in RAM, as I had to do recently. For that, you need to use "mysql_use_result", which transfers records as you fetch them. The problem with this is that you can't do other queries inside of that loop, since the outer query is still in progress. I couldn't find an elegant solution to this, so I just read my outer query out to disk first, then iterated from disk for my small inner queries, which worked fine in mysql_store_result mode. Basically, if you can't do this for lack of memory: code:
code:
code:
|
# ? Jun 19, 2008 19:54 |
|
Is the result set in the stored in the dbh or the sth? If it's dbh, then I understand why I had that problem. Regardless, I realised I was able to do that entire comparison with mysql joins. Thanks for the help.
|
# ? Jun 19, 2008 20:17 |
dagard posted:I've honestly almost always just used Time::HiRes for things like that. From http://search.cpan.org/~jhi/Time-HiRes-1.9715/HiRes.pm quote:tv_interval
|
|
# ? Jun 19, 2008 21:46 |
|
syphon^2 posted:I've got a stupid question... That just means it's .315718 seconds. The stock perl sleep and time functions are only accurate to the nearest second, so they're integers, whereas the functions in Time::HiRes use floats, since they can sleep < 1 second (or measure more accurately than 1 second).
|
# ? Jun 19, 2008 22:08 |
I've got another simple question (boy, this really shows how incompetent I am at reading documentation!) I'm using Win32::TieRegistry to gather information from the registry of a series of remote servers. My script has 6 methods, each which need to connect to the registry and grab some data. After implementing Time::HiRes, I can see that this is causing quite a delay, as each of these methods grabs several keys, and the methods are called multiple times for various servers. Since all the keys I'm interested are stored under HKLM/Software/CompanyName, I'd like to connect once and get a dump of all sub keys just once, and then let Perl iterate through the data structure rather than connect multiple times to get the data it needs. Any ideas? It seems like the whole module is built around connecting to the registry each time for individual keys.
|
|
# ? Jun 20, 2008 15:23 |
|
What's the best way to interface with a C++ library from Perl? And once I'm there, what's the best way to return a C++ map as a hash? I've been reading up on swig and while it seems pretty easy to call functions, I'm having a difficult time understanding how to return complex, dynamic structures.
|
# ? Jun 25, 2008 21:00 |
|
Cheesus posted:What's the best way to interface with a C++ library from Perl? The most efficient way would be to use XS. It not not that easy to use though. A lot of Perl modules use it to interface with C++.
|
# ? Jun 25, 2008 21:07 |
|
Cheesus posted:What's the best way to interface with a C++ library from Perl? depends what you're doing. Win32::Api, Inline::C (and Inline::CPP), and XS all offer different ways to interface with C++ with varying degrees of ease. if you don't want to do any post-processing, XS is probably your best bet of returning your data back to perl DIRECTLY as a hash, but if i were you i'd take a look at Win32::Api and Inline first. you can also use XS with Inline if you like what you see.
|
# ? Jun 26, 2008 10:15 |
|
So I want to call method from a super class that uses data defined in each sub class. Sort like...code:
code:
|
# ? Jun 26, 2008 14:27 |
|
Triple Tech posted:So I want to call method from a super class that uses data defined in each sub class. Sort like... What type is your object? blessed hashref? inside-out object?
|
# ? Jun 26, 2008 16:21 |
|
Reg'lur old blessed hash.
|
# ? Jun 26, 2008 16:35 |
|
It's quite common to use regular methods for this. I use this pattern all the time. For example:code:
|
# ? Jun 26, 2008 19:41 |
Does anyone know of a way to take a dump (heh heh) of a portion of the Win32 registry, and store it in a hash to be parsed through later? A script I'm working on gathers data from a bunch of remote servers, some of them across the world. The data I need all resides within a key in HKLM/Software/KEYNAME, and isn't terribly large. I'd like gather all these keys in one go, and use Perl to iterate through them. I'm currently using Win32::TieRegistry to do this. code:
As I mentioned, some of the servers are (physically) very far away, so the latency is very high. Win32::TieRegistry seems to re-connect to the server each time it needs to gather a registry value. In some of the extreme cases, it's taking my script anywhere from 2-10 seconds to gather each registry key, for a total of about 30 seconds per server. This is SLOOOOOW. Do you guys know of anything that will connect to the remote server, take a dump of the Key I specify (and all subkeys), then disconnect, maybe giving me a hash of the whole Key? I tried using Win32::TieRegistry, but it only seems to support tied-hashes (meaning, even though I try to store all the data at once, Win32::TieRegistry remotely queries each key as it's needed). Any ideas?
|
|
# ? Jun 30, 2008 19:53 |
|
You should be able to enumerate all of the keys for a given registry entry just like a hash, something like:code:
code:
|
# ? Jun 30, 2008 21:53 |
I'll try that tomorrow... but like I said, I suspect Win32::TieRegistry only works with tied-hashes. Thus, when it goes through the loop, it makes and breaks the connection for every iteration. That's what happened when I tried it earlier (although I did it slightly differently). EDIT: It's as I suspected. Using either snippet of code from above, creating the hash is reasonably quick (around the order of 600-800ms on my test scenario). Executing 'print Dumper(%copy);', however, took approximately 51938ms. EDIT2: Well, I'm starting to think the bottleneck isn't Win32::TieRegistry, but really just the act of querying a remote registry. On a whim, I changed to calling reg.exe with a backtick (reg.exe is WinXP's native command line registry tool) code:
syphon^2 fucked around with this message at 23:27 on Jun 30, 2008 |
|
# ? Jun 30, 2008 22:06 |
|
Rather than relying on the registry query code to handle communicating with each remote server, what about installing a local script on each one that bundles up all the relevant registry keys and spits it out as a single blob of data to your main script?
|
# ? Jul 1, 2008 13:20 |
|
|
# ? May 21, 2024 18:23 |
Erasmus Darwin posted:Rather than relying on the registry query code to handle communicating with each remote server, what about installing a local script on each one that bundles up all the relevant registry keys and spits it out as a single blob of data to your main script?
|
|
# ? Jul 1, 2008 13:57 |