sub highest_number{
use strict;
use File::Basename;
use Cwd;
my ($aref, $filetype, $word) = @_;
my $number;
my @matching;
my $ext = ".".$filetype;
push (@matching, 0); #min returned value
for my $file (@{$aref}) {
#print "file is $file\n";
if ($file =~ /^$word(\d*)$ext$/){
#print "matching is $file\n";
push (@matching, $1);
}
}
@matching = sort @matching;
my $winner = pop @matching;
return $winner
}
####
$ history | tail - 10
==> standard input <==
1987 pt 1.a.pl
...
1990 ./1.a.pl 1.k.pl
1991 rm 2.k.pl
1992 ./1.a.pl 1.k.pl
1993 file -i *.pl
1994 cat 1.manifest
...
1996 history | tail - 10
tail: cannot open '10' for reading: No such file or directory
$
####
$ cat 1.a.pl
#!/usr/bin/perl -w
use 5.011;
use Path::Tiny;
use Encode;
use utf8; # a la François
use open OUT => ':encoding(utf8)';
use open ':std';
# This script increments and clones the file in $1.
## enabling cyrillic
## decode argv and current
say "argv is @ARGV";
foreach (@ARGV) {
say "before decode is $_";
$_ = decode( 'UTF-8', $_ );
say "after decode is $_";
}
my (@in_files) = @ARGV;
my $current = Path::Tiny->cwd;
$current = decode( 'UTF-8', $current );
say "current is $current";
say "-------------";
say "in_file: @in_files";
for (@in_files) {
my $tiny_in = path($_);
## use Path::Tiny
my $file_contents = $tiny_in->slurp_utf8;
$_ =~ m/^(\d+)(.*)$/;
my $number = $1;
my $rest = $2;
my $increment = $number + 1;
my $new_base = $increment . $rest;
say "new base is $new_base";
## use Path::Tiny to create new file
my $save_file = path( $current, $new_base )->touchpath;
say "save path is $save_file";
my $return = $tiny_in->copy($save_file);
$return->chmod(0755);
say "return is $return";
## write to local manifest
my $manifest_name = "1.manifest";
path($manifest_name)->append_utf8( $new_base . "\n" );
system "cat $manifest_name";
system "cat $save_file";
}
$
####
$ cat 1.manifest
2.haukex.pl
3.haukex.pl
4.haukex.pl4.ping3a.pl5.haukex.pl5.ping3a.pl2.k.pl/n2.k.pl
3.k.pl
$