Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Use Schwartzian transform across multiple files

by Sonya777 (Novice)
on Sep 19, 2016 at 13:59 UTC ( [id://1172140]=note: print w/replies, xml ) Need Help??


in reply to Re: Use Schwartzian transform across multiple files
in thread Use Schwartzian transform across multiple files

Hi! Thanks for the comment! I have corrected that. Here is the upated script:
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
However, I am still getting the unchanged files as a result:
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$
The standalone sorting script is working so there is something wrong with my code.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1172140]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-19 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found