|
Wow thank you, I've been working on this for a month.
|
# ? Dec 20, 2009 19:40 |
|
|
# ? Jun 1, 2024 09:54 |
|
^ and its counterpart $ are pretty basic regular expressions special characters; if you don't know them, it's probably because you never got a good introduction to perl (autodidacts in any field tend to have gaps in their knowledge). The canonical way to learn perl is via either the book Programming Perl (the 'Camel book') or Learning Perl (the 'llama book'). If you want something online, you could do worse than A Beginner's Introduction to Perl 5.10, or perldoc. Perldoc is way useful for more in-depth topics as well; for example, here's a regular expressions tutorial in perldoc. There are a couple other bits of perlish syntactic sugar in the code I wrote, but you'll pick that up pretty quickly as you progress.
|
# ? Dec 20, 2009 20:29 |
|
Figured I'd move this to here instead of a separate thread: I'm working on a perl script that will end up putting about 500000 entries into a hash. Any perl coders out there know if there's a maximum that I'll be hitting or anything like that? I couldn't find much info on the algorithm that perl uses.
|
# ? Dec 22, 2009 00:02 |
|
You won't find a maximum aside from your RAM. I'd honestly suggest doing this with a database, MySQL or SQLite, instead of a hash.
|
# ? Dec 22, 2009 00:07 |
|
^^^^ That's a good idea, and take a look at tie() in perldoc while you're at it Generally perl lacks static limits and you can keep on truckin til malloc fails I believe recent perl still uses this hash function Blotto Skorzany fucked around with this message at 00:14 on Dec 22, 2009 |
# ? Dec 22, 2009 00:11 |
|
Mithaldu posted:You won't find a maximum aside from your RAM. I'd honestly suggest doing this with a database, MySQL or SQLite, instead of a hash. Ok thanks. Yeah, I know it's gonna be pretty slow, but it's just a rarely used script for parsing certain parameters of a log file and doing some processing and comparisons.
|
# ? Dec 22, 2009 00:11 |
|
Does anyone have any experience using perl with emacs? I was recommended the cperl mode, but being fairly new to emacs, I have no idea how to set that up. All I know is something about the Init file which I don't know how to find.
|
# ? Jan 5, 2010 21:25 |
|
Any HTML::FormHandler users around? I've got a form which is comprised of a few sub-forms which are pulled in with Moose's extends() function, and I need to make some values readonly at run-time, but the readonly() attribute for a field is => 'ro' so it blows up when passed a value, and my Moose-fu isn't yet strong enough to switch an attribute to is => 'rw' by tweaking the field's meta-class (from looking at the source for Moose::Meta::Attribute I'm not sure it's even possible). Edit: Solved by nasty hacks. Mario Incandenza fucked around with this message at 13:11 on Jan 6, 2010 |
# ? Jan 6, 2010 08:02 |
|
On that note, how would I go about altering the delagations (handles) for an attribute. My idea is to call the fields method on a Rose::DB::Object subclass and then push that all to a specific attribute's delegations. Haven't been able to figure out how to do this yet but it will solve a lot of upcoming issues I'm going to have to slave over if I don't do this now.
|
# ? Jan 6, 2010 14:31 |
|
Well I figured out the emacs nonsense. But now I a little confused about the right way to go about what I'm trying to do. I realize that this is all pretty basic, but I'm pretty new with perl and, until now, haven't really been using it for what I'm supposed to (I'm just now getting something to do the deals with text). I have to read in a text file, grab some numbers out, and transplant them into another one. I know it should be simple, but I just have a few questions. First, can I just open the filehandle and immediately start scanning through it with index? If not, how do I turn it into a readable string, or do I even want to do that? I'm also a little unsure about how to go about grabbing the data. I assume once I've indexed to where I want to be I can just use regular expressions to grab what I want, but I'll see when I get there.
|
# ? Jan 7, 2010 19:43 |
|
code:
code:
code:
Blotto Skorzany fucked around with this message at 20:28 on Jan 7, 2010 |
# ? Jan 7, 2010 20:14 |
|
Otto Skorzeny posted:
Great! thanks!
|
# ? Jan 7, 2010 20:52 |
|
How would you deal with an input file that's split up into several different parts, most of which I don't need, if I'm reading in the file line by line? I was planning on setting up a hash of different flags that would tell what I was trying to do at that particular point, and having the reading loop just be a bunch of if-statements about what to do if the flags are set up a certain way. Does that seem too convoluted or is there maybe a better way of doing that?
|
# ? Jan 7, 2010 21:34 |
|
Maybe the flip flop operator can do what you want.
|
# ? Jan 7, 2010 21:44 |
|
Triple Tech posted:Maybe the flip flop operator can do what you want. I didn't even think about doing something like that but it seems like to could definitely help out.
|
# ? Jan 7, 2010 22:54 |
|
Triple Tech posted:Maybe the flip flop operator can do what you want. Whoa. I only just now understood why it's called flip flop. Thanks for the link.
|
# ? Jan 8, 2010 10:02 |
|
Triple Tech posted:Maybe the flip flop operator can do what you want. Quick question, does this work for any conditionals, or just regular expressions?
|
# ? Jan 8, 2010 16:05 |
|
Any time it's being evaluated in a scalar context
|
# ? Jan 8, 2010 16:22 |
|
Otto Skorzeny posted:Any time it's being evaluated in a scalar context so does code:
|
# ? Jan 8, 2010 16:40 |
|
No. Are you looking for if(($i==3)..($i==6))?
|
# ? Jan 8, 2010 17:01 |
|
Captain Frigate posted:so does [mah codez] do what I think it does? No. You usually flip flop between boundaries (like $i == 2 or /START/). If you run your code, you print everything from 3 up. Why: The code fails until it hits three. At which point it satisfies and flips to the second condition. Code up until that condition is true, it's less than seven. Then, when you hit seven, that second expression is false, so it flops back to the first. But wait, every high number is always greater than 2. So it prints the rest. You want hard boundaries like Vanadium posted.
|
# ? Jan 8, 2010 17:09 |
|
Vanadium posted:No. Are you looking for if(($i==3)..($i==6))? Hm. Trying that for some reason causes an infinite loop or something. It just keeps printing sixes. EDIT: Ok, it looks like it skips the rest of the numbers as well. It goes straight to six and just stays there. EDIT 2: Well, I did some fiddling around. This is what I'm getting, and it doesn't make a whole lot of sense to me. code:
Captain Frigate fucked around with this message at 17:45 on Jan 8, 2010 |
# ? Jan 8, 2010 17:11 |
|
Captain Frigate posted:I don't think I really understand what's going on here. Me either. This worked for me, as in it printed 3, 4, 5, 6: code:
|
# ? Jan 8, 2010 17:59 |
|
Vanadium posted:Me either. This worked for me, as in it printed 3, 4, 5, 6: Wow, this is why I try and avoid coding. The reason it was repeating was because I was assigning values in the if statements with "=" instead of checking them... Captain Frigate fucked around with this message at 18:04 on Jan 8, 2010 |
# ? Jan 8, 2010 18:01 |
|
So here's my final chart (probably mostly for my own reference, but it might help someone else too)code:
|
# ? Jan 8, 2010 18:13 |
|
Or to abstract the chart a bit:pre:$res = $x .. $y; (state) starts false and represents the internal hidden state of the .. operator. * - Either True or False. $x | $y | (state) || $res | (new state) --------------------------------------- F | * | F || F | F <-- Pre-Flip or post-Flop F | F | T || T | T <-- Post-Flip and pre-Flop T | F | * || T | T <-- Flip * | T | T || T | F <-- Flop T | T | F || T | F <-- Immediate Flip-Flop
|
# ? Jan 8, 2010 18:29 |
|
Ok now I have a question about regular expression matching variables. I'm sorry to be filling the thread with my poo poo, but I can't seem to find any good explanation in the books that I have. Lets say I have:code:
|
# ? Jan 8, 2010 22:29 |
|
regex vars always refer to the most recent regex computed
|
# ? Jan 9, 2010 17:34 |
|
Guess the context!code:
|
# ? Jan 11, 2010 19:46 |
|
Another quick, stupid question. This time about filehandles (at least that's what I think I'm doing wrong). Lets say I want to print out all of the lines of a script after a certain number of lines, so I try something like this: code:
|
# ? Jan 12, 2010 20:16 |
|
You ought to increment $i when it is below 190. I am guessing you misunderstand next.
|
# ? Jan 12, 2010 20:22 |
|
Vanadium posted:You ought to increment $i when it is below 190. I am guessing you misunderstand next. Ah, good! That makes sense to me so far. I moved the $i++ to inside the first if statement and it worked fine. But how about this thing: code:
EDIT: Or is this because it's a new file, and therefore empty, causing a "false" value in the (<$outfile) statement? EDIT2: Ok, I'm pretty sure that's what was causing the problem because I made it into a normal for loop: code:
Captain Frigate fucked around with this message at 20:43 on Jan 12, 2010 |
# ? Jan 12, 2010 20:37 |
|
You're doing well, checking for errors on the open() and using lexical filehandles. I'd suggest 1) checking that chdir() isn't failing: code:
code:
So overall, you could write something like code:
|
# ? Jan 12, 2010 20:45 |
|
Captain Frigate posted:Ah, good! That makes sense to me so far. I moved the $i++ to inside the first if statement and it worked fine. But how about this thing: What is <$outfile>? That's your first problem. You've opened a filehandle for write, and then <$outfile> is trying to read it, but since that file is empty it just bombs out of the for loop right away and your output file stays empty. I think you need two filehandles, one for the output file (which is what you've already done) and one for input. When you're a beginner, mucking around with files in-place is a very good way to delete or corrupt your files. Read from one, write to a second: code:
|
# ? Jan 12, 2010 21:26 |
|
Neat! I didn't know about the $. That could actually come in handy!
|
# ? Jan 12, 2010 21:27 |
|
You almost never want to docode:
code:
Also, CanSpice slightly messed up the syntax when converting the for to a while. You would want code:
|
# ? Jan 12, 2010 21:30 |
|
Captain Frigate posted:Neat! I didn't know about the $.
|
# ? Jan 12, 2010 21:33 |
|
Another smallish question: is there any simple way of converting numbers in strings to integers? Lets say I read in some number as a string and want to add some some number and output the result as a string. How would I go about doing this, if they are all integers?
|
# ? Jan 12, 2010 21:41 |
|
At a really high level, there aren't really types with scalars. (internally, there is, but that's not what we're talking about)code:
|
# ? Jan 12, 2010 21:46 |
|
|
# ? Jun 1, 2024 09:54 |
|
Triple Tech posted:At a really high level, there aren't really types with scalars. (internally, there is, but that's not what we're talking about) This is really something I should have remembered.
|
# ? Jan 12, 2010 21:50 |