However, I am still getting the unchanged files as a result:sonya$ vi sorting.pl #!/usr/bin/perl use strict; use warnings; use Getopt::Long; my $version="0.2"; my $files_match=""; my $files_dir=""; my $file_name=""; my $help_flag=""; my $version_flag=""; GetOptions( 'm|match=s' => \$files_match, 'd|directory=s' => \$files_dir, 'h|help' => \$help_flag, 'v|version' => \$version_flag, ); sub sorting { my @lines = @_; my @sorted = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { my ($x) = $_ =~ /VerNumber:\((\d+)/i; [$_, $x]; } @lines; print FILE for @sorted; } if (($files_match ne "") and ($files_dir ne "")) { chdir("$files_dir") or die "$!"; opendir (DIR, ".") or die "$!"; my @files = grep {/$files_match/} readdir DIR; my $files_size = $#files + 1; my $index_file = 1; print "Files to process: $files_size\n"; close DIR; foreach (@files) { open(FILE, ">./sorted/$_.sort") or die $!; my @singlefile = $_; print "Processing $index_file of $files_size files: $_ ++\n"; local @ARGV = @singlefile; while(<>){ sorting($_); } close(FILE); $index_file++; print "OK: Sorted @singlefile \n"; } } elsif ((!$help_flag) and (!$version_flag)){printHelp();} "sorting.pl" [New] 49L, 1391C written
The standalone sorting script is working so there is something wrong with my code.sonya$ ./full.pl -d /home/sonya/test/ -m file Files to process: 3 Processing 1 of 3 files: file1.txt+ OK: Sorted file1.txt Processing 2 of 3 files: file2.txt+ OK: Sorted file2.txt Processing 3 of 3 files: file3.txt+ OK: Sorted file3.txt sonya$ diff /home/sonya/test/file1.txt /home/sonya/test/sorted/file1.t +xt.sort sonya$ sonya$
In reply to Re^2: Use Schwartzian transform across multiple files
by Sonya777
in thread Use Schwartzian transform across multiple files
by Sonya777
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |