|
Mithaldu posted:You need to stop golfing your stuff so hard. Hey everyone, pro tip! This one, right here! Just because you can chain nested indices together doesn't mean you should! code:
|
# ? Jan 22, 2010 16:54 |
|
|
# ? May 17, 2024 01:54 |
|
I think Mithaldu's got the right idea with making it more readable. Regardless, for the sake of information, here's a working version of the original.code:
|
# ? Jan 22, 2010 16:56 |
|
Readable version:code:
code:
|
# ? Jan 22, 2010 17:06 |
|
Mithaldu posted:You need to stop golfing your stuff so hard. Try it like this. Wow I did that and it worked out great! I assume perl like references better than lots of stacked brackets? I'm not sure what you mean by golfing though. Ok, so how about assigning hashes to array indices? Would that look something like: code:
|
# ? Jan 22, 2010 17:35 |
|
Golfing. To code emphasizing the least amount of keystrokes. Usually results in lovely, unreadable code.Captain Frigate posted:Wow I did that and it worked out great! I assume perl like references better than lots of stacked brackets? I'm not sure what you mean by golfing though. Yes, pretty much. But after the first index, you don't need subsequent arrows for dereferencing. code:
|
# ? Jan 22, 2010 17:41 |
|
Your mistake was simply that you didn't understand what $# does. It gives you the last index of the array that has the name that follows directly after those sigils. So if you do something like: $#array[$i] perl tries to do this: 5[$i] (if @array has 6 entries). Obviously 5 is not an array, so it fails. If you do something like this: $array[$i]{array} then you get back a reference to an array. If you want to treat that like an array you have to dereference it and tell perl how you want to treat it, either as an array: @{ $array[$i]{array} } or that you want to extract the last index number: $#{ $array[$i]{array} } Of course this looks like arse and is completely undebuggable without going insane, so you just don't do things like that and keep them simple. code:
Here's alternatives on how to do this: code:
code:
|
# ? Jan 22, 2010 17:48 |
|
quote:# quote your keys goddammit
|
# ? Jan 22, 2010 17:49 |
|
You know what, I take back what I said about quoting keys. My misunderstanding. I thought the default case was it as an expression. Turns out that hasn't been the case for some time. I got it backwards. I'm confusing it with functions that consume parenthesis.
|
# ? Jan 22, 2010 17:58 |
|
I have no idea why functions feed on parens, but at least it's good to know i'm not insane. Fake-Edit: Do you mean flattening of lists?
|
# ? Jan 22, 2010 18:04 |
|
The canonical example of what I was referring to is:code:
|
# ? Jan 22, 2010 18:14 |
|
Triple Tech posted:
Triple Tech posted:
|
# ? Jan 22, 2010 18:22 |
|
Ok, how about getting a reference to an array stored in a hash? I feel like it would work like this:code:
Those two tell me that I have the wrong kind of reference, and if I change the sigil to % I get a syntax error. EDIT: Triple Tech posted:The canonical example of what I was referring to is: I have no idea what is happening here. What does the preceding "+" do? Captain Frigate fucked around with this message at 21:01 on Jan 22, 2010 |
# ? Jan 22, 2010 20:59 |
|
Captain Frigate posted:Ok, how about getting a reference to an array stored in a hash? I feel like it would work like this: array is an arrayref already because you used []. You can get it simply http://codepad.org/ofB2C9R3
|
# ? Jan 22, 2010 21:03 |
|
Wow, way too much crazy going on up there. You have a fundamental misunderstanding with references and how to access them. Granted, I went through the exact same thing, but once you get it, it's pie (except for maybe some weird edge cases or trying to find the last index of an array ref, both of which could easily be addressed by not nesting indices).Captain Frigate posted:I have no idea what is happening here. What does the preceding "+" do? The "unary plus" operator forces Perl to evaluate the expression in a different manner. In the first example, it consumes the parenthesis before print can, so print evaluates over the whole expression instead of just the parenthesis. In the second example, you're saying that print should be treated as more than just a bareword, and that you want to plusify (aka do nothing to) the return value of a function called print.
|
# ? Jan 22, 2010 21:06 |
|
Captain Frigate posted:references ??? Play around with what it does, step by step. Then ask here for clarifications on things that are still unclear.
|
# ? Jan 22, 2010 21:17 |
|
Captain Frigate posted:Ok, how about getting a reference to an array stored in a hash? One thing to keep in mind is that scalars are the only thing you can store inside arrays and hashes. So when you do this: code:
(Technical sidenote: For simplicity, I skipped over a small intermediate step where the data being assigned to the hash is technically a list.)
|
# ? Jan 23, 2010 00:11 |
|
I'm using Perl for the first time. I'm coming from doing C# in MS Visual Studios 2008, and now all I have access to is xemacs. The transition is a little rough. I find I'm spending waaaay too much time tracking down where I forgot a ; or $. Is there an IDE out there that can do syntax highlighting and error checking?
|
# ? Jan 23, 2010 23:44 |
|
It is a bit glitchy due to being a Firefox based ... thing, but Komodo IDE will give you a visual line debugger and syntax checking exactly like you're used to.
|
# ? Jan 23, 2010 23:47 |
|
xemacs should do syntax highlighting and some form of auto-indenting for you
|
# ? Jan 23, 2010 23:48 |
|
Wasted two hours trying to figure this out. I give up. I'm using Windows XP, Perl 5.x. On the command line, if I do this in a directory: code:
code:
But when I try to opendir in Perl, I'm very clearly missing files, specific ones--about five of them. I've tried: * Running ATTR using Windows; all of the files have A set. * These files exist in Perforce, so I've tried deleting locally and Force Synching. The same files are missing in Perl. * Curiously, I did code:
* In Perl, I tried code:
* In Perl, code:
In all appearances there is no hidden attribute set on these absent files. I've also tried renaming the file (file2_2.xml)--still nothing. There is some MAGIC PROPERTY set on these files that I can't for the life of me detect. For the love of God HOW DO I MAKE THESE FILES ACCESSIBLE? tl;dr: can see the files in Explorer; can see them using dir at the command line; cannot see them whatsoever in Perl.
|
# ? Jan 27, 2010 02:55 |
|
1. What's your exact Perl version 2. What are your results from doing code:
|
# ? Jan 27, 2010 03:31 |
|
Otto Skorzeny posted:1. What's your exact Perl version 1. 5.8.8 built for MSWin32-x86-multi-thread 2. Had to install Path::Class using ppm. Mother effer. Riddle me this: * I'm using Cwd. When I did 'cwd()' for the path to folder, the files were missing * When I used '.' (script is running in the same dir), the files were missing * When I used an absolute path, e.g. 'C:/dev/dir/', the files were goddamn there. Edit: just tested--absolute path with opendir shows the files, too Explanation, anyone? Sabacc fucked around with this message at 20:05 on Jan 27, 2010 |
# ? Jan 27, 2010 19:47 |
|
Hurf durf Windows. :B
|
# ? Jan 27, 2010 22:27 |
|
Sabacc posted:Explanation, anyone? Your working directory is not what you think it is? If the only way you can access the files is absolute and not relative, perhaps your script *isn't* running with the cwd you expect.
|
# ? Jan 28, 2010 13:07 |
|
tef posted:Your working directory is not what you think it is? If the only way you can access the files is absolute and not relative, perhaps your script *isn't* running with the cwd you expect. In that same directory that I am opendir() into, I'm processing all the files. it just threw a "cannot open" file on one of the missing files I noted earlier. God only knows, maybe there is some encoding corruption or something. Edit: Forget it, appending an absolute path fixed this problem too. No encoding/XML errors that I can see. Who knoooooowsssss Sabacc fucked around with this message at 00:51 on Jan 30, 2010 |
# ? Jan 30, 2010 00:38 |
|
A wizard did it
|
# ? Jan 30, 2010 01:24 |
|
speaking of magic, Moose::Util::TypeConstraints* is pretty neato-burrito, and brings some perl 6-ish features to 5:code:
*I've been informed that MooseX::Types is similar but 'higher tech' but haven't given it more than a cursory glance myself e: added links
|
# ? Jan 30, 2010 10:53 |
|
MooseX::Types is worth looking into, if you're creating your own types there's the possibility of collisions with other packages that define the same type, whereas MX::Types prefixes all custom types with the calling package, preventing this. It also exports the short version of those names into your class via a constant sub, meaning you don't have to quote your types:code:
|
# ? Jan 31, 2010 02:38 |
|
Someone on either #moose or #perl (don't remember which and too lazy to Still, it impresses me that they're that close to compatibility with something as crufty as gcc (as horriffic as perl's internals are, gcc's are far, far worse. They use a somewhat bizarre mix of their own wrappers around malloc/free that iirc allocate from their own arena, their own custom garbage collector, and semi-automatic management via obstacks. I'm told it takes a reasonably skilled programmer about 6 months to get up to speed to the point they can work on the parser or codegen). Now, the Perl codebase is in C, which they've had more or less under down pat for a while (along with Objective-C for reasons you can guess), but as you've probably heard the clang folks are making strides in C++ too, just very recently advancing to the point that the compiler is self-hosting.
|
# ? Feb 10, 2010 00:17 |
|
It must've been #perl because it wasn't #moose.
|
# ? Feb 10, 2010 01:36 |
|
for (('to you', 'dear '.shift)[0,0,1,0]) { print "Happy birthday $_! " }
|
# ? Feb 16, 2010 21:34 |
|
Otto Skorzeny posted:for (('to you', 'dear '.shift)[0,0,1,0]) { print "Happy birthday $_! " } Mind blown. Is it someone's birthday? Edit: code:
Triple Tech fucked around with this message at 21:48 on Feb 16, 2010 |
# ? Feb 16, 2010 21:45 |
|
Triple Tech posted:
Incidentally, you can enable all supported features by running with -E rather than -e :tmyk:
|
# ? Feb 24, 2010 09:23 |
|
Tatsuhiko Miyagawa is the best thing to happen to Perl in a decade. First, he wrote Plack. Then he found that CPAN.pm was swapping on his VPS, so he wrote cpanminus, which is tiny, does the right things with no configuration, and covers enough to almost entirely replace CPAN(PLUS).
|
# ? Feb 24, 2010 21:45 |
|
So it doesn't seem to be widely documented and I suspect it's a bit of a dirty hack, but I've discovered a fairly easy to enable cross-schema joins with DBIx::Class and Catalyst - change your schema class's __PACKAGE__->table definition to use the fully qualified name:code:
code:
code:
code:
|
# ? Feb 25, 2010 08:22 |
|
So I was golfing the other day and tried to get an array slice to the end of an anonymous array and realized I couldn't find any way to do it without somehow naming the array first. E.g., neither of the following work: code:
|
# ? Mar 8, 2010 07:15 |
|
How's this?code:
|
# ? Mar 8, 2010 12:55 |
|
Mario Incandenza posted:How's this? EDIT: I know something like (@bar[0..2], @foo) = split; works too -- I was just surprised that the range syntax doesn't work. frunksock fucked around with this message at 17:36 on Mar 8, 2010 |
# ? Mar 8, 2010 17:13 |
|
Thought that might be the case. In that case, try assigning to undef, it looks weird but should work in recent versions of Perl (a quick Googling didn't tell me which version made it syntactically valid):code:
Mario Incandenza fucked around with this message at 19:15 on Mar 8, 2010 |
# ? Mar 8, 2010 18:55 |
|
|
# ? May 17, 2024 01:54 |
|
Why does code:
code:
|
# ? Mar 22, 2010 20:06 |