Last active
April 1, 2017 05:55
-
-
Save makoru-hikage/e896e1a78bb58686741e7c1e23b86177 to your computer and use it in GitHub Desktop.
Just like Repeater.perl but this is the original one I created
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
#The original one I wrote back in 2014 because I don't know sed and awk. | |
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, '+>'.$className.'Controller.php') or die "Couldn't create file, $!"; | |
print "\n$className"+"Controller.php is created\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; | |
#If in the template you find @_, 'User' will turn into 'user' | |
#Does not know how to turn things like 'UserGroup' to 'user_group' | |
if ($lineOfTemplate =~ m/@\_/){ | |
$lineOfTemplate =~ tr/[A-Z]/[a-z]/; | |
$lineOfTemplate =~ s/@_//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