I am working with an XML file and I am trying to check whether a line contains a specified String in the entire document. Reading the file seems to work and splitting the String into an array was also successful. But my code doesn't print the lines that contain the specified string and I can't figure out what's wrong. I've tried three different ways to check whether the String is contained (see below). Thanks for helping!
use strict;
use locale;
my($daten1, $daten2, @datenarray1, @datenarray2, $datenarray1, $datenarray2, $i, $j, $l);
open (FHIN, '0a_nur_Text_nur_795.xml') || die "Die Datei 0a_nur_Text_nur_795.xml konnte nicht geoeffnet werden: $!";
while(<FHIN>) {
$daten1=$daten1.$_; #Daten als String einlesen
}
close (FHIN);
$daten1 = lc $daten1;
@datenarray1= split(/\n/,$daten1);
for($i=0; $i<@datenarray1; $i++)
{
#if( grep { $_ eq '795.25-M'} $datenarray1[$i])
#if($datenarray1[$i] =~m/795.25-M/)
if(index($datenarray1[$i], '795.25-M') != -1)
{
print $datenarray1[$i];
}
}
The file is an XML file.