in reply to Split a string into individual words
I don't know the best way of getting rid of the newlines. Output:#!/usr/bin/perl $sentence= $a= "I sit here and think- what the-hell am i doing with perl?"; @segments = split(/\b$word\b/, $sentence); #@segments = grep { $_ ne '' } @segments; #remove undef elements @segments = grep { $_ ne ' ' } @segments; #remove space elements #print "$#segments\n"; print "$sentence\n"; $"="\n"; print "@segments\n";
I sit here and think - what the - hell am i doing with perl ?
|
|---|