G'day dushyant,
You say "system "gzip $full_name" is taking more time." but you don't say more time than what.
More time than some other compression program? More than the same command from the command line? More time than it took last week?
Your code shows nothing to indicate how you are measuring this time. How are you doing this?
You've provided no indication of how big your files are.
Perhaps 2 hours is perfectly reasonable for individually compressing 90,000 of your files.
I suggest you do a comparison of the times taken to compress a representative file from the command line (e.g. time gzip filename) and from a Perl script (Time::HiRes might be useful here).
If you do find a distinct difference, show us how you did the timings and what the results were.
A few other points regarding your code:
-
Don't prepend an ampersand ('&') to your function names as you've done here (see perlsub). Also, there's no need to quote variable arguments. So, go_dir($_) instead of &go_dir("$_").
-
You may find the -m file test operator easier than all the date calculations you're doing.
-
Read the subroutine arguments once (e.g. my ($dir) = @_;) rather than repeatedly accessing elements of @_ (e.g. you've used $_[0] in your foreach loop).
-
As well as excluding /^\./, you might want to also exclude /\.gz$/ — you don't want to compress files that have already been compressed.
-
I see no need for the chomp in the foreach loop (readdir just returns the file names — no newline is added); however, using it for the `date '+%Y%m%d'` return value would be correct.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.