Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

Subotai posted:

You should listen to Randal Schwartz over Damian Conway any day. *shakes fist at Damian Conway*

So why are you posting here and not in the Smalltalk thread? ;)

Adbot
ADBOT LOVES YOU

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
Have a look at Getopt::Whatever and Getopt::Casual, I bet one of those will do what you need.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
While in general you're certainly right (map { ... ? ... : () } is useful), in this case your code can be written as:

code:
@names = grep { /^joh?n/ } @names;

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
I'd say that's acceptable. Symbolic references are forbidden by use strict because it's so easy to screw up in subtle ways with them, if they're allowed everywhere. In your case, the symbolic reference very obvious and deliberate, so it's okay.

As a comment on your design, each $dbh should be replaced by a dbh method. Globals are a universal evil. :v:

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

syphon^2 posted:

Is this the best way to sort hashrefs alphabetically (well, ASCI-betically)?

Yes.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
Never.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
I was asked out of band for clarification. :angel:

I never use direct hash access (outside of accessors of course). This was true even before I started using Moose for every class.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

Subotai posted:

There is no need to try and abstract the internal data members of a class from itself.

Your class will get more complicated. Having layers of abstraction will ease that evolution.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

Subotai posted:

I for one find it much more of a pain in the rear end to have to write a function to access a data member in a class that I already have access to.

If you're writing all of your accessors, yeah I can see how it would be too annoying to do regularly. I just do has foo => (is => 'rw'); of course..

Use Moose, Class::Accessor::Fast, Class::Accessor::Complex, Object::Tiny, I don't care! It is too much of a pain to define new and every accessor for every class.

Subotai posted:

Unless you really think you might have to go back and redo how or the information in the class is stored or handled, and it is too much work to actually change the hash in the places you use it, then go ahead and write an accessor function. I believe it mainly will be a waste of time, involve extra code that doesn't need to be there, and make the code harder to debug.

The key here is to work with Perl's strengths.

$self->accssesor is an error.

$self->{accssesor} is a bitch to debug.

Subotai posted:

He is talking about a simple class in Perl. It shouldn't be something you turn into a monolithic piece of code. He probably shouldn't have any use for accssesor functions internally.

It's a balancing act. The more complex your class becomes, the more you'll want the encapsulation. For me, the tipping point is when I bless.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
That sort of thing is called dynamic scope. It was popular before (the much saner) lexical scope was invented. Perl supports it with the local operator.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

Paradox posted:

This cleanup is an implementation detail and should be hidden from the user if at all possible.

Perhaps you want an END block.

code:
END { unlink @temp_files }
Perl will do whatever it can to ensure that each END block is run at program termination (though some abnormal termination modes can still prevent these from running).

Also, if you're doing OO, then the method called DESTROY will be called just before an object's memory is freed.

If you really need to respond to a signal then I guess just install the signal handler.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

satest4 posted:

$ echo 'END { warn "Dying!\n" } kill("TERM", -$$)' |perl

That works, so it looks like we're..

Suffering from buffering

:ms:

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
Just a reminder that Devel::NYTProf is incredible.

Tim Bunce gave a very informative Devel::NYTProf talk about what it does, how it does it, and how it's better than the others (which all kinda suck in different ways)

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
I have a commit bit to Devel::NYTProf now, so if anybody wants to help support Windows, feel free to talk to me here or wherever. :v:

Triple Tech posted:

Edit: I've been asked to do a really informal presentation on Lua to a group of Perl programmers, but I still want to take it seriously. Aside from generic "learn other languages" benefits, what can learning Lua give Perl programmers?

Lua is actually very similar to Perl. Both provide high-level, orthogonal features. The biggest difference would be Lua's data structure: the table. They're like a hash and an array. Lua has metatables as well, which are actually very much like Perl's tying mechanism (running custom code when you get, set, etc. values in a variable). The feature is saner, and used a lot more in libraries, in Lua than in Perl.

I can't think of any specific things that would help a Perl programmer though.

I really like Lua, I just wish it had the CPAN. :shobon:

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

Triple Tech posted:

Maybe I'm being too idealistic (probably) but if I was developing a sort of Perl tool, a meta-program if you will, I would have concentrated on making it work on the language level and not use any OS-level stuff.

I'm sure it'll work fine on Windows once this one system call is figured out. It's not all going to come crashing down to support Windows.

Besides, this kind of library really has to be built into the interpreter, not on top of it, so it'll be sensitive to different OSes.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
Typically I build a list of all the items, then use join ", ", @items to make sure there are commas only between items.

If you have to process iteratively, then you can do something like:

code:
print get_item();
while (my $item = get_item()) {
    print ", ";
    print $item;
}
Alternatively, if you're building this up in a string..

