I know how to open a file and display entire content using perl script, but how can i read a string from file into a variable
Following is to open file and display entire content
#!/usr/bin/perl
use strict;
use warnings;
my $filename = '/home/abc/data.txt';
if (open(my $fh, '<', $filename)) {
while (my $row = <$fh>) {
chomp $row;
print "$row\n";
}
} else {
warn "Could not open file '$filename' $!";
}
My requirement is
#!/usr/bin/perl
use strict;
use warnings;
my $filename = '/home/abc/data.txt';
my $foo = ""
if (open(my $fh, '<', $filename)) {
---- Read test_reg_ip string from data.txt into variable
$foo=test_reg_ip;
} else {
warn "Could not open file '$filename' $!";
}
print "$foo\n";
Following is the input file data.txt
#############################################################################################
# mon_server_ip
# This parameter value should point to the IP address where the mon Server
# is installed
#############################################################################################
mon_server_ip = 127.0.0.1
#############################################################################################
# test_reg_ip
# This parameter value should point to the IP address where reg server is
# installed
#############################################################################################
test_reg_ip = 127.0.0.1
#############################################################################################
# mon_port
# This parameter value should point to the mon port
#############################################################################################