I’m modifying a pre-existing script in Xcode to customize my file headers. The script is Perl and it’s not my best langage. 🙂
I just need to insert the current date in the header in dd/mm/yy format.
Here is my script :
#! /usr/bin/perl -w # Insert HeaderDoc comment for a header # # Inserts a template HeaderDoc comment for the header. use strict; # get path to document my $headerPath = <<'HEADERPATH'; %%%{PBXFilePath}%%% HEADERPATH chomp $headerPath; my $rootFileName = &rootFileNameFromPath($headerPath); print '/*'; print ' * $rootFileName\n'; print ' * Project\n'; print ' *\n'; print ' * Created by Me on '; # in bash it would be something like that : # date +%d/%m/%y | awk '{printf '%s\n', $1}'; print ' * Copyright 2009 My_companie. All rights reserved.\n'; print ' *\n'; print ' */\n'; sub rootFileNameFromPath { my $path = shift; my @pathParts = split (m'/', $path); my $filename = pop (@pathParts); my $rootFileName = '$filename'; $rootFileName =~ s/\.h$//; return $rootFileName; } exit 0;
I’ve just modified the print command so don’t ask me for the rest of the code 🙂
Rather than removing
strict(!), why not just make the codestrictclean?Maybe even better (since more familiar looking to someone who asked in terms of Bash):
Funny coincidence: Perl Training Australia publishes semi-regular tips (you can get them via email or online), and just today there’s a new one on
strftime.