in reply to Read text in file and assign to variable
Just capture the match! You can get rid if the zero-width assertion at the same time:
my $file = '/etc/redhat-release'; # content of /etc/redhat-release # CentOS Linux release 7.6.1810 (Core) open(SOURCE, '<', $file); my ($version) = <SOURCE> =~ m/release (\d)/; close SOURCE; print "The version is: $version\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Read text in file and assign to variable
by maxamillionk (Acolyte) on Jan 24, 2024 at 00:31 UTC | |
by Athanasius (Archbishop) on Jan 24, 2024 at 07:58 UTC | |
by maxamillionk (Acolyte) on Jan 25, 2024 at 00:04 UTC | |
by kcott (Archbishop) on Jan 24, 2024 at 15:36 UTC |