Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: looking for aliases(5)-style entries in a text file

by athomason (Curate)
on Aug 17, 2000 at 08:42 UTC ( [id://28265]=note: print w/replies, xml ) Need Help??


in reply to looking for aliases(5)-style entries in a text file

Looks to me like your routine is reinventing the wheel. Take a look at grep, which handles regexen explicitly. Here's my go at a solution, though I'm not sure of the rules concerning valid alias names, so twiddle with those as appropriate. I'm also making even less of an attempt at verifying the destination address than BlueLines, because that's an entirely different problem. Also remember that things like /dev/null are valid targets.
#!/usr/bin/perl -w use strict; my @valid = grep { !/^[\w-]+:\s*\S+$/ } <>; # do some stuff with @valid
If the entire functionality of your program is to strip out the irrelevant lines, this is easier (fore! ;-).

perl -ne '/^[\w-]+:\s*\S+$/ and print' < /etc/aliases

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://28265]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-25 09:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found