#!/usr/bin/env perl

=head1 SYNOPSIS

Munge invocation line for all perl scripts.

 $0 /path/of/perl

=cut
use strict;
use warnings;

use FindBin qw( $Bin );
use File::Basename;
use Tie::File;

exit 1 unless my $perl = shift @ARGV;
my $path = -l $perl ? readlink $perl : $perl;

exit 1 unless $path =~ /perl/ && -f $path && -x _;
my $dir = dirname( $Bin );

for my $file ( `find $dir -type f` )
{
    my @file;
    chomp $file;
    tie @file, 'Tie::File', $file;

    if ( $file[0] =~ /#!.*?perl(.*$)/ )
    {
        $file[0] = "#!$perl$1";
        warn "$file\n";
    }
    untie @file;
}
exit 0;
