#!/usr/bin/perl use strict; use warnings; chomp(my $HN = `hostname`); if (open(HOSTS, "</etc/hosts")) { while (<HOSTS>) { next if ! /^((?:\d{1,3}\.){3}\d{1,3})\s+($HN)\b/; print "$2: $1\n"; last; } close HOSTS; } else { die "Could not open /etc/hosts for reading: $!\n"; }
... might save a few minutes of head scratching for someone.
In reply to Re: Passing variables into regular expressions
by gloryhack
in thread Passing variables into regular expressions
by wanderer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |