CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Perl grammer help

 



samuel_1
New User

Feb 27, 2009, 8:29 PM

Post #1 of 5 (1640 views)
Perl grammer help Can't Post

have a input file has begin/end delimitters on separate lines
content in between,
want to capture any of data not in between begin/end patterns as well

the below code works ,but fails on input not in begin..end format

does this require a grammer definition of begin,content ,end ?

open(IN,"<iostat.txt");

while(<IN>){
if(/^BEGIN/ .. /^END/){
add content to hash
}
}

--
BEGIN
Time: 04:43:29 PM
avg-cpu: %user %nice %system %iowait %steal %idle
1.59 0.04 5.13 10.49 0.00 82.75

Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 26.60 280.10 333.81 29294213 34911878
END
BEGIN
Time: 04:43:30 PM
avg-cpu: %user %nice %system %iowait %steal %idle
9.00 0.00 88.00 3.00 0.00 0.00

Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
BEGIN
Time: 04:43:31 PM
avg-cpu: %user %nice %system %iowait %steal %idle
7.00 0.00 91.00 2.00 0.00 0.00

Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 91.00 56.00 1912.00 56 1912
END


FishMonger
Veteran / Moderator

Feb 28, 2009, 7:26 AM

Post #2 of 5 (1633 views)
Re: [samuel_1] Perl grammer help [In reply to] Can't Post

I'm not sure what you're wanting, but maybe this.


Code
while(<IN>){ 
if(/^BEGIN/ .. /^END/){
add content to hash
}
else {
do something else
}
}



samuel_1
New User

Mar 1, 2009, 12:23 AM

Post #3 of 5 (1626 views)
Re: [FishMonger] Perl grammer help [In reply to] Can't Post

I was looking for how to validate input data

only look into if there is BEGIN and END blocks.
this should be possible with Parse::RecDescent ?
Data::Domain ?

should know that second block is missing the required data sets and does not have END
=============================
BEGIN
begindata1set
data1 data2 data3
datax datay dataz
enddata1set
begindata2set
data1 data2 data3
datax datay dataz
enddata2set
END
BEGIN
begindata1set
data1 data2 data3
BEGIN
begindata1set
data1 data2 data3
datax datay dataz
enddata1set
begindata2set
data1 data2 data3
datax datay dataz
enddata2set
END

thanks for help

In Reply To



(This post was edited by samuel_1 on Mar 1, 2009, 12:32 AM)


FishMonger
Veteran / Moderator

Mar 1, 2009, 7:17 AM

Post #4 of 5 (1620 views)
Re: [samuel_1] Perl grammer help [In reply to] Can't Post


Code
use strict; 
use warnings;
use Data::Dumper;

my @records = do {$/ = "BEGIN\n"; <DATA>};
shift @records;
print scalar @records, " records\n\n";
print Dumper \@records;


__DATA__
BEGIN
begindata1set
data1 data2 data3
datax datay dataz
enddata1set
begindata2set
data1 data2 data3
datax datay dataz
enddata2set
END
BEGIN
begindata1set
data1 data2 data3
BEGIN
begindata1set
data1 data2 data3
datax datay dataz
enddata1set
begindata2set
data1 data2 data3
datax datay dataz
enddata2set
END



FishMonger
Veteran / Moderator

Mar 1, 2009, 7:43 AM

Post #5 of 5 (1617 views)
Re: [samuel_1] Perl grammer help [In reply to] Can't Post

I may have missread your requirements.

Try this:

Code
use strict; 
use warnings;
use Data::Dumper;

$/ = "BEGIN\n";

my @records;
while ( <DATA> ) {
chomp;
push @records, $_ if $_ =~ /END$/;
}
print scalar @records, " records\n\n";
print Dumper \@records;


__DATA__
BEGIN
begindata1set
data1 data2 data3
datax datay dataz
enddata1set
begindata2set
data1 data2 data3
datax datay dataz
enddata2set
END
BEGIN
begindata1set
data1 data2 data3
BEGIN
begindata1set
data1 data2 data3
datax datay dataz
enddata1set
begindata2set
data1 data2 data3
datax datay dataz
enddata2set
END


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives