Reputation: 1328
How can I store value returned by -M $file
operator in Perl in a variable and later use in a mathematical expression? I have tried this on an existing file:
DB<1> $file="file.txt"
DB<2> $a=`-M $file`;
DB<3> print "$a"
But that does not seem to work.
Upvotes: 0
Views: 76
Reputation: 69264
You can take the value returned by a file test operator and store in a variable by... well... by taking the value and storing it in a variable.
my $mod_time = -M $some_file;
Then later you can treat $mod_time
as you would treat any scalar variable (because that's what it is).
Update: You've just updated your question to show what you've tried:
$ a= `-M $file`;
But -M $file
is not an external command, so you don't need the backticks.
Upvotes: 6