[solved] using backticks to call bash from perl

Hi all,

Here is my code:

my $x = `bash -c \" ls -l filename | awk '{print \$5}'\"`;
print "$x\n";

This will run the first part of the bash script but not the awk command. It therefore gives output of:

-rw-r--r-- 1 root root 13619200 2012-04-25 08:16 filename

I am actually trying to just extract the filesize, which works correct when the bash command is run in isolation, meaning that perhaps I have a syntax error somewhere inside my backticks...?

Thanks in advance.

[mod]Link: [url="Forum Video Tutorial: How to Use Code Tags"]How to use [noparse]

 tags

---------- Post updated at 03:01 AM ---------- Previous update was at 02:25 AM ----------

Just to answer my own post as in retrospect, it was a really stupid question.

The answer is, don't use bash, use perl as it is more than capable of carrying out these small functions! 

I had previously written the script in bash and i'm in the process of converting the functionality to perl. I guess I got caught up in re-using my previous code from the bash script.

Anyway, I did this in perl instead:

$fileSize = -s "filename";
print "filesize: $fileSize\n"; 

It does the job.