Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Lady_Aleena's scratchpad

by Lady_Aleena (Priest)
on Sep 07, 2007 at 20:54 UTC ( [id://637756] : scratchpad . print w/replies, xml ) Need Help??

some_sub(s/^[\*\+-] (.+)/$1/r, $opt); some_sub(s/^[\*\+-] (.+)/$1/r, $opt); some_sub(s/^[\+-] (.+)/$1/r, $opt);

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.

    I have three threads that show I can not get a grip on objects.

  • 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

Module's I wrote for myself

Base::Inline Base::LineMagic Base::Menu Base::Page Base::Path Base::Style Date::Misc Date::Verify Date::Birth::DayStone Date::Birth::Flower Date::Birth::Stone Date::Birth::ZodiacStone Fancy::Function Fancy::Map Fancy::Rand Fancy::Splice Fancy::Split Fancy::Join # brings Defined and Grammatical together in one place Fancy::Join::Defined Fancy::Join::Grammatical Fun::AstroBody Fun::ConvertFileSize Fun::Numbers Fun::Refreshment Fun::SoundofMusicSong HTML::Attributes HTML::Elements HTML::Forms Random::Alpha Random::Descriptor Random::Food Random::GemMetalJewelry Random::Government Random::Insanity Random::Misc Random::Month Random::Range Random::SciFi Random::Size Random::SpecialDice Random::Thing Random::Time Random::Title Random::Water Random::Body::Function Random::Body::Modification Random::Color Random::Color::Hex Random::Color::VisiBone Random::Name::Pattern Random::Name::Triador Random::RPG::Alignment Random::RPG::Class Random::RPG::Event Random::RPG::Military Random::RPG::Monster Random::RPG::SavingThrow Random::RPG::SpecialAttack Random::RPG::Spell Random::RPG::Weapon Random::RPG::WildPsionics Random::RPG::MagicItem Random::RPG::MagicItem::Giant Random::RPG::MagicItem::Ring::SpellDoubling Random::RPG::World::HighLevelCampaigns::ChronologicalRating Random::RPG::World::HighLevelCampaigns::EcologicalRating Random::RPG::World::HighLevelCampaigns::MagicalRating Random::RPG::World::HighLevelCampaigns::TechnologicalRating Random::RPG::World::WorldBuildersGuidebook::ClimateTerrainSubsistance Random::RPG::World::WorldBuildersGuidebook::Coastlines Random::RPG::World::WorldBuildersGuidebook::CulturalCharaceristic Random::RPG::World::WorldBuildersGuidebook::EarthquakeActivity Random::RPG::World::WorldBuildersGuidebook::GovernmentForm Random::RPG::World::WorldBuildersGuidebook::Hydrology Random::RPG::World::WorldBuildersGuidebook::LandWaterMasses Random::RPG::World::WorldBuildersGuidebook::LocalDistribution Random::RPG::World::WorldBuildersGuidebook::LocalPopulation Random::RPG::World::WorldBuildersGuidebook::LocalTopography Random::RPG::World::WorldBuildersGuidebook::MountainPlacement Random::RPG::World::WorldBuildersGuidebook::MountainSize Random::RPG::World::WorldBuildersGuidebook::Pantheon Random::RPG::World::WorldBuildersGuidebook::PlanetaryTemperature Random::RPG::World::WorldBuildersGuidebook::PlateMovement Random::RPG::World::WorldBuildersGuidebook::PrevailingWinds Random::RPG::World::WorldBuildersGuidebook::Race Random::RPG::World::WorldBuildersGuidebook::RacePosition Random::RPG::World::WorldBuildersGuidebook::RegionalClimate Random::RPG::World::WorldBuildersGuidebook::RegionalDistribution Random::RPG::World::WorldBuildersGuidebook::SeasonalVariations Random::RPG::World::WorldBuildersGuidebook::SettlementPattern Random::RPG::World::WorldBuildersGuidebook::Size Random::RPG::World::WorldBuildersGuidebook::SocialAlignment Random::RPG::World::WorldBuildersGuidebook::TechnologyLevel Random::RPG::World::WorldBuildersGuidebook::VolcanicActivity Random::RPG::World::WorldBuildersGuidebook::WorldHooks Random::RPG::World::WorldBuildersGuidebook::WorldShape RPG::AssetCost RPG::CharacterMutation RPG::InterspeciesAge RPG::Monster RPG::RacialLanguages RPG::WeaponName RPG::Character::AbilityScores RPG::Character::Alignment RPG::Character::AttacksPerRound RPG::Character::Class RPG::Character::HitDice RPG::Character::ProficiencySlots RPG::Character::RealityBubble RPG::Character::WeaponSlots RPG::Character::WizardSkills RPG::Character::GameTables RPG::Character::GameTable::ArmorClass RPG::Character::GameTable::Psionics RPG::Character::GameTable::RogueSkills RPG::Character::GameTable::SavingThrows RPG::Character::GameTable::SpellProgression RPG::Character::GameTable::THAC0 RPG::Character::GameTable::TurningUndead RPG::Spell::List RPG::Spell::Book Util::Abbreviation Util::Columns Util::Convert Util::ExternalLinks Util::FamilyTree Util::Line Util::ListLengths Util::Movie Util::Number Util::People Util::QuoteAttribute Util::Sort Util::TransformName Util::WordFind Util::Data Util::Data::Compare Util::Twitter Util::Twitter::Data Util::Twitter::ListSort Xanth::Character Xanth::Crossbreed # only works if the data is in the module Xanth::Dates Xanth::Family Xanth::LineMagic Xanth::Location Xanth::Novel Xanth::Species Xanth::Util Zodiac::Chinese

Reminder code

my @monsters = map{chomp $_; $_} <$word_find_list>; my @items; for my $monster (@monsters) { push @items, [$monster, { class => 'monster_item' }]; } my @gems = <$gems_file>; chomp @gems; my %alpha_gems = alpha_array(\@gems); for my $gems (keys %alpha_gems) { my @list = @{$alpha_gems{$gems}}; $alpha_gems{$gems} = undef; @{$alpha_gems{$gems}} = map { "$_ ".external_links([['Wikipedia', $_ +, $_],['Google', searchify($_), $_]]) } sort @list; }

is now

my @monsters = map { chomp $_; [$_, { class => 'monster_item' }] } <$w +ord_find_list>; my @gems = map { chomp $_; "$_ ".external_links([['Wikipedia', $_, $_] +,['Google', searchify($_), $_]]) } <$gems_file>; my %alpha_gems = alpha_array(\@gems);


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 and unfinished.

#!/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} );

Laundry day

This code was written for me by atcroft on 2015-03-11.

use strict; use warnings FATAL => qw( all ); use Data::Dumper; $| = 1; $Data::Dumper::Deepcopy = 1; $Data::Dumper::Sortkeys = 1; local $\ = "\n"; my @laundry_loads = ( 'cottons', 'cold water items', 'sheets', 'uniforms', 'clothing of the day' ); my @laundry_tasks = ( 'wash', 'dry', 'fold' ); sub wash { my ( $load, $loads ) = @_; } sub dry { my ( $load, $loads ) = @_; } sub fold { my ( $load, $loads ) = @_; } my @progress = ( undef, undef, undef, ); my %task; foreach my $i ( 0 .. $#laundry_tasks ) { $task{ $laundry_tasks[$i] } = $i; } while ( my $load = shift @laundry_loads or scalar keys %task ) { print ""; foreach my $current_task ( reverse @laundry_tasks ) { if ( not scalar @laundry_loads and not(defined $task{$current_task} and defined $progress[ $task{$current_task} ] ) ) { delete $task{$current_task}; next; } if ( defined $progress[ $task{$current_task} ] ) { my $current_load = $progress[ $task{$current_task} ]; my $activity = qq{$current_task $current_load}; print $activity; if ( $current_task eq q{wash} and defined $progress[ $task{$current_task} ] ) { } if ( $current_task eq q{dry} and defined $progress[ $task{$current_task} ] ) { } if ( $current_task eq q{fold} and defined $progress[ $task{$current_task} ] ) { if ( $current_load =~ /sheets|uniforms|clothing of the day/ ) { my $new_load = $current_load eq 'sheets' ? 'laundry' : $current_load; print "put away $new_load"; } if ( $current_load eq 'sheets' ) { print 'vacuum the house'; print 'make the bed'; } if ( $current_load eq 'uniforms' ) { print 'take showers'; } pop @progress; } } } if ( defined $load ) { unshift @progress, $load; } else { unshift @progress, undef; } }

The output is...

$ perl 2>&1 wash cottons dry cottons wash cold water items fold cottons dry cold water items wash sheets fold cold water items dry sheets wash uniforms fold sheets put away laundry vacuum the house make the bed dry uniforms wash clothing of the day fold uniforms put away uniforms take showers dry clothing of the day fold clothing of the day put away clothing of the day

Misc code

#!/usr/bin/perl use strict; use warnings FATAL => qw( all ); use Getopt::Long; use lib '../../files/lib'; use Util::Movie qw(movie); use Util::Convert qw(filify); use Util::Data qw(data_file); use Util::Sort qw(article_sort); GetOptions( 'open' => \my $open ); my $movies = movie('data'); local $\ = "\n"; for my $movie (sort { article_sort($a->{'title'}, $b->{'title'}) } val +ues %$movies) { my $title = $movie->{'title'}; next if ($movie->{'media'} ne 'tv' || (($movie->{'end year'} && $mov +ie->{'end year'} ne 'tbd') || !$movie->{'end year'})); next if $title =~ /Awards/; print $title; next if !$open; my $filename = filify($title); my $file = data_file('Movies/Episode_lists',"$filename.txt"); system("xdg-open", $file) == 0 || warn "Can't open $file"; }