Hi Chris, To debug your code simplify it as much as possible to include only the parts that aren't working right which means copy the file to a temporary working file (I usually call mine t.pl) and delete the stuff that's superflous. In your case that would be reading and writing files and the last 2 paragraphs starting with 'my $lastDist = 0.0;' and 'for my $record ( sort {'. Put one line of your data at the end of your truncated file after the __DATA__ line and read it into a variable with a line like: my $record = <DATA>;
On Thu, Sep 08, 2011 at 02:58:05PM -0500, Chris Stinemetz wrote: > What would be the best way to omit any record when varible $dist is > null or not > 1 ? > > I am not sure my attempt is correct with the ternary operator with > length function. It seems that $dist is just being assinged 0 when > the expression $dist is not > 1. > > Any help is greatly appreciated. > > Thank you, > > Chris > > #!/usr/bin/perl > > use warnings; > use strict; > use POSIX; > > my $filepath = sprintf("F:/Backup/MySQL/10072810.EVDOPCMD"); Double quotes strings are interpolated but wastes clock cycles when uncalled for. Won't make a big difference here but done several times within a loop will add up. my $filepath = 'F:/Backup/MySQL/10072810.EVDOPCMD'; > my $runTime = sprintf("C:/%s.txt",strftime("%y%m%d%H%M",localtime)); > #my $fileDate = strftime("%y%m%d%H%",localtime); > > open my $fh, '<', $filepath or die "ERROR opening $filepath: $!"; > open my $out, '>', $runTime or die "ERROR opening $runTime: $!"; > > my %sum; > > while (<$fh>){ > next unless /;/; > chomp; > my @data = split /;/; > my($cell,$sect,$chan,$rlp1,$rlp2,$rlp3,$rlp4,$dist) = > @data[31,32,38,44,45,46,47,261]; <snip> The answer to your first question is here: next if( $dist <= 1 ); You never use $rlp1,$rlp2,$rlp3,$rlp4 so are just wasting clock cycles by extracting them. my($cell,$sect,$chan,$dist) = (split /;/)[31,32,38,261]; > $dist = sprintf "%.1f", ( length( $dist ) > 1 ) ? $dist/8/6.6/2 : 0; This is the only place you assign to $dist so if you're not happy with the value here's where it needs fixing. 1/8/6.6/2 = 0.0094696 = 1/105.6 and is a constant so take that calculation outside your loop as you gain nothing by calculating it again and again. <snip> Pushing your data into an array just so you can pull it back out seems a bit cumbersome to me. HTH, Mike -- Satisfied user of Linux since 1997. O< ascii ribbon campaign - stop html mail - www.asciiribbon.org -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/