Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7836287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:04:59+00:00 2026-06-02T14:04:59+00:00

$args[0] is a reference to a string containing one or more times. I am

  • 0

$args[0] is a reference to a string containing one or more times. I am shifting each time by a variable number of seconds, but then I need to find a way to store (replace) the changed times back into the original string. Any help is appreciated. Here is roughly what I am working with:

    my $TIMEREGEX = qr/(\d{2}:\d{2}:\d{2}\.\d{3}|\d{2}:\d{2}:\d{2})/x;
    if ( my @sTime = ${$args[0]} =~ /$TIMEREGEX/g )
    {
        warn "\ttime(s) found @sTime\n" if $main::opt{d};
        for my $i ( 0..$#sTime )
        {
            $sTime[$i] =~ /(\d{2}):(\d{2}):(\d{2})(\.(\d{3}))?/;
            my $epoch_time = ( $1 * 3600 ) + ( $2 * 60 ) + $3;
            $epoch_time += $epoch_shift;
            my @f;
            $f[0] = $epoch_time % 86400 / 3600; # hours
            $f[1] = $epoch_time % 3600 / 60;    # minutes
            $f[2] = $epoch_time % 60;           # seconds
            my $save = $sTime[$i];
            $sTime[$i] = sprintf ( "%02d:%02d:%02d", $f[0], $f[1], $f[2] );
            $sTime[$i] .= $4 if defined ( $4 );
            warn "\tTimeShift $save => $sTime[$i]\n" if $main::opt{d};
            ### some other stuff
        }

        # ${$args[0]} = "$1$t[0]$4$t[1]$7$t[2]$10";
        ### save the changes to ${$args[0]} !

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T14:05:01+00:00Added an answer on June 2, 2026 at 2:05 pm

    Use the substitution operator.

    use 5.010;  # or better for 'say' and '//'
    use strictures;
    use Time::Piece qw();
    
    my @args; my $epoch_shift = 500;
    ${$args[0]} = 'foo18:00:00.123bar18:00:00baz18:00:00quux';
    
    ${$args[0]} =~
        s{
            (\d{2}:\d{2}:\d{2})  # capture hh:mm:ss
            (\.\d{3})?           # optionally capture
                                 #   decimal dot and milliseconds
        }
        {
            (
                $epoch_shift
                + Time::Piece->strptime($1, '%T')
            )->strftime('%T').($2 // '')
        }egx;
    say ${$args[0]};
    # foo18:08:20.123bar18:08:20baz18:08:20quux
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

You have to pass the args variable to the anonymous function, but the anonymous
When reference variable can be passed by reference : class Example { public string
class ArrayApp{ public static void main(final String[] args){ long[] arr; // reference to array
I am passing a string variable to a method. I know strings are reference
println args println args.size() println args.each{arg-> println arg} println args.class if (args.contains(Hello)) println Found
I understand that String[] args is an array of strings passed into main as
static void Main(string[] args) { //read in the file StreamReader convert = new StreamReader(../../convert.txt);
class Program { static void Main(string[] args) { List<Book> books = new List<Book> {
If two assemblies both define namespace A containing class A1 , then the two
In C#, I have a simple 3D vector class. static void Main(string[] args) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.