Perl – What’s the simplest way to return the first line of a multi-line string in Perl

multilineperlstring

When I say simple, I mean, within an expression, so that I can stick it in as a value in a hash without preparing it first. I'll post my solution but I'm looking for a better one that reminds me less of VB. 🙂

Best Solution

How about

( split /\n/, $s )[0]

?

You don't have to worry about \n being not cross-platform because Perl is clever enough to take care of that.