in reply to Regular Expression

Well you can go for this, this change is required in your first line of code:
if($line =~ m/^Width(\s*)\=(\s*)(\d*)/)#to match width
Please go through Regular Expressions tutorials for a better understanding, these are very simple search techniques This is my program
$line = 'Width = 32 <uart0_rx_data : 16\'h0000> Descr - "This is Regis +ter1 comment" f_name bit_pos RESERVED 31:8 RXDATA 5:0 + </uart0_rx_data>'; if($line =~ m/^Width(\s*)\=(\s*)(\d*)/) # to match Width { print "something"; } elsif ($line =~ m/^Descr[\s]*-[\s]*[\w]+$/) # to match Descr { print "noone"; } else { printf "Garbage found: \"%s\" \n",$line; }
UPDATE:: So, WW I haven't said that this is the only way there are lots of way to do things in perl. Secondly, I didn't say that what you need to print the width value. Yes $3 will give the exact output, while you are completely wrong on the statement that it will not match ) after equal to. Check it and then say.

Replies are listed 'Best First'.
Re^2: Regular Expression
by ww (Archbishop) on Jun 27, 2012 at 14:15 UTC
    Capturing the zero-or-more-spaces surrounding the equals symbol is NOT helpful... and means OP, were your suggestion adopted, would have to use $3 for the value of width.

    Moreover, if there were zero-digits after the equals symbol, the data would not match OP's explicit example and implicit spec.

    Update re ckj's update which is MOSTLY WRONG. Reread the above.

    (\d+) captures one or more digits. (\d*) matches ZERO digits which is useless.

    perl -e "use 5.014; my $foo= 'bc'; if ($foo = /(\d*)/ ) {say 'match'; +}else{ say 'Duh!';}" match

    OP does not ask to capture the spaces. There is no need to capture the spaces to account for their quantity; 0, 1, 2 or whatever.
    Your parens are capturing. Grouping (aka 'non-capturing') parens are (?:...).

    Nothing was said about print.
    And "not helpful" ne "not match."

    Please read carefully before unburdening yourself of mis-statements.

    Despite it's irrelevance here, though, you did get one aspect of your reply partially right: "TIMTOWTDI." But -- as the rest of that wisdom goes - 'and most of them are wrong.'

    </Update>