add half an hour to all times in file

Discussion in 'Perl Misc' started by Dan Jacobson, Sep 24, 2003.

  1. Dan Jacobson

    Dan Jacobson Guest

    $ cat file
    18:25
    18:56
    $ perl -wlpe 'Please tell me what to write here to get the following' file
    18:55
    19:26
    Maybe perldoc Date::parse has something to do with this.
    In Unix I can do $ date +%H:%M -d '22:22 + 30 minutes'.
    Dan Jacobson, Sep 24, 2003
    #1
    1. Advertising

  2. Dan Jacobson

    Tore Aursand Guest

    On Wed, 24 Sep 2003 12:56:18 +0800, Dan Jacobson wrote:
    > Maybe perldoc Date::parse has something to do with this.


    Indeed. What went wrong when you tried to use it?


    --
    Tore Aursand <>

    "You know the world is going crazy when the best rapper is white, the best
    golfer is black, France is accusing US of arrogance and Germany doesn't
    want to go to war."
    Tore Aursand, Sep 24, 2003
    #2
    1. Advertising

  3. Dan Jacobson

    Frank Maas Guest

    "Dan Jacobson" <> schreef in bericht
    news:...
    > $ cat file
    > 18:25
    > 18:56
    > $ perl -wlpe 'Please tell me what to write here to get the following' file
    > 18:55
    > 19:26


    perl -wlpe 'my ($h,$m)=split(/:/); my $t=($h*60)+$m+30; $h=int($t/60)%24;
    $m=$t%60; $_=sprintf "%02d:%02d",$h,$m;'

    --Frank
    Frank Maas, Sep 24, 2003
    #3
  4. Dan Jacobson wrote:
    >
    > $ cat file
    > 18:25
    > 18:56
    > $ perl -wlpe 'Please tell me what to write here to get the following' file
    > 18:55
    > 19:26
    > Maybe perldoc Date::parse has something to do with this.
    > In Unix I can do $ date +%H:%M -d '22:22 + 30 minutes'.



    $ perl -e'
    use Time::Local;
    my @times = qw/ 18:25 18:56 23:42 /;
    for my $time ( @times ) {
    print "$time ";
    $time = join":",(gmtime(timegm(0,(reverse $time=~/\d+/g),(gmtime)[3,4,5])+1800))[2,1];
    print "$time\n";
    }
    '
    18:25 18:55
    18:56 19:26
    23:42 0:12



    John
    --
    use Perl;
    program
    fulfillment
    John W. Krahn, Sep 24, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    866
    Hal Rosser
    Jun 1, 2007
  2. trint
    Replies:
    4
    Views:
    684
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Sep 11, 2007
  3. ssylee
    Replies:
    4
    Views:
    501
    Thad Smith
    Jan 1, 2008
  4. Chris Gunnels
    Replies:
    4
    Views:
    153
    Robert Klemme
    Sep 16, 2010
  5. joe chesak
    Replies:
    7
    Views:
    265
    (r.*n){2}
    Sep 23, 2010
Loading...

Share This Page