Я знаю, как открыть файл и отобразить все содержимое с помощью PERL скрипт, но как я могу прочитать строку из файла в переменнуюPerl скрипт, чтобы открыть файл и прочитать строку
Ниже открыть файл и отобразить все содержимое
#!/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' $!";
}
Мое требование
#!/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";
Ниже входной файл 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
#############################################################################################