I have the file with content as :
Component (0463) "commonfiles"
Component (0464) "demo_new_comp"
Component (0467) "test_comp" (removed)
Component (0469) "test_comp3" (removed)
Component (0465) "textfiles1
Need to extract string within double quotes from each line having (removed) and place in a 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 as:
"18446744073709551614"
"18446744073709551614"
Output should be :
test_comp
test_comp3
my $compName = $_ = ~ m/"(.*?)"/;
= ~
is not same as =~
but assignment and bitwise negation
and what you want is,
my ($compName) = $_ =~ m/"(.*?)"/;
or just,
my ($compName) = /"(.*?)"/;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With