Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Narveson's scratchpad

by Narveson (Chaplain)
on Mar 06, 2008 at 20:55 UTC ( #672586=scratchpad: print w/ replies, xml ) Need Help??

Golf challenge: print the numbers from one to a hundred in English (each on its own line). (Yes, I know I could save a few strokes with say if I had Perl 5.10.)

$,=$/;print@a=qw[one two three four five six seven eight nine],qw[ten eleven twelve],(map{s/ree/ir/;s/ve$/f/;s/t$//;$_.'teen'}@b=@a[2..8]),(map{s/u//;$t=$_.'ty',map{"$t-$_"}@a}$w='twen',@b),'one hundred'

A quine that tries to follow some of the guidelines in Perl Best Practices:

my $generator = <<'END_GENERATOR'; my $self = <<"END_SELF"; my \$generator = <<'END_GENERATOR'; ${generator}END_GENERATOR eval \$generator; END_SELF print $self; END_GENERATOR eval $generator;

DBI snippet: read tab-separated data and insert it into a database table.

use DBI; my ($connect_string, $table, @columns) = @_? @_: @ARGV; my $dbh = DBI->connect( "dbi:ODBC:$connect_string", undef, undef, { RaiseError => 1 }, ); my @placeholders = map {'?'} @columns; my $insert_statement = do { local $" = "\n, "; "Insert into $table (@columns) values (@placeholders)"; }; my $sth = $dbh->prepare($insert_statement); while (<>) { chomp; my @values = split /\t/; $sth->execute(@values); }

FindBin and use lib for an environment I work in

my $root; BEGIN { use FindBin; ($root) = $FindBin::Bin =~ m{ (.* racine) [\\/] }imsx; } use lib "$root/Jobs/Perl/lib";
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 perusing the Monastery: (10)
As of 2014-12-20 14:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (96 votes), past polls