I have to double what was said here. Break up the script into subs. Even if you're just calling it one time. It will make more sense to you, and to other people viewing your code. Break up what happens into tasks. I have started the process here for you.. this is not functional code.. But it illustrates some examples.
#!/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

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.