Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Wow, thanks everybody, what a response..!!

kejohm,
In terms of updating to Perl 5.10 and using the Smart Match Operator. I did look into that but updating the Perl version wasn't really an option at the moment bc it is a production server and a bunch of things running depend on that. But I did want to try to use that at some point...


ww,
Thanks for the reply, The example you show is sort of what I was trying to achieve with the ranges, maybe I'll give that one a try as well. Thanks again!


LanX,
Oh ok I gotcha... Bc it was working just not in the way I thought it would...? Thanks for the info.


NetWallah,
Hey, that looks cool I'll have to look into that Module as well. Seems alot like the Acme::Tools Module that I eventually went with from toolic's suggestion... Thanks I'll have to download that Module.


TJPride,
That's a good one..! I like that! Don't know why I didn't think of that. Clean and simple, since the control structure, once it finds a match, it will drop out of the if/elsif clause which leads to not having to use a range to test on, but just one test instead... Cool thanks..!


GrandFather,
Hey thanks for the reply. Sorry it took me a while to respond back but I decided to go with toolic's suggestion with the ACME::Tools solution... Works Good!
But in terms of a backstory. The thing I need this for is a script to run along side with MRTG and Interafce Templates to check which GigabitEthernet port it is and then separate them into groups to test for Backplane usage on a Cisco switch. Backplane is Bundeled ports (usually 8 consecutive one's) ranging from (Gi3/1<-->Gi3/48; Gi4/1<-->Gi4/48; ... all the way to ... Gi7/1<-->Gi7/48).

So basically some of the groups would be in ranges as follows... For example the range Gi3/1..Gi3/8 would be "Bundle-Gi3A", and Gi3/9..Gi3/16 would be "Bundle-Gi3B" all the way up to Bundle-Gi3F. As for Gi4 -to- Gi7 it would be the same Letters only difference would be the Gi number...


Here is my entire solution to the original question:
The original question had to do with the Subroutine "get_bundle()"
I know it's a SIMPLE program but here it is. Basically you just pass it the interface name (i.e. "Gi3/7") broken into two pieces, (1) the Gi number "Gi3" and (2) the reference number "7", which is passed from an MRTG Template/Script and then passed back to the Template to be added to the config ("cfg") file.

#!/usr/bin/perl use warnings; use strict; use Getopt::Long; use Acme::Tools qw(between); # Declare Command Line Option's Variables my $Gi_number; my $ref_number; my $get_what; # Declare regular variables my $bundle; my $target_lines; #my $target_name = "target_name"; my @number; my $GInum; my $userGraph; # Process Command-Line Options with the GetOptions::Long Module if ( @ARGV > 0 ) { GetOptions('Gi_number=s' => \$Gi_number, 'ref_number=s' => \$ref_number); } ### Extract the 'Gi' Number (i.e. Gi4 --> '4') and set it to $GInum @number = ($Gi_number =~ /(\d)/); $GInum = $number[0]; &get_bundle(); ### Build the the UserDefined Graph Name for the routers.cgi*Graph[] L +ine $userGraph = "Bundle-$Gi_number$bundle"; if ($bundle) { $target_lines .= "routers.cgi*Graph[\$target_name]: $userGraph tot +al average active\n"; } else { print "WARNING: No Bundle Letter has been assigned to \$bundle +... Try again.\n"; exit 2; } ###################################################################### +############## # SUB - get_bundle() --- This sub will take the interface reference nu +mber Gi3/"7" # # which is the '7' and get the corresponding Bundle letter +s.# ###################################################################### +############## sub get_bundle() { if (between($ref_number, 1, 8)) { $bundle = "A"; } if (between($ref_number, 9, 16)) { $bundle = "B"; } if (between($ref_number, 17, 24)) { $bundle = "C"; } if (between($ref_number, 25, 32)) { $bundle = "D"; } if (between($ref_number, 33, 40)) { $bundle = "E"; } if (between($ref_number, 41, 48)) { $bundle = "F"; } } ###################################################################### +########### ### END: get_bundle() print "$target_lines";

I'm SURE there is a 100 different ways to do this, but this works for my current situation...

I REALLLY want to thank all of you for your suggestions, it was MUCH MUCH more then I expected..!!

Thanks Again Everybody,
Matt



In reply to Re: Range Operator in If Statement by mmartin
in thread Range Operator in If Statement by mmartin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (8)
    As of 2015-07-29 07:37 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 (260 votes), past polls