Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: What can I do to improve my code - I'm a beginner

by Anonymous Monk
on Aug 10, 2017 at 14:47 UTC ( #1197176=note: print w/replies, xml ) Need Help??


in reply to What can I do to improve my code - I'm a beginner

@date1 = ($dt[0], $dt[1], $dt[2], $dt[3], $dt[4], $dt[5]);
This kind of thing is redundant and error-prone. That's why we have array slices!
@date1 = @dt[0..5];
Another redundancy:
chomp($line1); my @mg1 = split(/,/, $line1); my $line2 = <IN>; chomp($line2); my @mg2 = split(/,/, $line2); my $line3 = <IN>; chomp($line3); ...
You've replaced it with a loop that calls Add_Delta_DHMS on every line, not just once per twelve lines, so it's not equivalent at all. I would tend to write something like this:
my ($sum) = split /,/, $line; for (2..12) { my ($val) = split /,/, <IN>; $sum += $val; }

Replies are listed 'Best First'.
Re^2: What can I do to improve my code - I'm a beginner
by Anonymous Monk on Aug 11, 2017 at 08:52 UTC
    That array slice thing makes so much sense! Thank you! Also I now understand why my second code was running a lot slower - because I was calling the Add_Delta_DHMS every line. You've been a big help! Thank you!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1197176]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2017-12-16 06:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (449 votes). Check out past polls.

    Notices?