in reply to Re: Adding items to arrays: best approach?
in thread Adding items to arrays: best approach?

Hello Ken,

Thanks for your appreciation. I'm trying to be as clear as possible when asking questions. And in the meantime, I'm also learning the syntax to be used in messages, like showing the real name and also the username (or how do you call it with PerlMonks?): see the start of this reply... :-)

I'm definitely taking all the great advice given by many people here into account. I've already changed my script in many ways. And indeed, the testx was just an example I gave. The real files are not incremental by numbers but totally different names in totally different (sub)directories. I just wanted to point out the difference between how to extend arrays.

I've also seen Perl has a zillion modules/libraries that do a lot of the hard work behind the scenes. One of them is indeed File::Spec but there are more, lots more...

I'm still learning (and eager to learn) the language of Perl and I'm realizing I still have a long way to go. But by practicing it step by step I'm convinced I'll be able to do whatever I want it to do (this might be an "overstatement"... :-)).

Maybe little bit saying why I'm using Perl for the moment: automatic Java code generation. I'm using XML files as input and using the amazing Text::Xslate and XML::LibXML::Simple Perl modules together with appropriate code templates to generate that code. It's a bless!!!

Best,
--Geert

Replies are listed 'Best First'.
Re^3: Adding items to arrays: best approach?
by hippo (Archbishop) on May 29, 2020 at 14:26 UTC
    The real files are not incremental by numbers but totally different names in totally different (sub)directories.

    That's the problem with providing example data which has an inherent pattern that doesn't match your production data. It suggests to those wishing to help that the pattern matters and therefore they are likely to take this into account. If you don't want to give an excerpt from the production data for some reason (security, embarrassment, NDA, ...) it would be better to put something purely random (but still representative) in its place. For a short dataset your favourite metasyntactic variables would suffice.

Re^3: Adding items to arrays: best approach?
by kcott (Archbishop) on May 30, 2020 at 04:36 UTC
    "... just an example I gave. The real files are not ..."

    The last two paragraphs that I wrote were intended to convey the idea that I understood this.

    "I'm still learning (and eager to learn) the language of Perl ..."

    Well, you've certainly come to the right place. :-)

    "... and I'm realizing I still have a long way to go."

    It shouldn't be too hard to get a handle on the basics. Take a look at perlintro: as well as having those "basics" on that page, it is also peppered with links to additional information and advanced topics (I'd suggest following these as the need arises rather than trying to learn it all at once).

    "... automatic [whatever] code generation ..."

    Perl is an excellent language for this type of task. You can also generate Perl code; here's a rough example of one way you could do this:

    my $generated_function = generate_function(...); $generated_function->(); sub generate_function { ... return sub { ... }; }

    You might also find "Template Toolkit" is worth a look.

    — Ken