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

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.
  • I don’t see what’s wrong with that.

    You probably won’t like the way I’d write it either:

    my $_combination_info = {};
    sub combination_info {
        my $self = shift;
        my ( $info ) = @_;
        for ( $_combination_info->{ $self->csv_file_name } ) {
            $_ = $info if @_;
            return $_;
        }
    }

    • by mauzo (8185) on 2009.02.11 15:45 (#67311)
      5.10's given makes that a little less obscure to those unfamiliar with the idiom, or rather, since setting $_ is the only point of given, noone has to stop and think 'what's he looping over again?'
      • $ ~/perl/5.10.0/bin/perl -E '$x = 1; given ( $x ) { $_++ } say $x'
        1
        $ ~/perl/5.10.0/bin/perl -E '$x = 1; for ( $x ) { $_++ } say $x'
        2

        •     perl5.10.0 -E'say \my $x; given ($x) { say \$_ }'
              SCALAR(0x28368370)
              SCALAR(0x283683c0)

          It's a copy? Why on earth? Nothing in Perl copies its parameters. Doesn't that just make the whole feature hugely less useful? It's not as though given (my $tmp = $x) {} is that obscure, especially given its common use in conjunction with s///...

          Oh, and look:

              perl5.10.0 -E'say \$_ given my $x'
              syntax error at -e line 1, near "$_ given"
              Exec

          • I suppose it’s nice to be able to write given ( $foo ) in place of for ( my $copy = $foo ). But yeah, that threw me too. It’s a pity; a missed opportunity, even.

            The fact that you can’t use given as a statement modifier doesn’t bother me.