in reply to Read and Create File

Read the file line by line. Use regexes to extract parts of text. Use /x to make them readable and commentable.

Also, I used the variable $printed to print a newline before each section except the first one.

#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; my $printed; while (<>) { chomp; if (/^&LOG[ ]TEXT:[ ] " # The opening quote. [^"]*\\ # Path up to the last backslash. ( [^\\"]+ ) # The final part of the path. " # The closing quote. $/x ) { print "\n" if $printed++; say "[$1]"; } elsif (m{^&LOG[ ]Naming_Technique:[ ] [^@]+\@ # Anything up to the @. \w+/ # Word characters followed by a slash. ([^/]+)/ # The part_no. ([^/]+) # the part_rev. $}x ) { say "db_part_no=$1"; say "db_part_rev=$2"; } }

Save as create-ini.pl, run as

perl create-ini.pl input-file > output-file.ini

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Read and Create File
by szpt9m (Novice) on Jun 28, 2021 at 08:22 UTC
    Really nice. Working as expected. Thanks a lot for quick help