I tried to print my apache2 access log dates with the following one liner. Within single quotes it shows the value but within double quotes it shows as Array object. My command is as follows
sudo perl -ane 'print $F[3] . "\n" ' /var/log/apache2/access.log | head -n 10
[21/Jul/2014:09:16:05
[21/Jul/2014:09:16:05
[21/Jul/2014:11:32:55
[21/Jul/2014:11:32:55
[21/Jul/2014:11:32:59
[21/Jul/2014:11:33:02
[21/Jul/2014:11:33:02
[21/Jul/2014:11:33:10
[21/Jul/2014:11:33:14
[21/Jul/2014:11:33:14
sudo perl -ane "print $F[3] . \"\n\" " /var/log/apache2/access.log | head -n 10
ARRAY(0x195fca8)
ARRAY(0x1960128)
ARRAY(0x195fca8)
ARRAY(0x195fd38)
ARRAY(0x1960128)
ARRAY(0x195fca8)
ARRAY(0x195fd38)
ARRAY(0x1960128)
ARRAY(0x195fca8)
ARRAY(0x195fd38)
sudo perl -ane "print @{$F[3]} . \"\n\" " /var/log/apache2/access.log | head -n 10
1
1
1
1
1
1
1
1
1
1
When you're using double quotes $
gets interpolated by Bash and not by Perl. That's why this is happening.
Example:
a='foo bar'; perl -le "print \"$a\""
foo bar