And the clouds parted, and deb said... > > ## begin ## > > while ($name = <DATA>) { > $name =~ /(\w*)\.*/; > $name{$1}++; > $name =~ /(\w+)/; > print "$& \n"; > } > > > __DATA__ > tibor.test.net > mars.test.net > moon-bx-r.test.net > moon-bs-d.test.net > moon-bt-321.test.net > > ## end ## > > This works for hostnames without hyphens, but when there is a hyphen in the > name, everything after the hyphen is ignored. I've been trying things like > $name =~ /[a-z]*\-*\-*/ with no luck. The data coming into the expression > may or may not be fully qualified, so I can't just take everything to the left > of .test.net, and the domain name may be different at times, anyway. > > So what I'm left with finding an expression that will match any alphanumeric, > with 0 or more embedded dashes. It sounds simple, but I can't seem to find > it. > > What am I missing?
Two things: 1) The regex you're looking for is likely /[-\w]+/, which says "match one or more dashes or word characters". This will slurp up everything up to the first non-word, non-dash character. 2) You can probably simplify your script to ## begin ## while (<DATA>) { (print "$& \n" and $name{$&}++) if /[-\w+]+/; } __DATA__ tibor.test.net mars.test.net moon-bx-r.test.net moon-bs-d.test.net moon-bt-321.test.net ## end ## Its output is : ksh$ ./mchname tibor mars moon-bx-r moon-bs-d moon-bt-321 ksh$ HTH- Brian /~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\ | Brian Gerard A child of five could understand | | First initial + 'lists' this! Fetch me a child of five. | | at technobrat dot com | \______________________________________________________________________/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]