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

Re^2: Display tide based on time now.

by Anonymous Monk
on Mar 27, 2013 at 12:51 UTC ( #1025703=note: print w/ replies, xml ) Need Help??


in reply to Re: Display tide based on time now.
in thread Display tide based on time now.

Unfortunately it does not work, it will not match any time before the first AM time, its back where my issue is.


Comment on Re^2: Display tide based on time now.
Re^3: Display tide based on time now.
by hdb (Prior) on Mar 27, 2013 at 13:05 UTC

    I might not be quite sure what you want to achieve. Can you please try this?

    my $last_time = 0; my $current_tide = "Now is before first tide in xml file."; foreach my $tides (@{$data->{data}->{item}}) { my $format_date = "$tides->{date} $tides->{time}"; my $date_to_seconds = str2time($format_date); if( $date_to_seconds > $last_time and $date_to_seconds <= $now_in_ +seconds ) { $tides->{highlow} =~ s/L/Low/; $tides->{highlow} =~ s/H/High/; $current_tide = " Test: ".$tides->{highlow}." Tide at: ".$tides->{ +time}; $last_time = $date_to_seconds; } } if( $now_in_seconds > $last_time ) { $current_tide = "Now is after the last tide in xml file." } print "$current_tide\n";
      Here is what I am trying to accomplish:

      There are 4 tides in the XML, sometimes 3 but the goal is:

      if time now in seconds is greater and equal to the first tide time in the XML, and the now in seconds is less than the second tide time in the XML print the first tide specs.

      if time now in seconds is greater and equal to the second tide time in the XML, and the now in seconds is less than the third tide time in the XML, print the second tide specs.

      if time now in seconds is greater and equal to the third tide time in the XML, and the now in seconds is less than the fourth tide time in the XML, print the third tide specs.

      if time now in seconds is greater and equal to the fourth tide time in the XML, and the now in seconds is less than the first tide time in the XML, print the fourth tide specs.


      I hope is clear, but thanks for trying!

        Sounds like you've got a very straightforward algorithm laid out there. It is difficult to be both "greater" and "equal" at the same time, but I presume you meant to say "or".

        You may have also noticed how repetitive it is, and that it can be reworded as a for loop, using N, and (N+1)%$numTidePoints

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1025703]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (11)
As of 2014-09-21 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (172 votes), past polls