Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: netswap.pl (style/coding comments)

by OeufMayo (Curate)
on Jun 04, 2001 at 02:16 UTC ( #85378=note: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    #!/usr/bin/perl -wi.bak
    use strict;
    
  2. or download this
    my %params;
    my $filename = shift || die "Usage: netswap.pl CONFILENAME\n";
    
  3. or download this
    open(FH,"$filename")
        or die "Could not open network configuration file: [$filename] for
    + reading: $!\n";
    
  4. or download this
    while(<FH>){
        # Skip the blank lines or the commented lines
    ...
        # avoid typing mistakes
        $params{$name} = lc($value);
    }
    
  5. or download this
    print <<"EOL";
    new hostname    = [$params{hostname}]
    ...
    new gateway     = [$params{gateway}]
    
    EOL
    
  6. or download this
    my $replacements = {
        '/etc/hosts' => {
    ...
        my $replacements = shift;
        foreach my $filename (keys %{$replacements}){
            print STDERR "Processing file [$filename]\n";
    
  7. or download this
            unless (-e $filename){
                print STDERR "  [$filename] cannot be found!\n";
                next;
            }
    
  8. or download this
            @ARGV=($filename); # put the filename where perl can find it.
            while(<>){ 
    ...
            print STDERR "  done\n";
        }
    }
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (17)
As of 2015-07-01 15:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (8 votes), past polls