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";

In reply to Would you mind critiquing my script? by marlowvoltron

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.