|
Triple Tech posted:Although I do see the argument of "well, it's a module we developed internally, so we have to put it in our own namespace". True, but sometimes you create things that aren't really proprietary, or could easily be shared with the world. Most any application/module/plugin developed at a company is going to be an IP, even small things like a slightly more specific text parser. Everywhere I've worked has used their own namespace, and even namespaces specific to each individual group. It just adds one more layer of structure, in my opinion, and I see no reason to be rid of the practice.
|
# ¿ Jan 4, 2008 04:47 |
|
|
# ¿ May 2, 2024 23:51 |
|
TiMBuS posted:I use ubuntu. It's my fav distro and you cant change my mind >=( What I did was do a source install to /opt/perl and just changed the shebang to #!/opt/perl/bin/perl. This is only temporary until 5.10 is made available for an upgrade.
|
# ¿ Jan 14, 2008 06:43 |
|
TiMBuS posted:I don't really need it, I just really want it :3 Throw this at the beginning of a 5.8 script: code:
Fenderbender fucked around with this message at 09:36 on Jan 15, 2008 |
# ¿ Jan 15, 2008 09:33 |
|
TiMBuS posted:Ah yeah, nearly forgot about local. Say is definitely really cool, have you seen Perl6::Say?
|
# ¿ Jan 16, 2008 05:13 |
|
Mustach posted:Any clues to what could be causing this? The only thing I can guess is that you have shared objects with mismatched versions?
|
# ¿ Jan 18, 2008 00:01 |
|
German Joey posted:http://search.cpan.org/~davecross/Symbol-Approx-Sub-2.06/ That modules like a disfigured orphan. Horrifying and depressing at the same time.
|
# ¿ Apr 4, 2008 18:09 |
|
Among a bunch of other things, you should concatenate with a period (.) not a comma (,) so the first I'm going to say is to replace: open $out, ">", "$log_dir$csvfile"; with: open $out, ">" . "$log_dir$csvfile"; if not: open $out, ">$log_dir$csvfile"; or even better: open($out, '>' . $log_dir . $csvfile); Couple of suggestions: 1. As has been said use strict; though I generally use #!/usr/bin/perl -w instead of use warnings; thought that's all a matter of taste. 2. If you're declaring variables as the same value (in this case, undefined), you can declare them like my ($foo, $bar, $baz) = 'whatever'; or just my ($foo, $bar, $baz); 3. Also, another useful thing to use for getting a file list is glob() so instead of code:
code:
|
# ¿ May 14, 2008 14:12 |
|
Just because I get some sick joy out of reformatting and condensing code, I took a swing (not that I've tested it, just really reformatted and changed a few things). Do not take this as a lesson in how to write code, this is more for me than it is for you, but it can give you some idea of how it can be done differently. Perl has a lot of stylistic measures that are purely preferential so don't think you're doing something wrong because I'm doing something slightly different. I agree with Triple Tech that we need to write a style guide.code:
Fenderbender fucked around with this message at 15:16 on May 14, 2008 |
# ¿ May 14, 2008 15:13 |
|
Triple Tech posted:I see you and I raise you. Untested. Main problems (with the original code) include not knowing interpolation/parsing tricks and excessive scope. Though you condense the code, there is an amount of readability lost. If you're going for less lines, I think this would save you a few. code:
|
# ¿ May 14, 2008 16:03 |
|
Triple Tech posted:I disagree, actually. I find that as a seasoned Perl guy (and not someone who just uses Perl on the side), less is more. I'm not saying it's a golfing contest. Clearly, I would have lost some strokes (and performance) by introducing those concept scalars. But the way the OP wrote it, those scalars tell you nothing of what business logic is going on. And poo poo like this always bubbles up and turns into maintenance nightmares. Oh, I agree. That is pretty much what goes on in my head as I'm coding. I just see far too often people that have tried to do too much on one line that can be handled more concisely. I completely agree that your way is more concise, I guess I misunderstood what you were attempting to go for. For example, just a few minutes ago I was able to bring 7 lines of someone else's code down to just 3 with a simple open($fh_conf, $conf_file) or die "Couldn't open file $conf_file: $!\n"; my $conf_vars = { map { chomp;split('|') } <$fh_conf> }; close($fh_conf); and lost little readability. I think we're mostly agreeing in different ways.
|
# ¿ May 14, 2008 17:00 |
|
Erasmus Darwin posted:I've got one minor quibble with this. I personally prefer moving the last / to when $csv_dir and $log_dir are used rather than sticking it in the config string: Once again, I completely agree, I was more trying to reformat and clean than change values. I think I might start a Perl style guide thread in the next couple of days based on some of the stuff I've seen in this thread, if anybody would like that.
|
# ¿ May 14, 2008 19:49 |
|
It's a bit late so maybe I'm misunderstanding the discussion or the way it works, but to comment on the above code, => is just an alias for a comma. So when you declare a a hash, if you have (), it's essentially not putting an item in there. In the above example:code:
my %hash = ('foo', 1, 'bar', 'baz', 2); You're placing an empty array as a value, so it's compiled as essentially just nothing, and so it offsets all the key/value pairs in the hash.
|
# ¿ Aug 27, 2008 06:53 |
|
yaoi prophet posted:Sure, we know why it happens, but the point is that it's a gotcha that can cause problems due to the sneaky ways that list context will suddenly appear without you realizing it. Now that I'm awake to compound more on this, there was an interesting issue that arose recently at my work which this list flattening is used for in a legitimate sense. When trying to match "john", "jon", "johnathan", or "jonathan" from an array of first names using map (yes, I know grep is much more suited, but bear with me), the code my coworker was having issue with was something along the lines of @names = qw(john jacob jeremy jon johnathan allan jonathan); @names = map { /^joh?n/ } @names; would return ['john', undef, undef, 'jon', 'johnathan', undef, 'jonathan'] Now, that's because you're returning a false/undefined value since the regex wouldn't match. What instead you needed to do was to use @names = map { /^joh?n/ ? $_ : () } @names; This will use that "sneaky" behaviour of lists to create: ['john', 'jon', 'johnathan', 'jonathan'] This was when I started to realize the usefulness of this behaviour. Thought it might be an interesting enough of an anecdote since it seemed relevant enough even if it's going over something glaringly obvious to most people.
|
# ¿ Aug 27, 2008 14:52 |
|
Sartak posted:While in general you're certainly right (map { ... ? ... : () } is useful), in this case your code can be written as: Fenderbender posted:(yes, I know grep is much more suited, but bear with me)
|
# ¿ Aug 27, 2008 17:00 |
|
syphon^2 posted:I don't know, it seemed that creating a new array and sorting it JUST for the sake of iterating through another hash in a certain manner (alphabetized) wasn't the best way to do things. I had no valid reasons to think so, I just wanted to make sure. Well, as Tech said, you don't need to create a new array, just use foreach my $key (sort keys %$data) {
|
# ¿ Aug 29, 2008 21:41 |
|
I don't know if this would be an ok place for this or anything, but my company is looking for web and application developers specializing in Perl. If you're interested, send me a PM and I'll give you some contact information.
|
# ¿ Sep 16, 2008 13:53 |
|
Triple Tech posted:Randomly curious, what city/metropolitan area are you located in? It's in Nashville, TN Mithaldu posted:Could you please activate the ability for other members here to email you? I don't have PM ability, but if you can accept remote workers i'd be very interested. Or, if you don't want to do that, you could give my ICQ/AIM or Yahoo ids in my profile a poke. Done. I'll also drop you an IM once I get to work.
|
# ¿ Sep 16, 2008 14:26 |
|
I typed this.code:
Fenderbender fucked around with this message at 22:12 on Nov 14, 2008 |
# ¿ Nov 14, 2008 22:10 |
|
s/\\(.{8}).+(\\)/\\\1~1\2/g would work too I would think. Untested and off the top of my head.
|
# ¿ Jan 16, 2009 04:55 |
|
Erasmus Darwin posted:I think your regexp is still broken. Regardless, you need to check the file system to reliably determine a short name due to the possibility of naming collisions. If I make a root-level folder on C: called "Program Stuff", it'll wind up being Progra~2 due to Progra~1 being taken by "Program Files". Ah, yes, completely forgot about that.
|
# ¿ Jan 16, 2009 05:13 |
|
Sock on a Fish posted:I've got a step in a script at which I need to see if two times are equal to one another. They come in as a UTC string, and I'm not sure which is quicker -- convert the string to an integer with str2time and compare the integers, or just use a string comparison on the twenty-odd character string. I can't just use time to test the two methods, since my data gets pulled from an external source that varies wildly in the amount of time it takes to return a query result. If you're not worried about compile-time overhead, Date::Manip is good for such a thing.
|
# ¿ Jan 20, 2009 20:21 |
|
Oh, I completely missed that it's coming in UTC format. I need to readed better.
|
# ¿ Jan 20, 2009 21:08 |
|
atomicstack posted:It's also a handy idiom if you want to merge two hashes: gently caress! I could've used this many times before!
|
# ¿ Jan 29, 2009 02:10 |
|
I've come to love Rose::DB over the past few months.
|
# ¿ Mar 4, 2009 20:01 |
|
hitze posted:I have r93 and TeX::Hypen is in my lib folder. Kind of pointless to mention it now, but you can use a module from the command line with perl -MTex::Hyphen
|
# ¿ Mar 27, 2009 13:52 |
|
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 |
|
Hahaha, when I started using Perl I got into an argument with merlin on PerlMonks about sorting algorithms, unbeknownst to me that merlin = Randall Schwartz.
|
# ¿ Apr 22, 2009 23:42 |
|
SA Support Robot posted:Does anyone here use AnyEvent? I am madly in love with it and wish to project my love upon others. That's pretty cool. For curiosity's sake, what has been your greatest use for it so far?
|
# ¿ Jul 23, 2009 18:34 |
|
I'm getting into Moose and I am looking to make a simple object for a User, but I'm not sure the best way to go about implementing Rose::DB::Object into it. Would anyone be willing to throw me a few pointers on where to start?
|
# ¿ Sep 8, 2009 02:36 |
|
atomicstack posted:Where are you going to be using this user class? If I were doing it in Catalyst, for example, I'd create a new model which consumes the RDBO schemas and loads the row from the database on your behalf, before packing it into the attribute of a Moose object and returning that. Then you call high level methods on the Moose object and it operates on your RDBO row under the hood. I'm writing it for use within my own framework. The current method I've gone about it is as such, though I plan on expanding the fields that 'rose' handles out to include all of the row's fields. Possibly I'll be doing that through more logic in BUILD? I'm not too familiar and if this seems like an obtuse way of getting what I need, please let me know. code:
|
# ¿ Sep 8, 2009 15:42 |
|
atomicstack posted:You can add delegates at run-time, but you'll have to pay the toll of mutability, and to be honest database schemas don't really change all that frequently. Unless you need to do it that way, you might be best off hacking some meta-code into your toolchain so that when you update your schema files, a complete Moose role will pop out that contains a correct has 'rose' declaration, with the table's column names listed as delegates under handles. Then you can replace your existing has 'rose' declaration with, err, with. Did just what you described, took all of 5 minutes to do. Clarifies and compartmentalizes the objects properly with little effort. Moose rules.
|
# ¿ Sep 8, 2009 18:51 |
|
Say, I'm building an object like so:code:
Now in the ESP::Objects::Events I have: code:
|
# ¿ Sep 10, 2009 19:12 |
|
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 |
|
Just going to reask this:Fenderbender posted: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 12, 2010 22:30 |
|
Hurf durf Windows. :B
|
# ¿ Jan 27, 2010 22:27 |
|
demonbleh posted:They're vim fold markers. why not just enable perl_fold in vim?
|
# ¿ Jul 14, 2010 05:59 |
|
Triple Tech posted:I recently took up a new job in NYC in one of the city's like... five or so active Perl shops. It's like a vicious cycle! Anyway, I should be back on the Perl grind soon. I'm going to miss Visual Studio... Probably took my last job. ;X
|
# ¿ Jul 31, 2010 16:45 |
|
I think Perl6 itself won't be making any converts in business, but once a web framework project gets to a stable level and a few evangelists and success stories get out there, there will probably be a slow shift to it.
|
# ¿ Aug 2, 2010 18:37 |
|
yeah you should immediately have red flags going off for backticks the same as when you see eval()
Fenderbender fucked around with this message at 21:50 on Jan 8, 2011 |
# ¿ Jan 8, 2011 21:44 |
|
|
# ¿ May 2, 2024 23:51 |
|
Otto Skorzeny posted:NB. block eval != string eval I thought about editing that to make myself more clear, but was too lazy. Thanks for clarifying.
|
# ¿ Jan 9, 2011 00:40 |