English 中文(简体)
如何在找到一种模式后读行?
原标题:How to read line after finding a pattern?
  • 时间:2011-01-17 07:40:47
  •  标签:
  • perl

一线

CHANNEL(SYSTEM.DEF.SVRCONN) CHLTYPE(SVRCONN)
id=3

我想做的是,在我对档案进行搜索并找到第一条线之后,再找回这块id子。

open(CHECKFILE8, "$file");
while (<CHECKFILE8>) {             #while loop to loop through each line in the file
    chomp;                         #take out each line by line
    $datavalue = $_;               #store into var , $datavalue.
    $datavalue =~ s/^s+//;        #Remove multiple spaces and change to 1 space from the front
    $datavalue =~ s/s+$//;        #Remove multiple spaces and change to 1 space from the back
    $datavalue =~ s/[ 	]+/ /g;    #remove multiple "tabs" and replace with 1 space
    if ($datavalue eq "CHANNEL(SYSTEM.DEF.SVRCONN) CHLTYPE(SVRCONN)") {
        # HOW TO READ THE NEXT LINE?
    }
}
最佳回答

读其他所有内容的同样方式:用<代码>和>;CHECKFILE8>。 例如:

my $nextline = <CHECKFILE8>;

不过,你应当知道,通过一个光口识别码打开档案,有些是无政府状态。 允许Perl在具有灵活性的变数中编造档案材料,这在总体上是更安全的,更具有辅助性:

open my $checkfile8,  < , $file or die "Can t open $file: $!";
while (<$checkfile8>) { ... }

你们正在使用<条码>严格使用?

问题回答

暂无回答




相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签