http://www.perlmonks.org?node_id=945016


in reply to Unable to extract elements from a split. Kindly Help.

Since you do not say what is the expected result, my answer is guessing you want the element 3 from line 4.

Try this:

#!/usr/bin/perl use warnings; use strict; my @eachlinecmd = `ping 127.0.0.1`; my @eachwordcmd = split (/ /, $eachlinecmd[4]); print "@eachlinecmd\n"; print "@eachwordcmd\n"; print "$eachlinecmd[4]\n"; print "$eachwordcmd[3]\n";
perl "F:\perl_TK\perl1ping.pl" Process started >>> Pinging 127.0.0.1 with 32 bytes of data: Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 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 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 bytes=32 <<< Process finished. ================ READY ================