Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl Strange -M Flag in 'If' statement

Tags:

perl

What is this flag?

if (-M ..filepath..)

what is the '-M' flag?

like image 215
Paul Avatar asked Aug 02 '10 22:08

Paul


People also ask

What is an IF statement in Perl?

In Perl, if statements are the conditional statements that work on either or statements, i.e. it executes the program or task based on the condition that can be true or false.

Is everything else is true in Perl?

Everything else is true. If you do not remember the rules or you doubt whether a condition is true or false, you can always write a simple if statement to test if the expression. The limitation of the Perl if statement is that it allows you to execute a single statement only.

How to test if an expression is true or false Perl?

If you do not remember the rules or you doubt whether a condition is true or false, you can always write a simple if statement to test if the expression. The limitation of the Perl if statement is that it allows you to execute a single statement only. If you want to execute multiple statements based on a condition, you use the following form:

How to execute multiple statements based on condition in Perl?

The limitation of the Perl if statement is that it allows you to execute a single statement only. If you want to execute multiple statements based on a condition, you use the following form: if (expression) { statement; statement; ... } Noticed that the curly braces {} are required even if you have a single statement to execute.


3 Answers

perldoc -f -M will answer your question...

This is the modification "age" of the file, in fractional days. That is, it is the number of days since the file was modified, as of the script start time (or as of some other time, if you explicitly set the $^T variable).

I sure hope that the actual code is along the lines of -M filepath > ...; just testing -M's result for truth is pointless.

like image 165
ysth Avatar answered Sep 23 '22 09:09

ysth


Script start time minus file modification time (aka file modification age), in days.

In other words, it returns the age of OPERAND in days when the program started.

Also see a full list of file test operators in perldoc perlfunc (-X section)

like image 34
DVK Avatar answered Sep 23 '22 09:09

DVK


Modification age (measured in days)

from http://www.devshed.com/c/a/Perl/File-Tests-in-Perl/

if we have something like this:

$age = -M FILE;

$age will contain the days since the file was modified.

like image 26
KLee1 Avatar answered Sep 23 '22 09:09

KLee1