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 1098663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:36:41+00:00 2026-05-17T00:36:41+00:00

$tasks->{t1}{cmdline} = convert -f %FONT% %1%; $tasks->{t1}{report} = Launched as %CMD% by %USER%; $tid

  • 0
$tasks->{t1}{cmdline} = "convert -f %FONT% %1%";
$tasks->{t1}{report} = "Launched as %CMD% by %USER%";
$tid = 't1';
foreach my $parm (keys %{$tasks->{$tid}}) {
    $tasks->{$tid}{$parm}=~s/%FONT%/$tasks->{$tid}{font}/g; # may evaluate if $parm == 'cmdline';
    $tasks->{$tid}{$parm}=~s/%CMD%/$tasks->{$tid}{cmdline}/g;
}

The code is bad, because it needs another loop outside foreach (to ensure that all copied values were replaced), and also contains too much textual data. The best way to rewrite currently looks as:

foreach my $parm (keys %{$tasks->{$tid}}) {
 &lookupValues(\$tasks->{$tid}{&parm}); # or ($parm) if strict refs?
}

However it still needs to have keys sorted in order to detect priority (if %CMD% is replaced before %FONT%, $tasks->{$tid}{report} is wrong).

foreach my $parm ( &SORTME($tasks->{$tid}) ) {&lookupValuesFor($tid,$parm); }

What is a best way to sort depending on the number of specified variables and their relations? Native one (lots of loops and hashes), or expat [ Related questions are somehow pointing me to expat, would investigate it too: Parsing a string for nested patterns ] or other parser?

OOP way of $object->value(‘cmdline’) is not liked now.

  • 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-05-17T00:36:42+00:00Added an answer on May 17, 2026 at 12:36 am

    This code ‘works’ – and looks cleaner to me. Whether it does what you’re after is more debatable.

    use strict;
    use warnings;
    
    my $tasks;
    
    # Demonstration setup
    $tasks->{t1}{cmdline} = "convert -f %FONT% %1%";
    $tasks->{t1}{report}  = "Launched as %CMD% by %USER%";
    $tasks->{t1}{maps} = {
        '%USER%'    => 'user-expansion',
        '%1%'       => 'one-expansion',
        '%FONT%'    => 'font-expansion',
        '%CMD%'     => 'cmd-expansion',
    };
    
    # Do the substitutions
    foreach my $tid (keys %$tasks)
    {
        my $task = $tasks->{$tid};
        my $maps = $task->{maps};
        foreach my $map (keys %$maps)
        {
            foreach my $key (keys %{$task})
            {
                next if ref $task->{$key};
                $task->{$key} =~ s/$map/$maps->{$map}/g;
            }
        }
    }
    
    # Demonstration printing
    foreach my $tid (keys %$tasks)
    {
        my $task = $tasks->{$tid};
        foreach my $key (keys %{$task})
        {
            next if ref $task->{$key};
            printf "%s: %-8s = %s\n", $tid, "$key:", $task->{$key};
        }
    }
    

    The output using Perl 5.13.4 on MacOS X (10.6.4) is:

    t1: report:  = Launched as cmd-expansion by user-expansion
    t1: cmdline: = convert -f font-expansion one-expansion
    

    The triple loop is close to unavoidable; you want to apply each mapping to each string for each of the tasks. Each task can have its own mappings, in general.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

INSERT INTO [Tasks] ([LoginName] ,[Type] ,[Filter] ,[Dictionary] ,[Description]) Select N'Anonymous',4,'SomeTable.targetcode in (select Code from
The following code adds tasks that perform some processing on files from the blobstore,
db.tasks.find({user:saturngod}); is return { _id : ObjectId(4de20ef97065cc77c80541fd), todo : [ { id : 1,
What tasks, features, executions vary with compiler? I know this code is compiler-dependent- #include
What tasks should one not use HBase for? My understanding is that HBase and
Projects have many tasks and a task has a custom RESTful action called 'approve'.
I'm firing off tasks using an ExecutorService, dispatching tasks that need to be grouped
So a OS multi-tasks and runs one process at a given moment (assuming it's
When estimating tasks, how does one break from the grip of Hofstadter's law ?
We have two tables - Tasks and TasksUsers (users assigned to task). Task has

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.