#!/usr/bin/perl use strict; # THIS SCRIPT CONCATENATES DATA FOR 1 WEEK OF RELIANT TRUST DATA AND S +ENDS TO NDM # my $MAIL_ALIAS='my.email.com'; # Mail Alias used for sending emails my $ASL='app-server'; # what the heck is ASL?????????!!!! my @LOG_FILENAMES=('name1.log','name2.log'); my($yyyy,$mm,$dd) = deduct_date_values( timestamp_days_back(1) ); my $abs_log_yesterday = "$0.$dd.log"; sub secsday { return (3600 * 24) } # to give you an idea how far you c +ould consider breaking this up sub deduct_date_values { my $timestamp = shift; $timestamp or die; # expect the 'impossible' require Time::Format; my $date_string = Time::Format::time_format('yyyy_mm_dd',$timestamp +); my($yyyy,$mm,$dd) = split( /_/, $date_string ); # make sure $yyyy or die; $mm or die; $dd or die; return ($yyyy,$mm,$dd); } sub timestamp_days_back { my $numdays = shift; $numdays or die; my $then = ( time - ( $numdays * secsday() ) ); return $then; } if ($yesterwday == 5) { # compute last 7 days of file names # cat the files foreach $logfilename (@LOG_FILENAMES) { my $abs_cat_target = "$logfilename.$year$mm$dd"; unlink $abs_cat_target; # in case we run 2x in one day for my $i (5,6,7,8) { for my $days_back (7,6,5,4,3,2,1) { # Number of days + to go back for process my($yyyy,$mm,$dd) = deduct_date_values( timestamp_days +_back($days_back) ); my $abs_file = "$logfilename.myservername$i\.$year$mm$ +dd"; $command = "cat $fileext.$ASL$i >> $catfile 2>/dev/nul +l"; if ($debug) { print "WOULD $command\n"; } else { $output = `$command`; }
Now, some serious pointers. Things you may think trivial but are actually make or break. Label your scalars/symbols descriptively. Don't use shotcuts like 'f' to mean absolute path to logfile , call it $absolute_path_to_logfile
Use strict. Don't play russian roulette with this. Maybe the data you are handling is actually valuable information.
Do what the pros tell you to do.
The more time passes, the more I come to agree with the higher monks. Try out what they suggest, understand it, then reject it if you still want to- after you've done it, used it.
There's a *reason* for the anal retentiveness of things like using strict and naming variables properly- and it's not to make our life harder or to patronize the noobs.
It's to make your life better and easier.
If you ignore people telling you to use strict- and you continue using perl, you will be using strict. It will just take longer to come around- and slow down your learning curve. I think that to learn to do as much as you did, you must have been exposed to 'use strict' a lot of times. Believe it. Don't doubt it.
I hope this is not going too far up your ***. I would have cleaned out your script but I have to tell you my friend, it's impossible unless I'm you- because of how the code is written.
I would let most of this go for a noob. But from looking at your code, I *know* you're new to perl but not to computers. You know some shiznit. You need a peer to smack you upside the head- here it is.
If you see yourself using perl in the future, you need Damian Conway's Perl Best Practices, you can get it for $5 at amazon.com.
In reply to Re: Help with Concatenates script
by leocharre
in thread Help with Concatenates script
by wskibum
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |