go ahead... be a heretic | |
PerlMonks |
jZed's scratchpadby jZed (Prior) |
on Jun 02, 2004 at 00:21 UTC ( [id://358896]=scratchpad: print w/replies, xml ) | Need Help?? |
Web Host woesme : I have accounts A and B, I want a third account C them : ok, we added C and deleted B me : no, I need B them : ok, we restored B and deleted A me : no, I need A them : ok, we restored A but not A's ability to edit files me : no, A needs to be able to edit files them : ok, we restored A's ability to edit all files except those starting with a dot like .htaccess me : nevermind, I'll change that myself. My Mason apache.conf
For hacker
For bhorton63
For hacker
For perllove
For Bart
CSS QuizWhat color is bar?
For grant123
A simple Mason server
For farhan
CGI.pm sticky forms
Inheritance in JavaScript
DBD::CSV addition function
SQL::Translator - trying to get column defs in a structureThe code below produces:"ERROR (line 1): Invalid statement: Was expecting create, or comment on ..."
Text::CSV_XS for demerphq
utf-8
SELECT foo, bar
FROM baz JOIN qux
WHERE quimble = ?
AND bop = ?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>MCB Bookmarks</title>
<base target="main">
<link rel="stylesheet" href="mcb.css" type="text/css">
</head>
<body>
<a href="http://www.perlmonks.org/?node=Newest%20Nodes">Newest Nodes</
+a><br />
<a href="http://www.perlmonks.org/?node=Recently%20Active%20Threads">R
+ecently Active Threads</a><br />
<a href="http://www.perlmonks.org/?node_id=358896">View Scratchpad</a>
+<br />
<a href="http://www.perlmonks.org/?displaytype=edit;node_id=358896">Ed
+it Scratchpad</a><br />
<a href="http://tinymicros.com/pm/">PM Stats</a><br />
<a href="http://www.perlmonk.org/~mojotoad/cbs/">CB Stats</a><br />
<a href="http://www.perlmonks.org/?displaytype=raw;xmlstyle=clean;node
+=XP XML Ticker">XP</a><br />
</body>
</html>
#!/usr/bin/perl -w
use strict;
use DBI::Shell;
my $str=" /format box
DROP TABLE IF EXISTS x;
CREATE TABLE x (num INT, let CHAR);
INSERT INTO x VALUES (1,'a');
INSERT INTO x VALUES (2,'b');
SELECT * FROM x;
";
open STDIN, '<', \$str;
DBI::Shell->new('--batch','dbi:DBM:')->run;
use Text::CSV_XS;
$c = Text::CSV_XS->new; # use default separator,delimite
+r,escape
or $c = Text::CSV_XS->new(%attr); # set your own separators,delims
+,escapes
$c->open_file($filename) # open a CSV file
$c->open_string($string) # open a CSV string
@row = $c->fetchrow_array # fetch one row into an array
$row = $c->fetchrow_hashref # fetch one row into a hashref
$table = $c->fetchall_arrayref # fetch all rows into an array
+of arrays
$table = $c->fetchall_hashref($key) # fetch all rows into a hashref
$c->write_row( @array ) # insert a row from an array of
+ values
$c->write_table($filename,$arrayref) # create a CSV file from an ar
+rayref
$c->write_table($filename,$hashref) # create a CSV file from a hash
+ref
$c = open_file( $filename ); # loop through a file fetching
+hashrefs
while(my $row = $c->fetchrow_hashref){
if($row->{$column_name} eq $value){
# do something
}
}
There are two interfaces to this module, the new interface (shown abov
+e) has convenient shortcuts, the older interface is for backwards com
+patibility for previous users. B<Please note>: in the new interface
+binary mode defaults to true, whereas in the older interface it defau
+lts to false. This means that the new interface methods will, by def
+ault, handle embedded newlines and binary characters, whereas if you
+want that behaviour with the old methods, you must manually set binar
+y=>1 in the call to new().
The char used for escaping certain characters inside quoted fields,
by default the same character as the quote_char. (C<">).
If quote_char is specified in the call to new() and escape_char is not
+,
the escape_char becomes the same as the specified quote_char. A liter
+al
value for the quote character thus becomes "" if quote_char is " and '
+' if
quote_char is ' and just " or ' if quote_char is specified as undef.
+However
if the escape_char is specified in the call to new() as something else
+,
that value will be used.
These examples should all parse properly as a single CSV field:
$csv = Text::CSV_XS->new();
$csv->parse(q["Joe ""the giant"" Jackson"]) or die $csv->error_input
+;
$csv = Text::CSV_XS->new({ quote_char=>q['] });
$csv->parse(q['Joe ''the giant'' Jackson']) or die $csv->error_input;
$csv=Text::CSV_XS->new({quote_char=>undef});
$csv->parse(q[17" monitor]) or die $csv->error_input;
$csv = Text::CSV_XS->new({ quote_char=>q['], escape_char=>q[\\]});
$csv->parse(q['Joe \'the giant\' Jackson']) or die $csv->error_input;
$csv = Text::CSV_XS->new({ escape_char => q[\\] });
$csv->parse(q["Joe \"the giant\" Jackson"]) or die $csv->error_input;
#!perl -w
use strict;
use Text::xSV;
my($cols,$data) = ( ['Name','City','Num'], [] );
for my $num(0..4999) {
push @$data, ["myself\nme","Portland,Oregon",$num];
}
create_xSV('test.xSV',$cols,$data);
read_xSV('test.xSV');
sub create_xSV {
my($fname,$cols,$data) = @_;
my $csv = Text::xSV->new( filename => $fname
, header => $cols
);
$csv->print_header();
$csv->print_row(@$_) for @$data;
}
sub read_xSV {
my $fname = shift;
my $csv = Text::xSV->new( filename=>$fname, close_fh=>1);
$csv->read_header();
my $count=0;
while ($csv->get_row()) {
print "$count ...";
my @row = $csv->extract(qw(Name City Num));
die 'Bad Read' unless "@row" eq "@{$data->[$count++]}";
}
print "Done!";
}
__END__
#!/usr/bin/perl -w
use strict;
use vars qw/ $mods $files %ismod/;
use FindRequires;
use DBI;
my $dbh=DBI->connect('dbi:DBM(RaiseError=1):');
recurse($mods->[0],'');
sub recurse {
my($mod,$insert)=@_;
return unless $mod;
print "$insert$mod\n";
$insert .= ' ';
for my $modfile(@{$files->{$mod}}) {
recurse($modfile,$insert);
}
}
package FindRequires;
# by [theorbtwo]
use warnings;
use strict;
my $reallibimport;
use lib;
BEGIN {
$reallibimport = \&lib::import;
}
{
no warnings 'redefine';
sub lib::import {
$reallibimport->(@_);
($INC[0], $INC[1]) = ($INC[1], $INC[0]);
}
}
unshift @INC, sub {
my ($self, $lookingfor) = @_;
# != works if it is OK, but if it's not, this is probably a string
+.
# Use ne to avoid warning, even though we're about to die.
if ($INC[0] ne $self) {
die "\@INC got messed up";
}
# return if $lookingfor =~ /\.al$/;
if ($lookingfor =~ /\.pm$/) {
$lookingfor =~ s![:/]!::!g;
$lookingfor =~ s/\.pm$//;
}
my ($filename, $line,@mods);
my $level=0;
while (1) {
(undef, $filename, $line) = caller($level);
last unless $filename =~ /^\(eval/;
$level++;
}
my $modfile = $filename;
for my $i(@INC) {
$modfile =~ s!$i!!;
}
if ($modfile =~ /\.pm$/) {
$modfile =~ s![:/]!::!g;
$modfile =~ s/\.pm$//;
}
push @{$main::mods}, $modfile unless $main::ismod{$modfile}++;
push @{ $main::files->{$modfile} }, $lookingfor;
# print "$lookingfor required at line $line of [$modfile] $filenam
+e\n";
};
1;
#!perl -w
use strict;
use DBI;
my $AoA = [ [qw(1 Hacker)]
, [qw(2 Perl)]
, [qw(3 Another)]
, [qw(4 Just)]
, [qw(5 junk)]
];
my $dbh=DBI->connect('dbi:AnyData(RaiseError=1):');
$dbh->ad_catalog('t','ARRAY',$AoA,{cols=>'id,phrase'});
print join ' ', @{ $dbh->selectcol_arrayref("
SELECT phrase FROM t WHERE phrase <> 'junk' ORDER BY id DESC
")};
updated 2004-09-24: brand new versioning per tye's suggestions, click the help button in the demo to read how it works The scenario: Someone in the chatterbox posts a snippet in the communal scratchpad ... other monks edit the communal scratchpad. This would be a sort of primitive whiteboard, a one-page wiki, where monks could collaboratively work on a problem they were discussing in the chatterbox. It wouldn't be too useful for simple things like someone asking for help spotting a typo in a snippet but could be productive for exploring TIMTOWTDI and for group-developing solutions to problems. Please give the demo a try! My Mandatory Registration Complaint LetterMandatory registration is a terrible idea. It violates my privacy (I don't care what you do or don't use your database for, I don't want to be in it); it exposes me to spam and identity theft (yes, maybe your database is protected, but if every content site on the web starts using mandatory registration, one of them won't be); it's worthless since anyone can submit fake info (yes I could do that too, but frankly I don't want to).I used to visit ___ daily. Never again though. my current hardware other remote computers | cable modem | wap/nat/router -- wifi -- other local computers / \ / \ cat5 cable wifi / \ Computer #1 Computer #2 | \ / | VGA/USB VGA/USB | \ / | KVM Switch | / | \ | / PS2->USB \ | / | \ DVI VGA PS2 USB \ / | | Monitor Keyboard Mouse \ | / \ | / zone of error (me) | my chair Questions for the Debian/VMware cluefull:I am getting a new Dell 3.2gHz pentium 4 with 1gig memory, 250gig storage, WinXP professional installed. I'd like to:
DBM::Deep
A Generic Inside-Out Wrapper
Re: Tutorial: Introduction to Object-Oriented Programming |
|