如何将字符串转换为perl中的文件句柄?

wuc*_*ang 4 string perl filehandle

我有一个非常大的字符串$s="dfasdfasdfafd....",有近1,000,000个字符.我想将其转换为文件句柄,使其看起来像从文件中读取此字符串.但我不想将它存储到临时文件中并阅读它.

谁能给我一些建议?

amo*_*mon 18

打开对字符串的引用:

use strict; use warnings; use autodie;

my $foo = "abc\ndef\n";
open my $fh, "<", \$foo;

while (<$fh>) {
  print "line $.: $_";
}
Run Code Online (Sandbox Code Playgroud)

输出:

line 1: abc
line 2: def
Run Code Online (Sandbox Code Playgroud)