Robin <[EMAIL PROTECTED]> suggested:
> This will split up the string based on the pattern (in this 
> case, a single space. You may want to change that to gain 
> robustness, e.g. /[ \t]+/ will split on any number of spaces and tabs)

I suggest /\s+/ instead. This splits on any whitespace,
and it'll also remove trailing whitespace like those
pesky trailing \n:


#!/usr/bin/perl -w

use strict;

my $string = "foo baz bar\n";

foreach my $word (split/[ \t]+/, $string) {
  print "'$word'\n";
}

foreach my $word ( split/\s+/, $string ) {
  print "'$word'\n";
}


HTH,
Thomas

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to