in reply to Help with logic/syntax
I had no problems with using /^/ for the beginning of a line - maybe because I processed the records line by line.
#!/usr/bin/perl use warnings; use strict; $/ = "#"; while (<DATA>) { next if $. == 1; # Skipt the empty "first" record; my @lines = split /\n/; my ($vlan, $ifconfig) = (0, 0); for (@lines) { if (/^hostname/) { print "$_\n"; } elsif (/^vlan/) { $vlan++ for m/\S+/g; $vlan -= 3; } elsif (/^ifconfig/) { $ifconfig++ for m/\S+/g; $ifconfig -= 3; } } print "vlan $vlan\nifconfig $ifconfig\n"; print "WRONG!!!\n" if $vlan != $ifconfig; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Help with logic/syntax
by randompug (Initiate) on Jul 25, 2013 at 17:23 UTC |