Perl:阅读网络文本文件和“打开”它 [英] Perl: Read web text file and "open" it

查看:221
本文介绍了Perl:阅读网络文本文件和“打开”它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个脚本来读取文本文件,然后分析它们,不管文本文件是在线还是离线。



离线部分内要信息亦读亦范范段当读范辛中内的数范范信范亦亦作亦信范上亦信信讯范信范范信信范亦中范信辛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屋!

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