Brian Gerard wrote:
>
> 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+]+/;
> }

That's a misuse of 'and' Brian. It says that the hash element
should be incremented only if the print succeeds, which isn't
what was intended. If you mean a code block then use a code
block.

Cheers,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to