I am writing a parser that will capture the value from text file. Apart from two values I am able to capture all values.
Can some one help me out to get those two values as well?
Here is my code:
use warnings;
open( my $fh, "<", "$tZPath\\Diag.txt" ) || print "can't open file filename : $!\n";
my ( $aBT_Slave, $iD, $hready, $address );
while ( defined( my $line = <$fh> ) ) {
if ( $line =~ /ID\:\s*(.+?\W+)/i ) {
$iD = $1;
print " Id -> $iD \n";
}
elsif ( $line =~ /HREADY\:\s*(.+?\W+)/i ) {
$hready = $1;
print " hready -> $hready \n";
}
elsif ( $line =~ /ADDR0\w\s*(.+?\W+)/i ) {
$address = $1;
print " address -> $address \n";
}
elsif ( $line =~ /PCNOC\_(.*?\d+)/i ) {
$aBT_Slave = "PCNOC_" . $1;
print " aBT_Slave -> $aBT_Slave \n";
}
}
Log file content:
ABT PCNOC_9 ID: 0x0000430c
ABT PCNOC_9 ADDR0: 0x000000e0
ABT PCNOC_9 ADDR1: 0x00000000
ABT PCNOC_9 HREADY: 0xfffffffd
ABT PCNOC_9 Slaves: 5
Fatal Error: AHB_TIMEOUT
Can anyone please help me out to get the ADDR0
value and PCNOC_9
from the log?
Please let me know if have kept unclear expiation here.
Please try this, It will make fetching fully dynamic.
while (defined(my $line = <$fh>)) {
if($line =~ /(PCNOC\_.*?\d+)\s*(\w+):\s*(.*)/i){
print "$1 ==> $2 ==> $3\n";
}
}
You can try this.
if($line =~ /ADDR1:\s*(.*)/i){
.....
}
elsif($line =~ /ADDR0:\s*(.*)/i){
.....
}
/ADDR0\w\s*(.+?\W+)/i
^^
This fails to match because :
is not a word char. Fix:
/ADDR0:\s*(.*)/
User contributions licensed under CC BY-SA 3.0