Skip to content

Instantly share code, notes, and snippets.

@makoru-hikage
Created August 3, 2016 06:14
Show Gist options
  • Save makoru-hikage/d3797a4ba75ad195d958fbb38eb8534a to your computer and use it in GitHub Desktop.
Save makoru-hikage/d3797a4ba75ad195d958fbb38eb8534a to your computer and use it in GitHub Desktop.
Because I do not know `sed` and `awk` back in 2014
#!/usr/bin/perl
open(INFILE1, "<list_of_classes.txt") or die "Couldn't open file, $!";
@listOfClasses = <INFILE1>;
@items = ();
#Split all the items of the list which might be
#seperated by commas(,), spaces ( ), or both (, ) or ( ,)
#and it shall be pushed into the blank @items array.
foreach $i (@listOfClasses){
push @items, split (/,\s|,|[\s,]/ ,$i);
}
foreach $className (@items){
if ($className ne ""){
open(OUTFILE, '>>list.txt') or die "Couldn't create file, $!";
print "\n$className is appended\n";
#We will load the template as pristinely as possible
#to the @classTemplate array
open(INFILE2, "<class_template.txt") or die "Couldn't open file, $!";
@classTemplate = <INFILE2>;
foreach $lineOfTemplate (@classTemplate){
$lineOfTemplate =~ s/\#_\#/$className/g;
#For debugging
print "WRITING: $lineOfTemplate";
#For writing onto file
print OUTFILE $lineOfTemplate;
}
close (INFILE2);
close (OUTFILE);
}
}
close (INFILE1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment