in reply to Getting range from N..end with list slice

Not ideal:
(undef, undef, undef, @set) = (split ' ', $x);

Replies are listed 'Best First'.
Re^2: Getting range from N..end with list slice
by Marshall (Canon) on Nov 27, 2010 at 13:02 UTC
    Good thought. The problem is that this doesn't scale very well. Some of these files can have lines with hundreds of fields. I'm working with file like that now and I wouldn't be surprised if I find some field that means "name of user's first dog"! :)

    Something like this would scale better and run fast, but of course it is two statements and doesn't use list slice.

    my $x = "a b c d e f g h"; my @set = (split /\s+/, $x); splice(@set,0,3); print "@set\n"; #prints d e f g h
      Personally, I wouldn't fret on it. If the point is you want to do it all in one statement:
      my @set = (split /\s+/, $x)[3 .. -1 + split /\s+/, $x];
      But that splits twice.