> I tried
@ans = split (/\r/s, $msg);
@ans = split (/\r/g, $msg);
@ans = split (/\r\n/s, $msg);
@ans = split (/\r\n/g, $msg);
2 things - Perl should handle the \r\n part for you - "\n" is normally a
match for whatever your OS's end of line marker is. You also don't need
the modifiers on the match - split is like a \g already, and \s only
affects the '.' metachar (allowing it to match a newline). So
@ans = split( /\n/, $msg );
*should* work, usually this kind of problem is due to the newlines not
really being there. But, as an idiom, this works to split up a multi-line
string into an array, one line per element. Note also there *won't* be a
new line on the end of each element anymore:
my $msg =
'this is line one
this is line 2
this is line III'
my @ans = split(/\n/, $msg);
foreach my $line ( @ans ) {
print "line: $line\n";
}
$ perl /tmp/test.pl
line: this is line one
line: this is line 2
line: this is line III
a
----------------------
Andy Bach
Systems Mangler
Internet: andy_b...@wiwb.uscourts.gov
Voice: (608) 261-5738, Cell: (608) 658-1890
We are what we pretend to be, so we must be careful about what we
pretend to be.
Kurt Vonnegut
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs