Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2017-03-29 02:32 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (343 votes). Check out past polls.