Extract double quoted string from string in file

I have a file with content like:

Component (0463) "commonfiles"
Component (0464) "demo_new_comp"
Component (0467) "test_comp" (removed)
Component (0469) "test_comp3" (removed)
Component (0465) "textfiles1

You need to extract the string in double quotes from each string that has (deleted) and put in an array. My code is:

my $fh = new IO::File;
$fh->open("<comp.log") or die "Cannot open comp.log";
my @comp_items;
while (<$fh>) {
    if ( $_ =~ /removed/ ) {;
        my $compName = $_ = ~ m/"(.*?)"/;
        print " Componnet Name : \"$compName\"\n";
    }
}

I am not getting the correct output giving some numbers:

"18446744073709551614"
"18446744073709551614"

The conclusion should be:

test_comp
test_comp3
+4
source share
1 answer
my $compName = $_ = ~ m/"(.*?)"/;

= ~does not match =~, but assignment and bitwise negation

and what do you want

my ($compName) = $_ =~ m/"(.*?)"/;

or simply,

my ($compName) = /"(.*?)"/;
+7
source

All Articles