------------------------------------------------------- RDN[ 01 ] : checking my test = 1 RDN[ 1 ] : allowing data = 11030101 RDN[ 2 ] : retrieving data = 1 FOR CLASS main WITH NAME TYPE help = < 1 > Testnok = < [0] [1] [0] [[0]] [[1]] [[0]] > ; --------------------------------------------------------------And I'm interested in extracting the values between "Testnok = <" and ">;", exactly the following values:
[0] [1] [0] [[0]] [[1]] [[0]]I have done this in this way, but it's wrong:
open(IN, "< myfile.txt"); my @list =Thank you for your time; close IN; while ( $_ = shift ( @list ) ) { s/Testnok\s*=\s*<\s*//; s/\s*>//; s/\s*//; } #and it's not printing only my interested values
This will do it:
use Data::Dumper;
open(IN, "< myfile.txt") or die $!
my $data_ok = 0;
while() {
chomp;
m/^\s*>\s*$/ and last; # stop when encountering that last ">".
$data_ok and push @data, $_; # keep all data inbetween.
m/Testnok/ and $data_ok = 1; # start after "Testnok".
}
print Dumper \@data;
Cheers, Sören
open(FILE, ") { if(/Testnok/ .. /\>/) { print "$_"; } } close(FILE);
#!/usr/local/bin/perl -w
use strict;
my $data = do { local($/); <> };
print qq{$1\n} if ( $data =~ /(Testnok =[^>]+>)/s )
Or all right on the command line. Prob a cleaner way to do this though,
perl -e 'print $1 if ( do{local $/; <>} =~ /(Testnok =[^>]+>)/s)' data.txt
Wonko
perlmonks.org content © perlmonks.org and bory, davidj, Happy-the-monk, Wonko the sane
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03