I rewrote your subroutine, and changed something:

sub extractTarFile { my ($strftime, $submissionID, $cur_submit_dir, $tarLocation, $old_cwd, $tar, $RC_extract); my ($user_Name, $tmpFilePosition, $user_File_Filename) = @_; # just to save some typing $strftime = POSIX::strftime("%Y-%m-%d-%H-%M-%S", localtime); # note that this ID is not unique $submissionID = "$strftime-$user_Name"; $cur_submit_dir = "$submittedFiles/$submissionID"; $tarLocation = "$cur_submit_dir/$user_File_Filename"; # do you really need to create a world writable directory? mkdir($cur_submit_dir, 0755) or die "Cannot make directory: $! +"; copy("$tmpFilePosition", "$tarLocation") or die "copy failed: +$!"; # store our current working directory $old_cwd = Cwd::cwd; # change to submitted files current dir Cwd::chdir($cur_submit_dir); $tar = Archive::Tar->new(); $RC_extract = $tar->extract_archive($tarLocation); # restore previous working dir Cwd::chdir $old_cwd; return $RC_extract, $tar->error(); }

Few notes: Archive::Tar extracts archives in current directory, so you need to change your working directory before extracting and possibly restore it when done. I also used strftime, checked return values of file operations instead using -e and removed the open that was unnecessary. All paths must be absolute.

Ciao, Valerio

Update:You are welcome heezy :) I couldn't believe my eyes when I realized that I was writing somewhere else...
Oh, I forgot to do some final cleaning: we should remove submitted files from $tmpFilePosition and $tarLocation... Ciao!


In reply to Re: Extracting files Using Archive::Tar? by valdez
in thread Extracting files Using Archive::Tar? by heezy

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.