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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:21:12+00:00 2026-05-19T09:21:12+00:00

Cross-posted from perlmonks: I have to clean up some gross, ancient code at $work,

  • 0

Cross-posted from perlmonks:

I have to clean up some gross, ancient code at $work,
and before I try to make a new module I’d love to use an existing one if anyone knows of something appropriate.

At runtime I am parsing a file to determine what processing I need to do on a set of data.

If I were to write a module I would try to do it more generically (non-DBI-specific), but my exact use case is this:

I read a SQL file to determine the query to run against the database.
I parse comments at the top and determine that

  • column A needs to have a s/// applied,
  • column B needs to be transformed to look like a date of given format,
  • column C gets a sort of tr///.
  • Additionally things can be chained so that column D might s///, then say if it isn’t 1 or 2, set it to 3.

So when fetching from the db the program applies the various (possibly stacked) transformations before returning the data.

Currently the code is a disgustingly large and difficult series of if clauses
processing hideously difficult to read or maintain arrays of instructions.

So what I’m imagining is perhaps an object that will parse those lines
(and additionally expose a functional interface),
stack up the list of processors to apply,
then be able to execute it on a passed piece of data.

Optionally there could be a name/category option,
so that one object could be used dynamically to stack processors only for the given name/category/column.

A traditionally contrived example:

$obj = $module->new();  
$obj->parse("-- greeting:gsub: /hi/hello"); # don't say "hi"  
$obj->parse("-- numbers:gsub: /\D//"); # digits only  
$obj->parse("-- numbers:exchange: 1,2,3 one,two,three"); # then spell out the numbers  
$obj->parse("-- when:date: %Y-%m-%d 08:00:00"); # format like a date, force to 8am  
$obj->stack(action => 'gsub', name => 'when', format => '/1995/1996/'); # my company does not recognize the year 1995.  

$cleaned = $obj->apply({greeting => "good morning", numbers => "t2", when => "2010116"});  

Each processor (gsub, date, exchange) would be a separate subroutine.
Plugins could be defined to add more by name.

$obj->define("chew", \&CookieMonster::chew);  
$obj->parse("column:chew: 3x"); # chew the column 3 times  

So the obvious first question is, does anybody know of a module out there that I could use?
About the only thing I was able to find so far is [mod://Hash::Transform],
but since I would be determining which processing to do dynamically at runtime
I would always end up using the “complex” option and I’d still have to build the parser/stacker.

Is anybody aware of any similar modules or even a mildly related module that I might want to utilize/wrap?

If there’s nothing generic out there for public consumption (surely mine is not the only one in the darkpan),
does anybody have any advice for things to keep in mind or interface suggestions or even other possible uses
besides munging the return of data from DBI, Text::CSV, etc?

If I end up writing a new module, does anybody have namespace suggestions?
I think something under Data:: is probably appropriate…
the word “pluggable” keeps coming to mind because my use case reminds me of PAM,
but I really don’t have any good ideas…

  • Data::Processor::Pluggable ?
  • Data::Munging::Configurable ?
  • I::Chew::Data ?
  • 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-19T09:21:13+00:00Added an answer on May 19, 2026 at 9:21 am

    Thanks to everyone for their thoughts.

    The short version:
    After trying to adapt a few existing modules I ended up abstracting my own: Sub::Chain.
    It needs some work, but is doing what I need so far.

    The long version:
    (an excerpt from the POD)

    =head1 RATIONALE

    This module started out as Data::Transform::Named,
    a named wrapper (like Sub::Chain::Named) around
    Data::Transform (and specifically Data::Transform::Map).

    As the module was nearly finished I realized I was using very little
    of Data::Transform (and its documentation suggested that
    I probably wouldn’t want to use the only part that I I using).
    I also found that the output was not always what I expected.
    I decided that it seemed reasonable according to the likely purpose
    of Data::Transform, and this module simply needed to be different.

    So I attempted to think more abstractly
    and realized that the essence of the module was not tied to
    data transformation, but merely the succession of simple subroutine calls.

    I then found and considered Sub::Pipeline
    but needed to be able to use the same
    named subroutine with different arguments in a single chain,
    so it seemed easier to me to stick with the code I had written
    and just rename it and abstract it a bit further.

    I also looked into Rule::Engine which was beginning development
    at the time I was searching.
    However, like Data::Transform, it seemed more complex than what I needed.
    When I saw that Rule::Engine was using [the very excellent] Moose
    I decided to pass since I was doing work on a number of very old machines
    with old distros and old perls and constrained resources.
    Again, it just seemed to be much more than what I was looking for.

    =cut

    As for the “parse” method in my original idea/example,
    I haven’t found that to be necessary, and am currently using syntax like


    $chain->append($sub, \@arguments, \%options)

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

Sidebar

Related Questions

[Cross-posted from lib-curl mailing list] I have a single threaded app (MSVC C++ 2005)
Cross-posted from the Cukes Google Group: I have experimented with a number of methods
We have some code that is making use of the new postMessage functionality in
I tried Oleg clickable checkbox formatter recently posted in trirand.com forum. Code below from
EDIT: To fix mistake in covariance matrix Cross posted from here Ok so I
(cross-posted on Mozilla: http://forums.mozillazine.org/viewtopic.php?f=7&t=2254955 ) I'm trying to work with the Mozilla storageService .
[cross posted again to Mahalo answers] My Perl/Tk script has an initial spreadsheet like
This isn't cross-platform code... everything is being performed on the same platform (i.e. endianess
This is already cross-posted at MS Connect: https://connect.microsoft.com/VisualStudio/feedback/details/560451 I am attempting to override the
I'm doing some work for a charity that's having a fund drive. Whenever someone

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.