Perl:阅读网络文本文件和“打开”它 [英] Perl: Read web text file and "open" it
问题描述
离线部分内要信息亦读亦范范段当读范辛中内的数范范信范亦亦作亦信范上亦信信讯范信范范信信范亦中范信辛H2,13,13亦用信息信息信息信息信辛亦作内叙
sub analysis_file {
while(< FILENAME>){analyze analysis}
}
$信息信itch的信息信范范内的信息信息信息中信息的信息亦读信息信范信辛信读为信息亦亦亦范范信息信息信息中亦范信范亦亦信中预期信读信信信息信息信范亦亦亦范范读挥信范亦亦信范范范预章范亦范范范范范范范范范范范范范范范范预章范信息信息亦数信息范范信息中内的数范信范信息中信息内预读亦亦读信息信息内信息信息信息信息信息信息信息信息信息中信息中亦亦信息中信息)
}
elsif($ online){
##以某种方式打开http web文本,以便稍后可以执行一段时间(< FILENAME>)
}
analyze_file();
sub analysis_file {
while(< FILENAME>){analyze analysis}
}
有get('http://weblink.com/textfile.txt;),但它创建一个字符串。
有人知道如何做到这一点吗?
很简单,只需使用 打开
。
使用LWP :: Simple;
if($ offline){
open(FILENAME,'<','anyfilename.txt')
}
elsif($ online){
my $ text = get'http://example.com';
open(FILENAME,'<',\ $ text);
}
I'm trying to create a script that will read text files and then analyse them, regardless of whether the text file is online or offline.
The offline part is done, using
open(FILENAME, "anyfilename.txt")
analyze_file();
sub analyze_file {
while (<FILENAME>) {analyze analyze}
}
Now for the online part, is there anyway to read a text file on a website and then "open" it?
What I hope to achieve is this:
if ($offline) {
open(FILENAME, "anyfilename.txt")
}
elsif ($online) {
##somehow open the http web text so that I can do a while (<FILENAME>) later
}
analyze_file();
sub analyze_file {
while (<FILENAME>) {analyze analyze}
}
There's the "get('http://weblink.com/textfile.txt;)" but it creates a string. I can't do a while () with that string.
Does anyone know how this can be done?
It's simple, just use the open FILEHANDLE,MODE,REFERENCE
style of open
.
use LWP::Simple;
if ($offline) {
open( FILENAME, '<', "anyfilename.txt" )
}
elsif ($online) {
my $text = get 'http://example.com';
open( FILENAME, '<', \$text );
}
这篇关于Perl:阅读网络文本文件和“打开”它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!