Hi,
I am trying to read a file containing the following strings: "Width = 32" and "Descr - This is Register1 comment"
and extract the Width = 32 from file, but my code fails to match.
File contains:
Width = 32 <uart0_rx_data : 16'h0000> Descr - "This is Register1 comment" # f_name bit_pos RESERVED 31:8 RXDATA 5:0 </uart0_rx_data>
Code snippet:
if($line =~ m/^Width[\s]*\=[\s]*\d+$/) # to match Width { update_curs ($line); } elsif ($line =~ m/^Descr[\s]*-[\s]*[\w]+$/) # to match Descr { update_curs ($line); } else { printf "Garbage found: \"%s\" \n",$line; }
Output: Garbage found: "Width = 32"
Kindly help.
UPDATE: Thanks. I have removed extra spaces and new line character in my code. When I run the code individually it works, but when integrated with main package it doesn't work. As tobyink mentioned "Descr" is not matched.
sub validate_save_regs { my $line = $_; chomp $line; if($line =~ m/^Width[\s]*\=[\s]*\d+$/){ $reg_width_found = 1; update_curs ($line); } elsif ($line =~ m/^Descr[\s]*-[\s]*[\w]+$/) { printf "inside elsif, line is %s\n",$line; if(!$reg_offset_found) { printf "Garbage found at: %d \n", $line_no; exit(0); } $name_found = 1; update_curs ($line); } else { printf "Garbage found %s\n", $line; } }
In this integrated code "Descr - This is Register1 comment" doesn't match and goes to Garbage rule.
In reply to Regular Expression by pramod
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |