Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

schwern (1528)

schwern
  (email not shown publicly)
http://schwern.net/
AOL IM: MichaelSchwern (Add Buddy, Send Message)
Jabber: schwern@gmail.com

Schwern can destroy CPAN at his whim.

Journal of schwern (1528)

Sunday September 23, 2007
05:30 PM

push @{ $foo{bar} }, 3; vs $foo{bar}-push(3)

[ #34526 ]

A few weeks ago a friend of mine, who is a Ruby programmer that has to write Perl for $job, said "Perl makes me cry". He gave specific examples, one was...


Perl:
my ($self) = @_;
push @{ $test_files{ident $self} } , @failure_files;

Ruby:
@test_files.push(*failure_files)

I feel like perl is actively resisting me here.

And he's right, it is. The dereferencing syntax has nasty, sharp edges.

I thought autobox would solve this, but it doesn't add in the core functions. Then I discovered autobox::Core which does!

    use autobox;
    use autobox::Core;
 
    $test_files{ident $self}->push(@failure_files);

It's shorter, it involves less #*@(}, and it gets the subjects and verbs in the right order.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • You might also want to take a look at Moose::Autobox. It has a different goal from autobox::Core, which is to be more like the proposed core types and methods for Perl 6 (mostly found in Syn 29). And as far as your ruby-friend is concerned, you might want to show him Moose itself, he might not miss ruby as much.

    - Stevan
  • It seems like this would be less difficult if he didn't use Class::Std. A normal hash-based object makes it look simpler to me anyway:

    push @{ $self->{'files'} }, @more_files;
    • Throwing in an extra arrow makes it look simpler? Strange definition of simpler. :-)

      I like to preface my inside-out object methods with “my $this = ident my $self = shift;”, btw, which makes that code into this:

      push @{ $test_files{ $this } } , @failure_files;

      Of course Hash::Util::FieldHash [cpan.org]’s idhash function will make that separate $this unnecessary in 5.10 and you’ll be able to just write this:

      push @{ $test_files{ $self } } , @failure_files;

      The real problem persists thro