I need to store user preferences...
Currently, there are only two user preferences and these are stored as fields in the User table of the database. However, the number of preferences is going to increase. I guess there will be around 20 or so eventually. Experience suggests that most users won't change most of their preferences from the default setting. Therefore, I don't really want to add all the preferences to the User table when nearly all of them will be set to the default values.
I could implement the preferences in the database with an EAV model. But I wondered if Perl's core Storable might be a better solution.
I've not used Storable before so I'd appreciate the monastic wisdom about any issues I might face using Storable generally and it's suitability for this specific application...
|
Hello everyone
I've written a subroutine that replaces a handful of Windows-1252 characters within a UTF8 string with HTML entities. Basically changing ' … ' to ' … '. This code works fine on its own outside of a function, but the regex fails within if( $strng =~ /\xE2/ ) { it doesn't "see" \xE2. Something is changing in $clmnVal once it's passed to the subroutine and I don't understand why or how to fix it.
my $clmnVal = 'La Conner….Shelter Bay Fee Simple';
if ( grep $_ eq $clmnNm, @smblClmns ) {
$clmnVal = smblRpr( $clmnVal );
}
sub smblRpr {
my $strng = $_[0];
my %smblCO = (
'xE2' => {
'\xE2\x80\x9A' => '‚',
'\xE2\x80\x9C' => '“',
'\xE2\x80\x9D' => '”',
'\xE2\x80\x9E' => '„',
'\xE2\x80\x93' => '–',
'\xE2\x80\x94' => '—',
'\xE2\x80\x98' => '‘',
'\xE2\x80\x99' => '’',
'\xE2\x80\xA0' => '†',
'\xE2\x80\xA6' => '…',
'\xE2\x84\xA2' => '™'
},
'xC2' => {
'\xC2\xA9' => '©',
'\xC2\xAE' => '®',
'\xC2\xB1' => '±',
'\xC2\xBC' => '¼',
'\xC2\xBD' => '½',
'\xC2\xBE' => '¾',
'\xC2\xB0' => '°'
}
);
if( $strng =~ /\xC2/ ) {
my $C2 = $smblCO{'xC2'};
while ( my($bytes, $replc) = each %$C2 ) {
if( $strng =~ /$bytes/ ) {
$strng =~ s/$bytes/$replc/g;
}
}
}
if( $strng =~ /\xE2/ ) {
my $E2 = $smblCO{'xE2'};
while ( my($bytes, $replc) = each %$E2 ) {
if( $strng =~ /$bytes/ ) {
$strng =~ s/$bytes/$replc/g;
}
}
}
return $strng;
} # end smblRpr
|
Thanks, Tux, for Text:CSV. It keeps coming in handy both directly and indirectly.
I have a question about escaped quotes in incoming files. I would have expected the output for the three data lines below to be identical, but the second line misses the escaped single quote. Is an escaped single quote some kind of faux pax or even a mistake within the data or would it be one in something which Text::CSV draws on?
#!/usr/bin/perl
use Text::CSV qw(csv);
use strict;
use warnings;
my $csv = Text::CSV->new ({ binary => 1, auto_diag => 1 });
my $o = \*STDOUT;
# Read/parse CSV
while (my $row = $csv->getline (\*DATA)) {
my @selected = ( splice(@{$row}, 0, 2), splice(@{$row}, -6, 2) );
$csv->say($o, \@selected);
}
exit(0);
__DATA__
8, 9, NULL, 'Filler', '555-999', '77:88', 0, 0, 0, 0
8, 9, NULL, 'Filler', '555-999', '77:88', 'A \' B , C', 0, 0, 0
8, 9, NULL, 'Filler', '555-999', '77:88', 0, 0, 0, 0
This is based on something found in the wild.
|
O'Rielly cookbook suggests:
SELECT db1.artist.name, db2.painting.title
FROM db1.artist INNER JOIN db2.painting
ON db1.artist.a_id = db2.painting.a_id;
which is similar to my application requirements. I can use DBI of course to connect to db1. And make ANOTHER connection to db2. But then I need to "prepare" - which needs a database connection. How can I create a handle connected to TWO databases as this statement requires? Maybe:
$db1->$db2->prepare( $query );
Gracias
|
Is there an easy way to find out when a feature or keyword was introduced to Perl?
In other words, which version introduced it...
I have a module that uses pos, a keyword I infrequently use. How can I find out when this, or any other keyword, was introduced so I can set the minimum required Perl version?
Obviously I could go through each delta until I find it but that seems rather tedious...
|