Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

How to include a variable in output for derived subnets

by stroke (Acolyte)
on Jun 22, 2013 at 14:42 UTC ( #1040273=perlquestion: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    # Process a line and split out the data into variables
    my $function = sub {
    ...
            $comment );
        if ( is_ipv4($ipaddress) ) {
            store_subnet( $ipaddress, $prefix ) if $prefix;
    
  2. or download this
    # Produce IP subnets from the list of IPs
    sub store_subnet {
    ...
        $ip = Socket::inet_ntoa pack "N", $ipn;
        $subnets{"$ip,$len"} = { ipn => $ipn, maskn => $maskn };
    }
    
  3. or download this
    # Print it out
    print "subnet,prefix\n";
    print "$_\n"
      for sort { $subnets{$a}{ipn} <=> $subnets{$b}{ipn} }
      keys %subnets;
    
  4. or download this
    sub store_subnet {
        my ( $ip, $len, $comment ) = @_;
    ...
        $ip = Socket::inet_ntoa pack "N", $ipn;
        $subnets{"$ip,$len,$comment"} = { ipn => $ipn, maskn => $maskn, na
    +me => $comment };
    }
    
  5. or download this
    print "subnet,prefix,name\n";
    print "$_\n"
      for sort { $subnets{$a}{ipn} <=> $subnets{$b}{ipn} }
      keys %subnets;
     
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1040273]
Approved by Happy-the-monk
Front-paged by Corion
help
Chatterbox?
[Discipulus]: i'm not escaping correctly?
[moritz]: Discipulus] iirc bash doesn't let you escape ' with \
[moritz]: not inside a single-qouted string at least
[moritz]: echo 'a'\''

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2017-11-24 10:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (346 votes). Check out past polls.

    Notices?