marlowvoltron has asked for the wisdom of the Perl Monks concerning the following question:
The code works, I just know it can be improved... I just want to make sure I'm using "die" right, I've had issues before this version where the .tar files I am trying to move would disappear if something went wrong. And fyi- I can't use modules due to permissions when installing
#!/usr/bin/perl -w use strict; use warnings; my @files = glob "*.*"; my @tar_files = glob '*.tar.gz'; # All the tar files in the curr dir. my @jpg_files = glob '*.jpg'; # All the .jpg files in the curr dir. unless (@files) { die "No files here. Exiting!\n"; } for my $tar_file (@tar_files) { my ($path, $row) = $tar_file =~ m/^LC8(\d{3})(\d{3})\d+LGN\d\d\.ta +r.gz$/xms; print "Found $tar_file, with path $path, and row $row\n"; my $dir = "p${path}_r${row}"; print "...so... dir is /$dir\n"; #if (! -e $dir) { #print "$dir dir not found..."; #} { system ("mv $tar_file /data2/jennb/landsat8/antarctica/$dir") == 0 + or die "can't move file!"; print "moved $tar_file to /$dir\n"; } { chdir "/data2/jennb/landsat8/antarctica/$dir" or die "can't cd to +/$dir !\n"; print "...moving to /$dir...\n"; system ("pwd"); } { print "current contents: "; system ("ls"); print "...untaring... please wait...\n"; system ("tar -xzvf $tar_file --wildcards '*B8*'") == 0 or die "unp +acking of $tar_file failed!\n"; print "printing new contents...\n"; system ("ls"); print "...moving on...\n"; } { chdir "/data2/jennb/landsat8/downloads"; print "...listing remaining contents in /downloads...\n"; system ("ls"); } } print "tar files done...now jpgs...\n"; for my $jpg_file (@jpg_files) { my ($path, $row) = $jpg_file =~ m/^LC8(\d{3})(\d{3})\d+LGN\d\d\.jp +g$/xms; print "Found $jpg_file, with path $path, and row $row\n"; my $dir = "p${path}_r${row}"; print "...so... dir is /$dir\n"; system ("mv $jpg_file /data2/jennb/landsat8/antarctica/$dir") == 0 + or die "Failed to move $jpg_file\n"; print "Moved jpg to /$dir\n"; } print "process complete!\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Would you mind critiquing my script?
by dwm042 (Priest) on Feb 24, 2014 at 20:50 UTC | |
|
Re: Would you mind critiquing my script?
by karlgoethebier (Abbot) on Feb 24, 2014 at 21:21 UTC | |
|
Re: Would you mind critiquing my script?
by Laurent_R (Canon) on Feb 24, 2014 at 19:53 UTC | |
|
Re: Would you mind critiquing my script?
by Anonymous Monk on Feb 24, 2014 at 20:26 UTC | |
by Anonymous Monk on Feb 24, 2014 at 23:28 UTC |