in reply to (take two...) Re: A split ing headache
in thread A split ing headache

I tend to use alakaboo's construct when doing this: my (@bits) = (split /:/, $thing,4)[0..2] well, except that I constrain it to one more than the slice size so it doesn't do extra work.

When assigning to a list of scalars I use: my ($a, $b, $c) = split /:/, $thing, 4; knowing that the last item with all the unsplit bits will just blow away. No reason to promote a list to an anonymous array when you don't have to. Not a big deal tho but I've always felt that asking for 4 parts and only saving 3 made more sense.

--
$you = new YOU;
honk() if $you->love(perl)

Replies are listed 'Best First'.
Re: Re: (take two...) Re: A split ing headache
by japhy (Canon) on Dec 12, 2000 at 19:37 UTC
    Perl does that for automagically. split() knows how many scalars (if a finite number) you had on the left-hand side of the function call, so it will optimize itself thus.

    japhy -- Perl and Regex Hacker
      You can put perl5 on my system but you can't get perl4 outta my head =) Ahh well, it USED to be a good idea...

      --
      $you = new YOU;
      honk() if $you->love(perl)