in reply to Create sort function from a text file

If I where you I'd put real Perl code in the "config files" and compile them with do or require

something like

sub gSort { ($a =~ /B(\d+)/)[0] <=> ($b =~ /B(\d+)/)[0] or ($a =~ /U(\d+)/)[0] <=> ($b =~ /U(\d+)/)[0] }

and later

{ no warnings 'redefine'; do "$path/Sort.cfg.pl"; } my @sorted = sort gSort @data;

untested, since you didn't provide an SSCCE with data

I presumed these are sort configs you coded and not alien input, otherwise I'd surely second haukex' comment about NOT trusting user provided code.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

updates

  • added no warnings 'redefine' to handle multiple config files without warnings.
  • Replies are listed 'Best First'.
    Re^2: Create sort function from a text file
    by Doozer (Scribe) on Aug 16, 2021 at 12:41 UTC

      Thank you for the advice. Seeing as I maintain all instances of the interface, it would be sufficient for me to enable the ability to read the text file within the scripts, but manage the contents of the text files myself. I can then deploy the master version and any updates where needed but keep the custom config files as needed per instance

      I really appreciate all the insight here, thank you

        the point about

        > > put real Perl code in the "config files"

        is that the maintainer can run static syntax check° on these files to ensure there are no bugs, instead of hoping they don't fail at runtime. Some IDE's even do this automatically for you in the background.

        Putting only broken snippets of code in different files is mostly doomed to fail.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

        °) i.e. perl -c file.pl