Perl脚本-使用正则表达式的文件关闭 [英] Perl Script- File Chopdown With Regex

查看:130
本文介绍了Perl脚本-使用正则表达式的文件关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我有一个文本文件太大,无法逐行处理,但是我需要进行多行匹配.我正在尝试编写脚本以将所需的部分切掉(均为第1部分),这是到目前为止我所拥有的:

Hello all!

I have a text file that''s too large to be processed without doing it line by line, and yet I need to do multi-line matching. I''m trying to write a script to chop the parts out that I need (both Section 1''s) Here''s what I Have so far:

$insidesection = 0;
while (defined($line = <>))
{
    if($line =~ /Section.*?1/)
    {
        $insidesection = 1;
    }
    elsif($line =~ /Section.*?2)
    {
        $insidesection = 0;
    }
    if ($insidesection = 1)
    {
        print $line;
    }
}



提前谢谢!

仍然似乎不起作用.有人看到我要去哪里了吗?

-Grumbles22



Thanks in advance!

Still doesn''t seem to work. Anyone see where i''m going wrong?

-Grumbles22

推荐答案

insidesection = 0 ; 同时(已定义(
insidesection = 0; while (defined(


line =<>))) { 如果(
line = <>)) { if(


line =〜/Section.*?1 /) {
line =~ /Section.*?1/) {


这篇关于Perl脚本-使用正则表达式的文件关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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