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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |