Want Mega XP? Prepare to have your hopes dashed, join in on the: poll ideas quest (11840 days remain)
I am trying to insert/update/retrieve a data structure in MySQL. My question is what do I pass in as the value when using bind_param? I am inserting it into a BLOB data type. The data structure is an array of objects (hash refs).
So is it possible to do this or do I have to serialize/deserialze the structure first?
Thanks, Kenny
my $text = "pomperipossa"; if ($text eq "pomperipossa") { .. }
if ($text eq "pomperipossa") { .. }
if ($text eq 'pomperipossa') { .. }
This will ensure, hopefully, consistant html and prevent problems during any future processing.
What do you reckon?
Sorry to bother you. I need some help on my code. I have an input file named "origin8.txt" which holds 200 short sequences of width 8. My code is to use each short sequence from "origin8.txt" as a template to generate 100 short sequences of the same width and store them in a txt file A (A stands for short_sequences8_[$y].txt in my code).
Then the code will read 100 short sequences from the txt file A and 100 long sequences of width 200 from a txt file B , and then replaced a substring of each long sequence using each short sequence. This code will lead to two txt files C and D. File C will hold 100 replaced long sequences.
In other words, I want to input "origin8.txt" to get 200 File C (C stands for output8_[$y]2.txt in my code).
My code can generates 200 File D but each of them holds nothing. So I guess the problem is caused by a failure of passing the data to a subroutine named "make_file".
Can anybody suggest me how to modify that? Thank you very much in advance!
Sincerely,
Alex
My code:
Edit by castaway - added code tags
<html> <body> <table align="center"> <tr><td>Name</td><td>Blah</td></tr> <tr><td>bill</td><td>fdagdfg</td></tr> <tr><td>ted</td><td>sdfsdf</td></tr> </table> </body> </html>
#!/usr/bin/perl use warnings; use strict; use HTML::TableExtract; #my $te = HTML::TableExtract->new ( depth => 1, count => 2 ); my $te = HTML::TableExtract->new ( attribs => { align => 'center' } ); print "Start\n"; my $data; { local( $/, *FILE); open FILE, "blah.html" or die "Could not open file , $!\n"; $data = <FILE>; close (FILE); } print $data; $te->parse($data); print "table stuff:\n"; foreach my $ts ( $te->tables ) { print "Table\n"; foreach my $row ( $ts->rows ) { print "R ", join(',', @$row), "\n"; } }
print function(); # prints the string that function returns.
funtion(); # prints string since not assigned $value = funtion(); # Does not print. $value holds the return string.
Is this possible?
#!/usr/bin/perl use strict; use warnings; use SQL::Statement; my $statement = qq~CREATE TABLE test( ID int not null, Spalte1 varchar(255), Spalte2 int, Spalte3 int, Spalte4 int, Spalte5 blob, Spalte6 varchar(33), primary key(ID), )~; my $parser = SQL::Parser->new(); my $stmt = SQL::Statement->new($statement,$parser);
I'm looking for criticism of my regular expression that looks for a number to be >= 0 and < 1 (i.e. 0, 0.00001, and .99999 are OK but 1, -0.00001, and -1 are NOT OK). I'm using the RE to untaint a number from a CGI form. The regex seems to work and is based on a regex in PerlFaq4 that matches decimal numbers. Here is the code in my CGI script that handles the untainting.
my ($num) = $_num =~ /^(0(\.\d+)?|\.\d+)$/;
Please comment on the accuracy and if there is a better way to do it.
Thank you,
lupey
<bold>Update</bold> Thank you everybody for your suggestions. I seem to like tlm's answer the best. I didn't realize that I could separate tainting from checking the numerical properties of a scalar.
This is an expansion of something in my use.perl journal where I explained how logic programming works. What follows is a brief and over-simplified overview of what lies at the core of automated deduction and logical inference systems the world over. In short, it's at the heart of many AI projects. Even though it's one programming paradigm that's not natively supported by Perl, it's surprisingly simple.
If the following interests you, check out AI::Prolog, Logic or Language::Prolog::Yaswi. If you'll be at OSCON, I'll be talking about the first module.
I was looking at Luke Palmer's Logic module on the CPAN and it got me to thinking a bit about logic programming in general, as opposed to the specific implementation of Prolog I've been focusing on. To implement logic programming, you basically have to implement two things, backtracking and unification.
You already understand backtracking from regular expressions. If you fail to find a match (in our case, if we fail to unify two data structures), back up to the last point in the string (stack) where we can make a different decision and try again. It's pretty straightforward.
Unification is also fairly simple. You know it from makefiles or SQL, but we'll look at logic programming in particular. Imagine that you have two five element lists:
( 1, 2, undef, undef, 5 ) ( 1, 2, 3, 4, undef )
Imagine that undef means "unknown". We can unify those two lists because every element that is known corresponds in the two lists. This leaves us with a list of the integers one through five.
However, what happens if the last element of the first list is unknown?
( 1, 2, undef, undef, undef ) ( 1, 2, 3, 4, undef )
We can still unify the two lists. In this case, we get the same five element list, but the last item is unknown.
Logic programming works by pushing these lists onto a stack and walking through the stack and seeing if you can unify everything (sort of). But how to unify from one item to the next? We assign names to the unknown variables and see if we can unify them. When we get to the next item in the stack, we check to see if any named variables have been unified. If so, we unify the individual variables prior to trying to unify items with their counterparts in our lists.
Thats a bad explanation, so here's how it works. Imagine the following "knowledge base" of lists:
A famous Portuguese Perl hacker, author of the recent mad Acme::AsciiArt2HtmlTable module and I have been pondering the best way to classify the shapes in (the also mad) Acme::EyeDrops module to make them more amenable to searching and selecting.
You see, he wants, for example, to select from the many shapes available, only the faces of Perl celebrities.
I'm struggling a bit, not having much experience in this field. My first instinct was to look at the web site of a famous British Perl hacker to learn how to search his magnificent photo collection. acme seems to use some sort of keyword search, but when I typed in "perl celebrity" I was told to "Please come back later" in eight different languages.
My next instinct was to steal an idea I remember from Subversion, that of allowing arbitrary "properties" (key-value pairs), aka metadata, to be associated with a file.
Recently I realized that I was only considering attending sessions in the Perl track for OSCON.
What sessions, outside the Perl track, interest you?
For a more in depth tutorial on the topic The Bad, the Ugly, and the Good of autovivification may be of interest. Cheers :)
use strict; use warnings; use Test::More qw(no_plan); use Data::Dumper; my %hash = (a => 'a', b => 'b'); ok( ! exists($hash{c}), "hash -- c doesn't exist"); ok( ! exists($hash{c}), "hash -- c still doesn't exist"); ok( ! defined($hash{c}), "hash -- c not defined either"); my $hashref = { %hash }; ok( ! exists($hashref->{c}), "hashref -- c doesn't exist"); ok( ! exists($hashref->{c}), "hashref -- c still doesn't exist"); ok( ! exists( $hashref->{c}->{d} ), "hashref, deeper -- c->{d} doesn't exist"); ok( ! exists( $hashref->{c}->{d} ), "hashref -- c->{d} still doesn't exist"); ok( ! exists($hashref->{c}), "hashref -- c still doesn't exist"); #fails. c does + exist. ok( ! defined($hashref->{c}), "hashref -- c still doesn't exist"); #fails. c is +an empty hashfref, which is something other than undef.
This code is a part way point in the development of a tool to perform some directory and file management. At this stage it captures information required for the management from the user. The information gathered to controlled by a configuration file. This seems a generally usefull task so the code is offered here for other monks to make what use they wish of it.
The configuration files is comprised of lines containing a parameter name, and optional default value, and a label. For example:
If the default string contains names of other parameters, the default value for the parameter will be generated at run time as the other parameters are updated.
The work of the task goes in sub CreateProject (which is an appropriate name for my initial task :).
I have been waiting for quite some time for an API into iTunes so that I could control it from my keyboard or X10 remote controls and they released an SDK awhile back that I just discovered.
I know that you Mac users have Mac::iTunes but Windows users can now control iTunes natively.
James Craig has done some excellent work with the SDK and I borrowed the "SearchiTunesWinForSong" routine from him.
I am going to come up with a more complete library of functions as time allows but wanted to get this out so folks know that they can start hacking away at iTunes.
Enjoy, mdog
READMORE tags added by Arunbear