in reply to split this

The following groups them correctly but is still inserting extra blanks.

$x = 'E/stYna~ko'; @j=split (/(\w\W*)/, $x); foreach $j(@j){ $i++; print "$i - $j\n"; } print "\n";

(I added the extra code for clarity of output. It was hard to see where the exrta blanks were otherwise.)

Replies are listed 'Best First'.
Re: Re: split this
by pike (Monk) on Nov 06, 2001 at 18:04 UTC
    Almost what I was looking for. I just have to grep out the empty fields:

    print join(':', grep /\S/, split /(\w\W?)/,$x); #->E/:s:t:Y:n:a~:k:o
    And yes, using blanks as delimiters in the print was a bad idea -> changed to colons.

    Thanks, pike

more concise
by Fletch (Bishop) on Nov 06, 2001 at 18:06 UTC
      { local $" = "', '"; print "'@j'\n"; }

      perlvar is your friend :)

      Update: Well, OK. Maybe not more concise then. But, maybe easier to follow?

      I think we need a shorter alias for local.

      --
      <http://www.dave.org.uk>

      "The first rule of Perl club is you don't talk about Perl club."

        lemur:~ 404> wc print"'",join("', '",@j),"'\n"; 1 2 32 lemur:~ 405> wc {local$"="', '";print"'@j'\n";} 1 2 32