Jump to content

Most efficient way?


notta
 Share

Recommended Posts

I'm creating a script that will scan our network, but there's a part that I'm wondering if there is a more efficient way of doing. I'm scanning a list of computers for their IP and then parsing the subnet. After I have the subnet I want to output the building number depending upon the value. Example:

if $subnet = 111 Then FileWriteLine($output, "Building 4000 Floor 1")
         if $subnet = 112 Then FileWriteLine($output, "Building 4000 Floor 2") 
         if $subnet = 113 Then FileWriteLine($output, "Building 4000 Floor 3")

and so on. Is this the most efficient way of doing this? We have a large amount of buildings, so this could take some time to create :) Thanks guys.

Edited by notta
Link to comment
Share on other sites

Maybe a Switch would work better.

Switch $subnet

Case 111

FileWriteLine($output, "Building 4000 Floor 1")

Case 112

FileWriteLine($output, "Building 4000 Floor 2")

Case 113

FileWriteLine($output, "Building 4000 Floor 3")

EndSwitch

Link to comment
Share on other sites

Yea I was thinking about that. I would be able to break out instead of checking 100 more if statements. Thanks.

After reading the switch docs I found a switch is automatically exited when a case is matched. I thought you had to break out.

Link to comment
Share on other sites

After reading the switch docs I found a switch is automatically exited when a case is matched. I thought you had to break out.

Other languages (C++, PHP) support cascading Case statements and thusly require you to Break if you don't want to cascade through every case.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...