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, this is a homework assignment, and I am very new to programming in
Firstly I am very new to all forms of javascript, particularly anything remotely AJAX.
Firstly apologies if this a very basic question, I'm just curious to know the
Firstly appologies for the poor title, not sure how to explain this in one
Firstly, I am new to jQuery, coming from a Java background, so apologies if
Firstly: apologies if this is a duplicate post. Things got a bit confusing as
Firstly apologises for the length of code but I wanted to show it all.
Firstly, I wrote my customized setter for an NSString* like this: - (void)setDateString:(NSString *)newDateString
Firstly, I apologise if this is a dupe - I suspect it may be
Firstly I realise that this is a familiar question, it seems to pop up

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.