it is not so clear to me: perhaps you should post an example of the intended final datructure, but..
if you are trying to understand the .. part, in this case it is named flip-flop operator described among Range-Operators in the perlop
To help you understand it run the following code
use strict; use warnings; my $part = 0; while (<DATA>){ chomp $_; if ( $_ =~ /objet => debut$/ .. /objet => fin$/){ print "TRUE\n"; if ( /objet => debut$/ ){ next; # we skip the opening tag } elsif ( /objet => fin$/ ){ $part++; # we increment our index $part on closing tag } else{ print "\tPART $part: [$_]\n"; # here is the meat: do what +you need } } else{ print "FALSE for line: [$_]\n"; } } __DATA__ objet => debut index => 1 a => "premiere valeur" z => "dernier mot" objet => fin ALIEN LINE AFTER fin objet => debut index => 77 a => "autre valeur" z => "aurai-je le dernier mot ?" objet => fin
..and you will see how it works:
TRUE TRUE PART 0: [index => 1] TRUE PART 0: [a => "premiere valeur"] TRUE PART 0: [z => "dernier mot"] TRUE FALSE for line: [ALIEN LINE AFTER fin] TRUE TRUE PART 1: [index => 77] TRUE PART 1: [a => "autre valeur"] TRUE PART 1: [z => "aurai-je le dernier mot ?"] TRUE
L*
In reply to Re: parse a file TXT similar to XML -- flip-flop operator
by Discipulus
in thread RESOLVED - parse a file TXT similar to XML
by x-lours
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |