in reply to Re: Looping through a split() and more...
in thread Looping through a split() and more...

Don't do that with split(), (please)

split() works as follows ( I know it may work the way you have it but.. well... that's just wrong:

split /:/, $passwd_line;
split '', $line; # 'Special' case
Thanks,
--
Casey
  • Comment on RE: Re: Looping through a split() and more...

Replies are listed 'Best First'.
RE: RE: Re: Looping through a split() and more...
by takshaka (Friar) on Jun 01, 2000 at 03:37 UTC
    To what, in particular, are you refering?
      I'm refering to splitting on a scalar value such as the following wrong way:
      split "\n", $line;
      
      --
      Casey
      
        How about split '\n', $line;

        That's still splitting on a pattern, not a literal. Quotes are only special to split in those cases described in perlfunc, otherwise they are regex delimiters.

        The same holds true for the rhs of a '=~' expression.

        chh@scallop chh> perl -le '$a="foo\nbar"; print $1 if $a =~ "\n(.*)"' bar chh@scallop chh>

        It's potentially misleading but not wrong.