在Perl中返回多行字符串的第一行的最简单方法是什么? [英] What's the simplest way to return the first line of a multi-line string in Perl?

查看:58
本文介绍了在Perl中返回多行字符串的第一行的最简单方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我说简单时,我的意思是在表达式中,这样我就可以将其作为哈希值保留在其中,而无需先准备它.我将发布解决方案,但我正在寻找一种更好的解决方案,使我不怎么想起VB. :)

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. :)

推荐答案

如何

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

?

您不必担心\ n不是跨平台的,因为

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

这篇关于在Perl中返回多行字符串的第一行的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