Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
go ahead... be a heretic
 
PerlMonks  

Lady_Aleena's scratchpad

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

---File--- placeholder names|foo,bar,baz,qux,quux,garply,waldo,fred,plugh,xyzzy,t +hud Greek alphabet|alpha,beta,gamma,delta,epsilon,zeta,eta,theta,iota,kapp +a,lambda,mu,nu,xi,omicron,pi,rho,sigma,tau,upsilon,phi,chi,psi,omega numerical prefixes|yocto,zepto,atto,femto,pico,nano,micro,milli,centi, +deci,deka,hecto,kilo,mega,giga,tera,peta,exa,zeta,yotta numerical abbreviations|y,z,a,f,p,n,,m,c,d,da,h,k,M,G,T,P,E,Z,Y order|primary,secondary,tertiary,quaternary,quinary,senary,septenary,o +ctonary,novenary,denary polytope suffixes|gon,hedron,choron,teron polytope elements|vertex,edge,face,cell,hypercell music scales|Ionian,Dorian,Phrygian,Lydian,Mixolydian,Aeolian,Locrian evildead|Bruce Lorne Campbell,Sam Raimi,Rob Tapert,Ted Raimi,Scott Spi +egel,Ellen Sandweiss,Betsy Baker,Teresa Tilly,Hal Delrich DeLuise|Dom DeLuise,Carol Arthur,Peter DeLuise,Anne Marie Loder,David +DeLuise,Michael DeLuise taste sensations|bitter,salty,sour,sweet,umami ---end File--- # Written with rindolf in #perlcafe on freenode; golfed with the help +of [GrandFather] of PerlMonks. # Changed to accept named parameters to make it prettier to use. # The parameters are file, headings, and a very optional sort. sub get_hash { my %opt = @_; my $file = $opt{file} ? $opt{file} : data_file; open(my $fh, '<', $file) or die("can't open $opt{file} $!"); my %hash; while (my $line = <$fh>) { chomp $line; die "This file is not for get_hash!" if $line =~ /no get_hash/i; my @values = split(/\|/,$line); my $n = 0; $hash{$values[0]}{sort_number} = $. if $opt{sorted}; for my $heading (@{$opt{headings}}) { $hash{$values[0]}{$heading} = defined($values[$n]) ? $values[$n] + : ''; ++$n; } } return %hash; } my %hash = get_hash( 'file' => 'File', headings => [qw(list values)]); use Data::Dumper; print Dumper(\$hash{'evildead'));

Notes to self

  • If one changes a variable, check the whole script for that variable to make sure that the results will be as expected.
  • From 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.
  • 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.
  • 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)
  • From ambrus: In general, use magic only when normal solutions aren't enough.
  • From 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
  • 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.

To do

  • Install my own perl

Things I should get a grip on

  • objects
  • testing
  • SQL
  • version control
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2014-04-17 01:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (437 votes), past polls