Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6041903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:43:44+00:00 2026-05-23T06:43:44+00:00

Firstly, appologies if i get any terminology wrong on the upcoming post, this is

  • 0

Firstly, appologies if i get any terminology wrong on the upcoming post, this is all still very new to me.

Some background, I have a script that checks our archived network configs for a specific set of settings. As such, the script runs a number of checks, and adds the results to an array for that check.

e.g
a check to make sure syslog is configured is added to an array called @internalsyslogerror

after all the checks have run, the arrays for all the checks are added to a hash, with the key being the device name.

note all code has use strict, use warnings

with the following command;

$results{$configs} = [@internalsyslogerror, @bordersyslogerror, 
@borderntperror, @borderntperror, @internalntperror, 
@bordertacacserror, @internaltacacserror, @enablepasswordchecks,
@internalsnmpkeyserror, @timezoneerror, @configregistererror, 
@bannererror, @bootregistererror, @domainnameerror];

The issue im having is what is the most elegant way of extracting this information, i would like to reduce the amount of changes I have to make in order add a new check to the script.
Currently i would have to add the additional array to the above code and then add the dereferencing part to the sub that handles that.

Here is currently what i do to de-reference and out put to an array which i then send via an email.

foreach my $k (keys %results) {
    push @results, "<b>$k</b><br>";
    if (defined $results{$k}[0] ){
    push @results, "$results{$k}[0]";
    }
    if (defined $results{$k}[1] ){
    push @results, "$results{$k}[1]";
    }
    if (defined $results{$k}[2] ){
    push @results, "$results{$k}[2]";
    }
    if (defined $results{$k}[3] ){  
    push @results, "$results{$k}[3]";
    }
    if (defined $results{$k}[4] ){
    push @results, "$results{$k}[4]";
    }
    if (defined $results{$k}[5] ){
    push @results, "$results{$k}[5]";
    }
    if (defined $results{$k}[6] ){
    push @results, "$results{$k}[6]";
    }
    if (defined $results{$k}[7] ){
    push @results, "$results{$k}[7]";
    }
    if (defined $results{$k}[8] ){
    push @results, "$results{$k}[8]";
    }
    if (defined $results{$k}[9] ){
    push @results, "$results{$k}[9]";
    }
    if (defined $results{$k}[10] ){
    push @results, "$results{$k}[10]";
    }
    if (defined $results{$k}[11] ){
    push @results, "$results{$k}[11]";
    }
    if (defined $results{$k}[12] ){
    push @results, "$results{$k}[12]";
    }
    if (defined $results{$k}[13] ){
    push @results, "$results{$k}[13]";
    }
}

The question is, can i do what im doing above, but somehow generate the code “on the fly”

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:43:45+00:00Added an answer on May 23, 2026 at 6:43 am

    I haven’t seen enough of your code to be certain that this snippet doesn’t alter existing behavior. But it should be ok. And it definitely improves maintainability:

    foreach my $k (keys %results) {
        push @results, "<b>$k</b><br>";
        foreach my $index ( 0..$#{$results{$k}} ) {
            if (defined $results{$k}[$index] ){
                push @results, "$results{$k}[$index]";
            }
        }
    }
    

    The above replaces your entire foreach / if construct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly, there have some tag links in my main page. click each one, post
I have a WPF sorting/binding issue. (Disclaimer: I am very new to WPF and
(Firstly, as a disclaimer, this is related to an assignment. I'm not asking anyone
Firstly, apologies for the vague title, but I'm not sure exactly what I'm asking
Firstly, bear with me here. I have a custom model binder which is successfully
Firstly apologies for the title, I don't know if it describes what I am
Firstly, apologies for the bad question title - not entirely sure if I am
Firstly, I'm a newbie to C# and SharePoint, (less than a month's experience) so
I have a modeling question related to profiles. Firstly, I have looked into using
Firstly, let me set out what I'd like to do. Assume I have three

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.