Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^5: Epoch based parser

by kcott (Canon)
on Aug 12, 2013 at 06:35 UTC ( #1049060=note: print w/replies, xml ) Need Help??

in reply to Re^4: Epoch based parser
in thread Epoch based parser

There's some issues with is_poll_time(). You're looping through all hours except one: 1 to 24 won't pick up 00:20. As it looks like you want all hours, that loop is entirely redundant; all you need is:

sub is_poll_time { for (@_) { my $t = gmtime $_; return 1 if $t->min == $poll_minute; } return 0; }

If you had needed that loop, it would have better written more like Perl and less like C. Consider whether you think this is clearer:

for my $poll_hour (0 .. 24) { # Process $poll_hour here }

Assigning to @$_[0] and @$_[1] is a poor choice: you're altering the original data. I question whether doing that is necessary here; however, as a general rule of thumb, assign to a new variable rather than altering the original data.

Pulling out parts of date/time strings with substr and doing various arithmetic calculations to generate seconds, minutes, etc. is prone to errors and, as far as I can see, extra work you don't need to do. I repeat what I said in my initial reply:

"Check the Time::Piece documentation to see how I've used it and for ways to format the output ..."

Use indentation to show the logical structure of your code. This makes it easier for everyone (including yourself) to read and follow. It also makes it less prone to errors and, when errors do exist, easier to find them. You only have a small script so uneven and inconsistent identation was not a huge impediment; when you start writing more complex code it will make a big difference. See "perlstyle - Perl style guide" for hints and tips in this area.

Please do not post vast swathes of data such as you've done here. Only post enough to illustrate whatever point you're making. If you do consider it necessary to post pages of data, use <readmore> of <spoiler> tags which are explained here: "Writeup Formatting Tips".

-- Ken

Replies are listed 'Best First'.
Re^6: Epoch based parser
by spikeinc (Acolyte) on Aug 14, 2013 at 02:25 UTC

    Thanks for the review Ken! I ve now become more perl-aware than yesday :)

    Thanks for helping me undestand. I used the Time::Piece to get the year/date/format that I wanted and now the code looks pretty neat.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2017-03-28 07:44 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (327 votes). Check out past polls.