OK, printline could be a function/method, eg:
Code:
my $s = "This is a string";
while ($s =~ s/^(\w+ ?)//) {printline($1);}
sub printline {
my $word = shift;
print $word, "\n"; # or, less clear but all on one line: print $_[0], "\n";
}
In that case your example would indeed have done as you suggested, and printed one word per line. The bracket - printline() - just helps make it a bit clearer and less ambiguous, and means printline doesn't need to be pre-declared.
And of course I need to point out that
Quote:
print join '\n', split / /, "This is a string";
should read
Code:
print join "\n", split / /, "This is a string";
otherwise \n is interpreted literally - This\nis\na\nstring - which I'm sure was originally a typo and you knew that already
