in reply to Haven't Scripted in a Decade, need help (gift is probably a better word)!

I'm guessing one can get awfully rusty in a decade ...

Here's a start.

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11151867 use warnings; open my $fh, '<', 'config.file' or die; my $configlist = join '', <$fh>; close $fh; open $fh, '<', 'gamelist.txt' or die; while( <$fh> ) { chomp; (my $newfile = $configlist) =~ s/floppy0=\K/$_/; open my $outfh, '>', "$_.config" or die; print $outfh $newfile; close $outfh; } close $fh;

It's not complete, for example, the die messages need to be expanded to something reasonable.

  • Comment on Re: Haven't Scripted in a Decade, need help (gift is probably a better word)!
  • Download Code

Replies are listed 'Best First'.
Re^2: Haven't Scripted in a Decade, need help (gift is probably a better word)!
by tybalt89 (Monsignor) on Apr 28, 2023 at 14:18 UTC

    BTW, if a modern perl with Path::Tiny is available, here's how I'd do it.

    #!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11151867 use warnings; use Path::Tiny; my $configlist = path('config.file')->slurp; path("$_.config")->spew( $configlist =~ s/floppy0=\K/$_/r ) for path('gamelist.txt')->lines({chomp => 1});

    Short and sweet :)

Re^2: Haven't Scripted in a Decade, need help (gift is probably a better word)!
by rickyboy (Novice) on Apr 26, 2023 at 22:19 UTC
    Thanks for the quick replies and I understand the animosity. I've managed to get the gamelist file as it should be using scripts but failing when trying to fill in the configuration file and outputting to seperate files. I have actually been at this for about 8 hours with bash scripts and using awk and sed but getting error after error, usually with seperators. I only arrived here after a temper tantrum!

    Anyway, enough moaning as this is just what I'm looking for and I'm sure I can get that to work with some thought behind it. I'll let you know how I get on and post the full script if I manage it for any others who still live in the 80s/90s and want to get a retropie and play some old games without doing a time consuming setup.

    Thanks for your help!

      I had to Google "animosity" to make sure the word means what I thought it means. It does:

      "The meaning of ANIMOSITY is a strong feeling of dislike or hatred : ill will or resentment tending toward active hostility : an antagonistic attitude."
      which puzzles me because none of the replies you received contained anything anywhere near "animosity".

      In my view a key part of interactions on PerlMonks is to teach / learn. Part of being an effective teacher is understanding the level of understanding of the student. I'm very sorry if my attempt to reach that understanding was interpreted as anything other than trying to be helpful!

      Yes, please show us what you produce, but with the intent that we provide some constructive criticism and guidance to help you recover your lapsed coding foo.

      Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
        Hi Grandfather, please dont take offence. It was an off-the-cuff comment. I write as I speak; with a sarcastic, jocular tone that can't be heard on a forum board and tend to over exaggerate for a bit of artistic flare! I'm grateful for your help, I was specific in writing thanks for your replies (plural) even though I did not reply directly to you. Genuinely, your help is appreciated and your advice sound. Thanks again. :)
      I totally agree with GrandFather. He simply reminded you that PerlMonks is not a code writing service and following that he provided you with 4 great hints to writing good, solid code. It's always wise to take a breath and resist the urge to strike out at the ones who are trying to help you.

      We wish you well on your endeavors to re-enter the wonderful world of Perl.

      "It's not how hard you work, it's how much you get done."