无法使用perl成功提取段落

无法使用perl成功提取段落,perl,Perl,我试图使用PERL从文本中提取段落。但是,代码并没有生成我期望的结果。扎伊德在这篇文章中的回答让我受益匪浅。以下是我写的代码: my $string = <<'TEXT'; Assembly and Manufacturing The Company's assembly and manufacturing operations include PCB assembly and the manufacture of subsystems and complete

我试图使用PERL从文本中提取段落。但是,代码并没有生成我期望的结果。扎伊德在这篇文章中的回答让我受益匪浅。以下是我写的代码:

my $string = <<'TEXT';
     Assembly and Manufacturing

     The Company's assembly and manufacturing operations include PCB assembly
and the manufacture of subsystems and complete products. Its PCB assembly
activities primarily consist of the placement and attachment of electronic and
mechanical components on printed circuit boards using both SMT and traditional
pin-through-hole ("PTH") technology. The Company also assembles subsystems and
systems incorporating PCBs and complex electromechanical components, and,
increasingly, manufactures and packages final products for shipment directly to
the customer or its distribution channels. The Company employs just-in-time,
ship-to-stock and ship-to-line programs, continuous flow manufacturing, demand
flow processes and statistical process control. The Company has expanded the
number of production lines for finished product assembly, burn-in and test to
meet growing demand and increased customer requirements. In addition, the
Company has invested in FICO, a producer of injection molded plastic for Asia
electronics companies with facilities in Shenzhen, China.

     As OEMs seek to provide greater functionality in smaller products, they
increasingly require advanced manufacturing technologies and processes. Most of
the Company's PCB assembly involves the use of SMT, which is the leading
electronics assembly technique for more sophisticated products. SMT is a
computer-automated process which permits attachment of components directly on
both sides of a PCB. As a result, it allows higher integration of electronic
components, offering smaller size, lower cost and higher reliability than
traditional manufacturing processes. By allowing increasingly complex circuits
to be packaged with the components placed in closer proximity to each other, SMT
greatly enhances circuit processing speed, and therefore board and system
performance. The Company also provides traditional PTH electronics assembly
using PCBs and leaded components for lower cost products.;
TEXT

local $/ = "";
open my ($str_fh), '<', \$string;
while ( <$str_fh> ) {
     print "New Paragraph: $_\n","*" x 40, "\n" ;   
}
close $str_fh;
#
my$string=当我运行您在这里发布的代码时,它工作正常。它分别打印每个段落


最有可能的是,段落之间的行不是完全空白的。如果“空白”行上有空格,则它们不算作段落分隔符。

将$/更改为“\n\n”?两段之间用一个空行隔开。阅读
$/
手册。在perldoc perlvar中搜索输入\记录\分隔符您引用的文本不是来自您提供的链接。您能提供实际链接吗?@ngn999谢谢您的回复!我已更改为“\n\n”,但它仍然无法正常工作…它仍然返回整个文本。@ngn999我可以再问一个问题:即使当前的空行不算作段落分隔符,是否仍可以单独获取段落?非常感谢。谢谢你的回复!该文本是该公司年度报告的一部分(我发布的链接)。我认为很有可能“空白”行中有空格,因此我无法单独获取段落,可能不同的公司在编写这些文件时有不同的风格。我可以再问一个问题吗:即使“空白”中有空格,是否仍然可以单独获取段落?非常感谢。不使用
$/
。您必须迭代并使用正则表达式来代替它。@Sobrique谢谢您的回复!我会尽力做到的。但我仍然不知道文本使用了什么段落分隔符,有没有办法知道?谢谢致以最诚挚的问候。您链接到的文本文件与您发布的代码配合良好(只需将其更改为打开下载的文件而不是字符串)。如果你仍然有问题,发布更多细节。有很多方法,但在评论中回答有点太难了。