Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Diff'ing dates

by ikegami (Patriarch)
on Oct 02, 2007 at 13:33 UTC ( [id://642100]=note: print w/replies, xml ) Need Help??


in reply to Diff'ing dates (solved)

perl -MTime::Local -lane"END{print$t[1]-$t[0]}$F[1]--;push@t,timelocal +@F[5,4,3,2,1,6]"

Update:

perl -MTime::Local -lane"END{print$t}$F[1]--;$t+=($.*2-3)*timelocal@F[ +5,4,3,2,1,6]"

Replies are listed 'Best First'.
Re^2: Diff'ing dates
by LighthouseJ (Sexton) on Oct 02, 2007 at 14:33 UTC
    Using your inspiring one-liner, I morphed my script with yours and came up with this:

    /bin/perl -MTime::Local -ne '{$t[1]-- && push(@epochs,timelocal(@t[5,4,3,2,1,6])) if (@t=split)} END { print $epochs[1] - $epochs[0]; }'

    The END block is most likely what will change because the value of the diff will be used to determine exit status.

    Thanks a lot for the fresh perspective, it was very helpful.

    "The three principal virtues of a programmer are Laziness, Impatience, and Hubris. See the Camel Book for why." -- `man perl`

      The exit code can be controled as follows:

      END { exit 1+($epochs[0] <=> $epochs[1]) }
      0: first time is earlier 1: both times are the same 2: second time is earlier
      perl -MTime::Local -lane'END{exit 1+($d<=>0)}$F[1]--;$d+=($.*2-3)*time +local@F[5,4,3,2,1,6]'
        Oh, I'm not interested in which is earlier, I know the second one will always be later (or the same) than the first. I'm more interested in the actual value of the difference but I can handle that easily enough.
        "The three principal virtues of a programmer are Laziness, Impatience, and Hubris. See the Camel Book for why." -- `man perl`
Re^2: Diff'ing dates
by LighthouseJ (Sexton) on Oct 02, 2007 at 14:19 UTC
    I tried the command and this is what I got:
    $ echo -e "Sun 09 30 06 42 36 2007\nTue 10 02 06 01 55 2007\n" | perl +-MTime::Local -lane"END{print$t}$F[1]--;$t+=($.*2-3)*timelocal@F[5,4, +3,2,1,6]" Can't modify single ref constructor in postdecrement (--) at -e line 1 +, near "]--" syntax error at -e line 1, near "+=" Execution of -e aborted due to compilation errors.
    "The three principal virtues of a programmer are Laziness, Impatience, and Hubris. See the Camel Book for why." -- `man perl`
      Use single quotes on UNIX-like operating systems:
      echo -e "Sun 09 30 06 42 36 2007\nTue 10 02 06 01 55 2007\n" | \ perl -MTime::Local -lane 'END{print$t}$F[1]--;$t+=($.*2-3)*timelocal@F +[5,4,3,2,1,6]'

      Double quotes cause your shell to interpret e.g. $t as a shell variable.

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      Use the appropriate quotes for your shell. Switch double quotes for single quotes.
        I figured you had written the one-liner with single quotes anyway. The small monospace text perlmonks use looked like single quotes because I knew I didn't want to interpolate any variables.
        "The three principal virtues of a programmer are Laziness, Impatience, and Hubris. See the Camel Book for why." -- `man perl`

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://642100]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2025-05-14 04:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.