Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Narveson's scratchpad

by Narveson (Chaplain)
on Mar 06, 2008 at 20:55 UTC ( [id://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
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-16 18:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found