in reply to Re: one liner diff between HH military times
in thread one liner diff between HH military times

Thanks for the suggestion, but if my inputs are 22 and 02 (so 10PM and 2AM) the one-liner returns 1 and I would expect 4.

perl -e 'print( ($ARGV[1] - $ARGV[0] + 4) % 24 <= 8, "\n")' 22,02

am i using the one-liner incorrectly?

Replies are listed 'Best First'.
Re^3: one liner diff between HH military times
by Cristoforo (Curate) on Dec 16, 2013 at 21:49 UTC
    The comma must be replaced by a space to feed @ARGV. Running the command as you did (with warnings produced this.

    C:\Old_Data\perlp>perl -we "print( ($ARGV[1] - $ARGV[0])%24 <=8)" 22,0 +2 Argument "22,02" isn't numeric in subtraction (-) at -e line 1. Use of uninitialized value in subtraction (-) at -e line 1. 1

    With a space instead of comma it produced:

    C:\Old_Data\perlp>perl -we "print( ($ARGV[1] - $ARGV[0])%24 <=8)" 22 0 +2 1

    To get the actual hours difference, remove the <= 8 test.

    C:\Old_Data\perlp>perl -e "print( ($ARGV[1] - $ARGV[0])%24)" 22 02 4