I have simple code that is trying to print same thing twice. First I try to print via a scalar and then I try to print samething using an array. The output of two print statements is different. Could you please help me understand the reason(s) for this difference in behaviour?
my $dest = shift;
my $cmd = "ping -c 1 $dest";
@output = `$cmd`;
Upon executing the above code, test.pl 22.214.171.124, the output is:
ping -c 1 126.96.36.199
PING 188.8.131.52 (184.108.40.206) 56(84) bytes of data.
64 bytes from 220.127.116.11: icmp_seq=1 ttl=42 time=187 ms
--- 18.104.22.168 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 187ms
rtt min/avg/max/mdev = 187.409/187.409/187.409/0.000 ms
I understand that while using scalar it prints just the command. But while using array it executes the command and prints the output of the command. Could you please help me understand the reasoning for this differnce in behaviour?