in reply to Re^3: get a certain number of words from a line
in thread get a certain number of words from a line

I'd like to try it, but I don't have perl5 where I am this week. My understanding is that \(1..10) is shorthand for (\1,\2,\3,...,\10), and that your list will be flattened, so that (\(1..10),\(11..15)) is the same as \(1..15).

It's not a feature I've used, myself, so I could certainly be misunderstanding it. If I am, I would genuinely appreciate someone making it clear to me.

It took me a minute to decode "array slide" as "array slice". I thought you were talking about a feature I'd never heard of!

Update: from perlref:

Taking a reference to an enumerated list is not the same as using squa +re brackets--instead it's the same as creating a list of references!

We're not really tightening our belts, it just feels that way because we're getting fatter.

Replies are listed 'Best First'.
Re^5: get a certain number of words from a line
by sleepingsquirrel (Chaplain) on Jun 15, 2004 at 20:02 UTC
    Hmmm... Apparently not for my perl...
    greg@sparky:~/test$ cat ./list_ref #!/usr/bin/perl -w @a=qw/zero one two three four five/; $ref=\(1..3); @b=@a[@$ref]; print "\n \@a=@a\n \$ref=$ref\n \@b=@b\n\n"; greg@sparky:~/test$ ./list_ref @a=zero one two three four five $ref=ARRAY(0x813dcc0) @b=one two three greg@sparky:~/test$ perl -v This is perl, v5.8.0 built for i486-linux Copyright 1987-2002, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. <snip>
    ...And sorry for the typo. This thread (among others) has finally inspired me to create my first perlmonks .sig.


    -- All code is 100% tested and functional unless otherwise noted.
Re^5: get a certain number of words from a line
by sleepingsquirrel (Chaplain) on Jun 15, 2004 at 20:39 UTC
    "Enumerated list" must be the key concept.
    greg@sparky:~/test$ cat enum #!/usr/bin/perl -w use Data::Dumper; $ref=\(0..3); $enum_list=\(4,5,6); print "\n".Dumper($ref)."\n"; print "\n".Dumper($enum_list)."\n"; greg@sparky:~/test$ ./enum $VAR1 = [ 0, 1, 2, 3 ]; $VAR1 = \6;


    -- All code is 100% tested and functional unless otherwise noted.
      What do you get if you do
      $x = \((0..3));
      ?

      As a general rule, I would recommend use of [0..10] instead of the capricious \(0..10), since the former is always a way to get an array ref (and is a char shorter), while the latter is usually a way to make a list of references.


      We're not really tightening our belts, it just feels that way because we're getting fatter.
        Must have been a bug in 5.8.0 that was causing the behavior. Upgrading to 5.8.4 makes it behave like everyone expects. Just for the record, here's what you get for the above query on 5.8.0...
        perl -e '$x = \((0..3)); print @$x' 0123


        -- All code is 100% tested and functional unless otherwise noted.