Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: netswap.pl (style/coding comments)

by OeufMayo (Curate)
on Jun 04, 2001 at 02:16 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://85378]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (1)
As of 2024-04-19 18:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found