in reply to Split a string into individual words

# --- Part one --- @single = qw(I sit here and think- what the-hell am i doing with perl?); foreach (@single) { s/[,.?-]//g; # Updated: strip punctuation print "$_\n"; } # --- Part two --- $a= "I sit here and think- what the-hell am i doing with perl?"; $a=~ s/[,.?-]//g; print "$_\n" for $a =~ /(\w+)/g;

And the output -
I sit here and think what thehell am i doing with perl

Replies are listed 'Best First'.
Re: (2) Split a string into individual words
by pzbagel (Chaplain) on Feb 06, 2004 at 01:14 UTC

    Roger,

    Your code fails to keep 'the-hell' as one word which the original poster stated was a requirement. Also it doesn't answer the original posters question about why qw($a) only leaves then with 'a' after s///.

      Ah, thanks for pointing out the bit about 'the-hell'.