Slash Boxes
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.
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'
        $ ~/perl/5.10.0/bin/perl -E '$x = 1; for ( $x ) { $_++ } say $x'

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

          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"

          • 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.