
BillKSmith
Veteran
Oct 11, 2017, 4:18 AM
Post #2 of 2
(1766 views)
|
Re: [regex2012] Reading a list of names into a variable - config file?
[In reply to]
|
Can't Post
|
|
Your requirement is not clear. I think you want a program that will tell you if the current host is one of the ones named in a file. The following code reads the possible names from the file named on the command line (defaults to an internal memory file). It then uses a module to test if the hostname matches any of those names. use strict; use warnings; use List::MoreUtils qw(any); my $input_file = $ARGV[0] // \do{ "milkbottle\n" ."beerbottle\n" ."milktoast\n" }; open my $FH, '<', $input_file or die "Cannot open input\n$!"; my @hosts = <$FH>; chomp @hosts; my $strHostname = qx{ hostname }; print( ( any {$strHostname eq $_} @hosts ) ? 'yes' : 'no' ); Good Luck, Bill
|