code:
my $output = '';
while (my $item = get_item()) {
    $output .= $item;
    $output .= ", ";
}
chop $output; chop $output;
But really I recommend just join.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
local::lib is worth having a look at. It manages all the environment twiddling to let CPAN install into your home dir, and having Perl find it.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
There's going to be another Frozen Perl in Minneapolis on February 7th. I'll be there. I've submitted a talk for Devel::REPL and Carp::REPL that will probably be accepted (though I won't find out until November 20th).

Anyone else planning on going?

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
If you're logged into the conference site you can see something like this in your main page:



(Since the conference I'm browsing from is Frozen Perl 2009 it doesn't link it)

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
It is almost pure perl. It depends on PadWalker to get (and set!) lexical information for the entire stack. PadWalker is implemented in C but it's so loving useful that it may eventually get cored.

The only other tricky bit is hooking into die. You can do this by sticking a code reference in $SIG{__DIE__} and it'll be run before the program aborts.

code:
$SIG{__DIE__} = \&repl;
That's it. :D

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
ShoulderDaemon's way is probably best. It's the clearest which is the most important thing for code.

Anyway, the operator you're looking for is splice. Here's how you can use it:

code:
for (my $i = 0; $i < @arr; ) {
    if ($arr[$i] eq 'not') {
        splice @arr, $i, 1;
    }
    else {
        ++$i;
    }
}
One indicator that this code sucks is the C-style for loop.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

Triple Tech posted:

:( It's a shame that Devel::NTYProf doesn't work on Windows.

2.07, released today, does!

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

Voltaire posted:

[9,8,7,6,5,4,3,2,1,0] == [0,1,2,3,4,5,6,7,8,9]

This doesn't work; equality for array references just checks if they point to the same array. You need to iterate over the elements.

This seems terribly obtuse for a homework question. Job interview?

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
What exactly do they forbid or allow? I ask out of curiosity; I'm not going to post a solution for you. The task is yours alone.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

ashgromnies posted:

&is_palindrome($str)

You do know that & is no longer required on function calls right?

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

leedo posted:

$string eq join '', split //, reverse $string

reverse in scalar context will reverse the characters in the string. So just

$string eq reverse $string

is enough.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
Now you suck a little less. ;)

We're all always learning. Don't sweat it.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
I bet it's because Perl has to keep track of the value of $[, which controls the first index of an array. Then again, the perlvar doc says $[ has a compile-time effect. I'd still bet on it though.

$#array is defined as the index of the last element of array @array, so must respect $[. scalar @array is defined as the number of elements in @array and can ignore $[.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
For those of you going to Frozen Perl (Triple Tech, you are, right?), I'm going to be giving two talks. My Devel::REPL/Carp::REPL talk was accepted, and now I'm also giving the Intro to Moose talk.

It's going to be held in Minneapolis on Saturday, February 7th. If anything on the schedule piques your interest, come by and learn something!

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
Lembark may be a dork but his Signal::StackTrace is handy. :shobon:

edit: I use it to find where my code is infinitely looping. A life saver every couple of months.

Filburt Shellbach fucked around with this message at 04:44 on Nov 25, 2008

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
Double negatives kick rear end

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
Are you loving kidding me?

Go take a programming course, go read a book, anything.

You're wasting our time with retard questions.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
I hope you get the job buddy :waycool:

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
Maintain a separate hash of filenames you've seen thus far. Skip files you've seen.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
Set::Object probably has better memory and speed performance than hashes.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
Sets have fewer operations. You can add or remove items, and check if an item is in the set.

Hashes have to do more work, tracking a value for each item.

Though hashes are optimized as gently caress in Perl, sets can easily be made even faster.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
See perldoc -f system.

I will not recommend the use of do EXPRESSION here (or anywhere ever).

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

fyreblaize posted:

sort{$a <=> $b}@x;

<=> compares two numbers. Your strings are not numeric, so each is interpreted as 0 for the purposes of the sort.

cmp compares two strings, which is what you want. Because the default comparator for sort is cmp, just sort @x is all you need.


edit: Oh, it's not really clear what you're actually trying to do. You're assigning the hash %results to the list @x which flattens the hash structure. Maybe sort { $results{$b} <=> $results{$a} } keys %resluts?

Filburt Shellbach fucked around with this message at 03:38 on Dec 6, 2008

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
For god's sakes read it!

Adbot
ADBOT LOVES YOU

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
Your time is worth more than the computer's. Design the program well; don't worry about function or method call overhead until it actually becomes a problem (and it hopefully never will).

The term I've heard for what Triple Tech is describing is decoupling.

  • Locked thread