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 6172341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:22:32+00:00 2026-05-23T23:22:32+00:00

I just write this script however the script only print one result not the

  • 0

I just write this script however the script only print one result not the results from all devices. I belive my error is on print section but I couldn’t figure out.

Note :- the host file has 30 devices list but the script print the result of the last device only.

#!/usr/bin/perl

$host_file  = "/usr/local/bin/test/host2";

open (PACKETLOSS,"$host_file") or die "Cannot Open Extracted host file";

# Put Extracted data into an array

@extracted_array=<PACKETLOSS>;

chomp(@extracted_array);

foreach(@extracted_array) {
    @words = split;
    $host = $words[0];
}

$extracted_array[$ping_idx] = `/usr/sbin/ping -s -t 10 $host 56 2 2>&1`; 

$ping_idx++;

($packet_loss) = ($ping =~ m/packets received, (\d+)% packet loss/);

($round_trip) = ($ping =~ m/round-trip.*\(ms\).*min\/avg\/max\/stddev = \d+\.\d+\/(\d+\.\d+)\/.*/);

print " $host $round_trip ms Average Latency and $packet_loss Packet loss\n"; 
  • 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-23T23:22:34+00:00Added an answer on May 23, 2026 at 11:22 pm

    Cause you are closing foreach and then performing the operation. IT should be

    foreach(@extracted_array) 
     {
       @words = split; 
      $host = $words[0]; 
      $extracted_array[$ping_idx] = `/usr/sbin/ping -s -t 10 $host 56 2 2>&1`; 
      $ping_idx++; 
     ($packet_loss) = ($ping =~ m/packets received, (\d+)% packet loss/);  
     ($round_trip) = ($ping =~ m/round-trip.*\(ms\).*min\/avg\/max\/stddev = \d+\.\d+\/(\d+\.\d+)\/.*/); 
      print " $host $round_trip ms Average Latency and $packet_loss Packet loss\n";  
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code does not seem to compile, I just need to write something to
I have just upgraded my server 2003 to serrver 2008. As I write this,
This is just a question on how to write my code for a COM
Maybe I am just over thinking this and need to write some more prototype
how can I write just a simple disassembler for linux from scratches? Are there
I just wrote this into my WebForms .aspx: <span id=GenerateChartButton runat=server></span> I went to
I just wrote a new web part and now I am getting this error
I wrote a program to solve a complicated problem. This program is just a
WiX is great in that there is no GUI, you just write the installer
Just wanted to write some recursion but can't check if the child is in

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.