|
There are a lot of ways, this is how I usually do it:code:
SynVisions fucked around with this message at 01:46 on Dec 8, 2010 |
# ? Dec 8, 2010 01:40 |
|
|
# ? May 21, 2024 17:03 |
|
That returned "Not a HASH reference at servers.pl line 76." (the 2nd line in your code snippet). I thought I had a good handle on referencing/dereferencing various data types, but this problem escapes me.
syphon fucked around with this message at 01:57 on Dec 8, 2010 |
# ? Dec 8, 2010 01:49 |
|
Did you catch my edit? I assumed from you referencing Dumper(@Processors) in your original post that is what you were working with, but later on you're using @{$Processors} which is dereferencing an array. So I changed code:
code:
|
# ? Dec 8, 2010 01:51 |
|
The edit fixed it. Now that I have working code... I'll have to go back and try to comprehend what's going on! Thanks for your help! I think the core of my problem was that I was initializing @Processors (an array) yet the place I got the data from was an array-ref. Is it possible that @Processors somehow came out as an array-ref, even though it looked like an array? Is it even possible to dereference an array-ref into an array if the original array-ref looks like an array to begin with?!?! Crap, now i have a headache. I think I need to go stare out the window for a while! syphon fucked around with this message at 01:59 on Dec 8, 2010 |
# ? Dec 8, 2010 01:57 |
|
syphon posted:The edit fixed it. Now that I have working code... I'll have to go back and try to comprehend what's going on! Thanks for your help! What's happening is what you said initially. @Processors is indeed an array of anonymous hashes containing the info for each within. When you say 'for my $processor (@Processors)' you are looping through thay array assigning a reference to the anonymous hash in each element to $processor. From there you loop through all keys in %{$processor} (the dereferenced hash), and print the value for each key in that hash.
|
# ? Dec 8, 2010 02:02 |
|
I don't know how you're being passed the data, but if you want you can dereference it on the spot so you can use @Processors. e.g. code:
|
# ? Dec 8, 2010 02:06 |
|
syphon posted:I think the core of my problem was that I was initializing @Processors (an array) yet the place I got the data from was an array-ref. Is it possible that @Processors somehow came out as an array-ref, even though it looked like an array? @Processors must always be an array. What you've done is assigned a single element to it that's an array-ref. So it's an array containing an array containing hashes. If you do 'print Dumper(\@Processors);' instead of 'print Dumper(@Processors);', you'll see it for what it is.
|
# ? Dec 8, 2010 03:15 |
|
I've got a quick question. Does anyone know of a module to measure the duration of dates? For my application, I have a string that represents a server's LastBootTime and want a module to convert that into an Uptime. I poked around the DateTime stuff on CPAN but can't find something applicable. For example, I want to convert "11/14/2010 8:01:56 AM" into something like "24 days, 7 hours, 44 minutes" (I don't care too much about the formatting of the output). EDIT: Wow, an answer before I even finished editing my post to increase readability. Thanks! syphon fucked around with this message at 00:46 on Dec 9, 2010 |
# ? Dec 9, 2010 00:43 |
|
syphon posted:I've got a quick question. Does anyone know of a module to measure the duration of dates? For my application, I have a string that represents a server's "LastBootTime" (e.g. "11/14/2010 8:01:56 AM") and want a module to convert that into an Uptime. I poked around the DateTime stuff on CPAN but can't find something applicable. Date::Calc is awesome.
|
# ? Dec 9, 2010 00:45 |
|
toadee posted:Date::Calc is awesome. Ugh, ugh, ugh, no. Use DateTime's duration stuff. Off the cuff, it's something like: code:
|
# ? Dec 9, 2010 04:31 |
|
just use Date::Manip, it parses everything
|
# ? Dec 10, 2010 03:26 |
|
Are there any considerations to make with this script on W7? It works fine on my XP machine but does not work in W7 on a particular machine. The permissions appear to be open for the user (I believe they are an admin, in fact): code:
|
# ? Dec 15, 2010 15:53 |
|
mister_gosh posted:Are there any considerations to make with this script on W7? It works fine on my XP machine but does not work in W7 on a particular machine. The permissions appear to be open for the user (I believe they are an admin, in fact): What distribution of Perl are you using for Windows? ActiveState? Strawberry? Try this: (open's 2 vs 3 arg may be different on Windows) code:
|
# ? Dec 15, 2010 16:37 |
|
The Gate of Nanna posted:What distribution of Perl are you using for Windows? ActiveState? Strawberry? It is activestate 5.10.0 I'll have the user try that. Thanks!
|
# ? Dec 15, 2010 17:09 |
|
mister_gosh posted:Are there any considerations to make with this script on W7? It works fine on my XP machine but does not work in W7 on a particular machine. The permissions appear to be open for the user (I believe they are an admin, in fact): Isn't that just Windows 7 keeping the user from writing to the root of the drive? It's not enough to be "an admin", you have to run the interpreter as "an admin", ie, via right-clicking it and saying "Run as administrator". Alternately, make that open() || die $! so you at least get an error message?
|
# ? Dec 15, 2010 23:11 |
|
typester is alive
|
# ? Dec 15, 2010 23:18 |
|
Otto Skorzeny posted:typester is alive Wait, this typester? http://twitter.com/typester What made you think otherwise?
|
# ? Dec 16, 2010 02:52 |
|
the infobot on irc hadn't seen him in 60 days (I was looking for him to see what was up with a patch to one of his modules that I'd submitted in October). I think I heard a while back that he was on vacation in Spain for a while. He responded to the bug report on RT by accepting the patch yesterday so I guess he's good to go now.
|
# ? Dec 16, 2010 06:57 |
|
How do I split a UNC path in format "\\server\share\blah\..." into two strings: "server" and "\share\blah\..." using a ONE-LINE regular expression? (not "split" or anything like that) This is a specific assignment I am given at work, and I have a terrible time trying to learn it academically from "Programming PERL". I cannot bend the examples in "PERL Cookbook" into what I need, either. Same goes for googling. There's a learning curve, and I am being asked to skip half of it, looks like.
|
# ? Dec 16, 2010 21:10 |
|
my ($server, $rest) = $string =~ /^\\\\([^\\]+)\\(.*)$/; Edit: Though I don't know why you wouldn't want to use a 3 argument split after stripping off the first two characters: my ($server, $rest) = split(/\\/, substr($string, 2), 2); Second edit: You wanted to keep the \ for the rest. Here are your new lines of code: my ($server, $rest) = $string =~ /^\\\\([^\\]+)(\\.*)$/; or my ($server, $rest) = split(/(?=\\)/, substr($string, 2), 2); Anaconda Rifle fucked around with this message at 21:50 on Dec 16, 2010 |
# ? Dec 16, 2010 21:38 |
|
Awesome, thanks! You sir are a gentleman and a scholar.
|
# ? Dec 16, 2010 22:17 |
|
I've got an object - Champion - which contains an attribute - Powers - which is an arrayref. I have a method - addPower - which takes this arrayref and adds an object - Power - to it. I then have a method - listPowers - which takes this arrayref, cycles through it, and uses a method - name - on each entry in there. I'm able to perform the first 2 parts fine. However, the listPowers part fails. Code and error below: code:
code:
I'm using Moose, btw, which is what's generating the name() and powers() methods.
|
# ? Dec 22, 2010 03:35 |
|
Can you paste the full package? Edit: and a dump of $self->powers(). Somewhere along the way you're trying to do a method on a non-object. What you say is correct, but something in your code isn't what you say it is. Mostly because "foreach my $power (@{$powers}) {;" would lead to a compailation error due to the stray semicolon. Roseo fucked around with this message at 04:20 on Dec 22, 2010 |
# ? Dec 22, 2010 04:01 |
|
Roseo posted:Can you paste the full package? Sorry, code was on my laptop. Posted: http://pastebin.com/s8eJbf4i is the module. Calling lines are: code:
The semicolon thing got put in at the end by accident last night, not sure why. It still has the issue without it. Also, just hosed with recovery, it's seriously not that bad anymore, I was tired when I wrote that EVGA Longoria fucked around with this message at 06:15 on Dec 23, 2010 |
# ? Dec 23, 2010 06:13 |
|
code:
code:
Also, that extra semicolon wouldn't cause any problems. It would just be an empty statement.
|
# ? Dec 23, 2010 06:38 |
|
While the bug got pointed out,Casao posted:What exactly qualified a dump of the powers part? It shows up as a hash array when I print it out, and when I run REF on it it returns ARRAY. code:
code:
|
# ? Dec 23, 2010 07:34 |
|
Oh, and think about this. You don't need intermediate scalars.code:
|
# ? Dec 23, 2010 07:37 |
|
Roseo posted:Oh, and think about this. You don't need intermediate scalars. Honestly, I preferred it with intermediate scalars, because I find this very difficult to read and understand.
|
# ? Dec 23, 2010 09:51 |
|
It's also a good bit easier to run through in a debugger like Komodo.
|
# ? Dec 23, 2010 10:01 |
|
syphon posted:Ok, so how do I loop over each array element and access that data? Running "print $array->[0]->{CLOCKSPEED};" does indeed output '2400 MHz', but running code:
Edit: didn't realize how many replies there were, my bad.
|
# ? Dec 23, 2010 12:41 |
|
Roseo posted:Oh, and think about this. You don't need intermediate scalars. It was kind of making GBS threads itself without the scalars before, but yeah, I come from a background of more Python and scripting, I'm used to making each line do one thing and making it clear and simple code. But thanks, I see what you mean and I'll fix it when I get home. Is there a decent write up anywhere on making things a webapp in Perl? I was considering something along the lines of Titanium since it's supposedly pretty lightweight. Google's mostly been extolling the virtues of each without going into the process. For anyone interested (and nerdy enough), the goal is to write a web-based combat tracker for the Heros/Champions gaming system.
|
# ? Dec 23, 2010 14:09 |
|
Casao posted:It was kind of making GBS threads itself without the scalars before, but yeah, I come from a background of more Python and scripting, I'm used to making each line do one thing and making it clear and simple code. I'm going through http://advent.perldancer.org/2010 at the moment, which may fit the bill. It's also quite lightweight. Also, one thing I was going to mention is that you don't need to writesubroutines for common tasks done to hashes, arrays, etc. Go through http://search.cpan.org/~drolsky/Moose-1.21/lib/Moose/Meta/Attribute/Native.pm. code:
Roseo fucked around with this message at 04:26 on Dec 24, 2010 |
# ? Dec 24, 2010 03:41 |
|
Roseo posted:I'm going through http://advent.perldancer.org/2010 at the moment, which may fit the bill. It's also quite lightweight. Using that powers change, getting: quote:Cannot delegate addPower to push because the value of powers is not an object (got 'ARRAY(0x100b12808)') at ./Champion.pl line 11 Triggering it is: code:
Any idea why my created object is coming off as an array?
|
# ? Dec 24, 2010 04:27 |
|
Casao posted:Using that powers change, getting: Add traits => ['Array'], to the powers declaration and see if that fixes it, sorry about that. I haven't done too much actual code with it, most of my experience is from the MooseX extension that became this (they transferred it from an extension into the core as it was so useful, but switched up the API somewhat)
|
# ? Dec 24, 2010 05:08 |
|
Native traits are nearly as cool as Moose itself, inlining them was a great idea.
|
# ? Dec 24, 2010 14:20 |
|
Roseo posted:Add traits => ['Array'], to the powers declaration and see if that fixes it, sorry about that. I haven't done too much actual code with it, most of my experience is from the MooseX extension that became this (they transferred it from an extension into the core as it was so useful, but switched up the API somewhat) That got me there, thanks. And thanks for the Dancer thing, looks nearly perfect, and good walkthrough. This should do nicely.
|
# ? Dec 24, 2010 17:51 |
|
So I'm working on a fairly simple thing, but I've run into the terrifying bugaboo of regexps. (All of the following is using single-line mode, since I'm only really worried about separating out broad sections chunk-by-chunk from the formatted text files I'm working with.) The files I'm trying to read have a fairly standard format, with an intro ID number and name, a small block detailing general info about the file, an arbitrary number of PARTs, and then a marker for the end of the file. Kind of like: pre:SECTION 12345 SOMETHING SOMETHING ** Blah blah blah blah blah blah. PART 1 SOMETHING 1.1 SOMETHING SOMETHING A. Something PART 2 SOMETHING 2.1 SOMETHING SOMETHING A. Something END OF SECTION code:
EDIT: As is often the way with these things, figuring out how to describe the problem made me think of a whole new angle to attack it from, and now doing that, I think I've figured out a completely different way to do what I want that's working better. anagramarye fucked around with this message at 13:53 on Dec 29, 2010 |
# ? Dec 29, 2010 11:51 |
|
I found as a general good idea kind of rule, that when regexps get really long there is probably a better way to do it by breaking it down. Since the format is fairly standard you could use multiple regexps according to which section you're processing.
|
# ? Dec 29, 2010 19:54 |
|
The Gate of Nanna posted:I found as a general good idea kind of rule, that when regexps get really long there is probably a better way to do it by breaking it down. Since the format is fairly standard you could use multiple regexps according to which section you're processing. Yeah, I realized that like five minutes after I posted that, and switched to a recursive thing that's working way easier. My problems now are coming from the people who formatted the original text files having been 90% consistent but not having gone that last 10% at all
|
# ? Dec 30, 2010 02:02 |
|
|
# ? May 21, 2024 17:03 |
|
Just a note for the future, a better way to write out regex questions in my mind is to do the following: This is the data I'm parsing: code:
code:
I'm also more of a fan of a hash as storage when it comes to parsing out multiple values of data from raw text; it's far easier to pull out the data values you want from a hash than trying to remember the array position for the particular text you wanted, especially if your regex falls over with some data, and ends up populating the array incorrectly with odd data that caused an accidental match in your regex: It makes it far easier to spot in Perl's debugger when you can see that $regex_results['section_num'] contains incorrect data, rather than remembering what $regex_results[5] is for.
|
# ? Dec 30, 2010 03:23 |