Browsed by
Category: tech

How to check timestamp of a file using Perl

How to check timestamp of a file using Perl

You can use the built-in module File::stat (included as of Perl 5.004).

Say the file handle is $fh. Calling stat($fh) returns an array with the following information about the file handle passed in (from the perlfunc man page for stat):


  0 dev device number of filesystem
  1 ino inode number
  2 mode file mode (type and permissions)
  3 nlink number of (hard) links to the file
  4 uid numeric user ID of file's owner
  5 gid numeric group ID of file's owner
  6 rdev the device identifier (special files only)
  7 size total size of file, in bytes
  8 atime last access time since the epoch
  9 mtime last modify time since the epoch
  10 ctime inode change time (NOT creation time!) since the epoch
  11 blksize preferred block size for file system I/O
  12 blocks actual number of blocks allocated

The 9th element in this array will give you the last modified time since the epoch (00:00 January 1, 1970 GMT). From that you can compute the local time:

 my $epoch_timestamp = (stat($fh))[9];
 my $timestamp = localtime($epoch_timestamp);

If you use Time::localtime module, the code willl look better:

 use File::stat;
 use Time::localtime;
 my $timestamp = ctime(stat($fh)->mtime);


How to prepare for Programming Interviews . . .

How to prepare for Programming Interviews . . .

Mostly 3 things interviewers expect from a candidate

  1. Can you visualize a large system and build its components.
  2. Can you logically optimize the system or its modules.
  3. Can you implement your logic within small time.

Most companies will hire you if you do well in 1 and 2, but do average in 3.



If you are a C++ programmer, learn the language fundamentals and how to effectively use the standard template library.

Language Fundamentals:

Learn in detail about pointers, classes, structs and object oriented programming concepts. Know how to create nodes that will be crucial for most problems. You should be able to create and traverse a linked list in about 5 minutes. learn how to approach expanding the data structure considering the inheritance properties.

Data Structures:

Learn what the following are and how the related functions work. Understand and derive their time complexity.

  • stacks/queues/deques/lists
  • maps and sets (red-black Trees, AVL Trees)
  • unordered_maps and unordered_sets (hash tables)
  • vectors (dynamic arrays)
  • priority_queues
  • Iterators (how to use them with the above data structures)
  • Know how to represent a real world problem in the form of graphs.
  • Tries


The algorithm library is extremely important. Try to know all the functions, how they are internally implemented and their time/space complexity. They help save quite some of your interview time.

  • In memory sort
  • External sort
  • reverse a statement, string
  • Find nth_element
  • lower_bound,upper_bound
  • next_permutation/prev_permutation
  • rotate
  • optimize space usage
  • mathematical functions

How to use the above knowledge:

A typical interview is about 45 minutes. You have to write a complete program and answer few logical programming questions within that time. Interviewers look for the robustness of your implementation and your design capabilities. Most interviewees fail to implement their logic within the required time, even though they know the logical design.

  • Almost all the questions depend on your ability to use these data structures/algorithms directly, without implementing them – especially sort, vectors, maps.
  • You may often need a data structure like hash table or heap to achieve a appreciable time complexity.
  • First get the design in your mind and them start coding. Changing the design after coding half way is recipe for failure.
  • Ask the interviewer for hint, if you are out of ideas. Interviewers appreciate if you pick up the hints and solve the problem faster.