6 Replies to “perl ‑e ‘print time() . “n“ ‘”

    1. -e is a switch that tells

       

      -e is a switch that tells perl to exe­cute the fol­low­ing com­mand rather than read­ing a file and exe­cut­ing that. print is the same as in oth­er lan­guages, time() is a func­tion that returns the num­ber of sec­onds since mid­night Jan 1, 1970 UTC, the peri­od is the con­cate­na­tion oper­a­tor, and n is code for a new­line char­ac­ter (which needs to be inside quotes so perl knows it’s part of a string. Since time() is a func­tion it will not be inter­pret­ed if inside quotes, which is why they need be concatenated.

      Feb­ru­ary 13th 2009 at 3:31:30 (PST) was, by Unix time, 1234567890. There were par­ties and everything.

       

    1. The val­ue returned by that

      The val­ue returned by that line can be used as input for a wide vari­ety of func­tions in most pro­gram­ming lan­guages. In Unix, the numer­ic val­ue can be fed to the date com­mand like so:

      date -jr 1267574003

      Which returns:

      Tue Mar  2 15:53:23 PST 2010

      Or it can be done all on one line like so:

      date -jr `perl -e 'print time() . "n"'`

Leave a Reply