Venerated Monks,

I am trying to split a command output in an array and then print one specific line of it. Also trying to further split each line in words and count the occurances. For the second part of counting occurences, I will be referring the excellent node Count and List Items in a List. But before I do that, I need to break down the command as shown above. Kindly note that the "ping localhost" command is only being used as an example. I need to run some other commands and am using this only as an example. I wanted to give a sample output of those commands here, but to do that, I'd need to login to my office network and my remote connectivity to office VPN is disabled and will be resolved only by next 3-4 days. :(

I am getting an error message that states "Use of uninitialized value $eachlinecmd[4] in concatenation (.) or string at split.pl line 9." and "Use of uninitialized value $eachwordcmd[3] in concatenation (.) or string at split.pl line 10." Given below is my script

#!/usr/bin/perl use warnings; use strict; my @eachlinecmd = split ('/\n/,', `ping 127.0.0.1`); my @eachwordcmd = split ('/\w/,', @eachlinecmd); print "@eachlinecmd\n"; print "@eachwordcmd\n"; print "$eachlinecmd[4]\n"; print "$eachwordcmd[3]\n";

And here is the output

C:\Users\perl514\Documents\perl\practice>perl split.pl Pinging 127.0.0.1 with 32 bytes of data: Reply from 127.0.0.1: bytes=32 time<1ms TTL=64 Reply from 127.0.0.1: bytes=32 time<1ms TTL=64 Reply from 127.0.0.1: bytes=32 time<1ms TTL=64 Reply from 127.0.0.1: bytes=32 time<1ms TTL=64 Ping statistics for 127.0.0.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms 1 Use of uninitialized value $eachlinecmd[4] in concatenation (.) or str +ing at split.pl line 9. Use of uninitialized value $eachwordcmd[3] in concatenation (.) or str +ing at split.pl line 10.

Kindly help

Perlpetually Indebted To PerlMonks


In reply to Unable to extract elements from a split. Kindly Help. by perl514

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, 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.