Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Lady_Aleena's scratchpad

by Lady_Aleena (Deacon)
on Sep 07, 2007 at 20:54 UTC ( #637756=scratchpad: print w/replies, xml ) Need Help??


if ($show =~ s/^\!//) { $episodenum = 1; if ($show eq $currentshow) { $season++; } else { $season = 1; } } else { $episodenum++; }


if ($user_time < $dawn) { $daypart = 'night'; } elsif ($user_time < $noon) { $daypart = 'morning'; } elsif ($user_time < tmath($dusk, -1)) { $daypart = 'afternoon'; } else { $daypart = 'evening'; )

This is untested.

#!/usr/bin/perl use strict; use warnings; use Astro::Sunrise qw(sun_rise sun_set); sub tmath { my ($time, $offset) = @_; my ($hour, $minutes) = split(/:/,$time); $hour += $offset; return "$hour:$minutes"; } my $user_lon = -77.314444; my $user_lat = 39.534444; my $user_spot = { lon => $user_lon, lat => $user_lat }; my $noon = '12:00'; my $dawn = sun_rise($user_spot); my $dusk = sun_set ($user_spot); my %dayparts = ( 'morning' => { 'begin' => $dawn, 'end' => $noon}, 'afternoon' => { 'begin' => $noon, 'end' => tmath($dusk, + -1) }, 'evening' => { 'begin' => tmath($dusk, -1) , 'end' => tmath($dusk, + 1) }, 'night' => { 'begin' => tmath($dusk, 1) , 'end' => $dawn} );

Reminder code

my @monsters = map{chomp $_; $_} <$word_find_list>; my @items; for my $monster (@monsters) { push @items, [$monster, { class => 'monster_item' }]; }

is now

my @monsters = map { chomp $_; [$_, { class => 'monster_item' }] } < +$word_find_list>;

Notes to self

  • Do not print Dumper when trying to display a script in a browser without using <pre> tags.
  • Do print Dumper when something goes wrong. The data structure is usually the problem.
  • If one changes a variable, check the whole script for that variable to make sure that the results will be as expected.
  • rename will not create directories, be sure to use mkdir in conjunction with rename if the files are also being moved to a new directory.

Notes from others

  • bart: LA it's often considered good practice to increment the variable in a continue block, to prevent running out of sync when using next.
  • Intrepid: btw, i wish i could explain to a lot of people i know, how efficacious Lady_Aleena's explained strategy can be (to use coding and thinking about coding to master a disquieted state of mind)
  • ambrus: In general, use magic only when normal solutions aren't enough.
  • GrandFather: each time through its loop while asks itself "Can I loop this time? Can I? Can I Can I? Please?" and if the answer is no (false statement) while gets grumpy and stops
  • GrandFather: First make it work (using the easiest to maintain code you can) then, only if you need to, make it faster. (from: Re^5: I have a list expanding when I don't want it to)
  • GotToBTru: imho, you have nothing that needs defending. (from the Chatterbox on April 21, 2015)
  • SuicideJunkie: "you have nothing that needs defending" might be better stated as "you have a lot that needs no defending" (from the Chatterbox on April 21, 2015)

Things I should get a grip on

  • objects - After seeing how little objects do, I will keep my procedural code. Objects may be self-aware, but they are dumb as dirt. I write subroutines to work with predefined and preprocessed data. I have seen objects with predefined data, but I don't know how they do it. For example Net::Twitter::Lite knows where the data is and grabs it without me having to lug around the entire Twitter database with me. Why can't my objects have predefined data too?

    I write modules to reduce repetitive code. One repetitive thing is building hashes; so I build them in a module and write subroutines to return the data (possibly more processed than in the hash). From what I've been told in various threads objects don't do that. If that is the case, then objects are not for me.

  • SQL - I'm waiting for SQL to be standardized. I don't want to have to choose a flavor of SQL and then find out it is not compatible with where I am sending the SQL files.
  • version control
  • testing
Log In?

What's my password?
Create A New User
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2017-04-25 23:44 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (466 votes). Check out past polls.