scratchpad
serf
<p>I have been given a new Windows 7 desktop at work and would like to have Perl doing stuff.</p>
<p>I installed Strawberry Perl, which I usually use, and went from there...</p>
<p>One of the things I wanted to be able to do was write GUI applications in Perl, and found to my dismay that a lot of the tools I tried would not build OOTB.<p>
<p>I have found three that do, so I thought I'd share them here in case anybody else is in the same situation.</p>
<p>Installed OK:</p>
<ul>
<li><a href="http://www.prima.eu.org/">Prima</a> - Very small and light</li>
<li><a href="http://www.wxperl.it/">wxPerl</a></li>
<li><a href="http://search.cpan.org/~asg/XUL-Gui-0.63/lib/XUL/Gui.pm">XUL::Gui</a> - doesn't do what I need</li>
</ul>
<p>Failed to install:</p>
<ul>
<li>Tk (crashed 3 times then failed to install)</li>
<li>Win32::GUI <a href="http://www.perlmonks.org/?node_id=1004548">this may help</a></li>
<li><a href="http://gtk2-perl.sourceforge.net/">Gtk2</a></li>
<li>Qt - I wasn't up for having to install <a href="http://qt-project.org/downloads">525MB</a> of libraries to get a little GUI app working!</li>
</ul>
<p><a href="http://en.wikipedia.org/wiki/List_of_widget_toolkits">read this</a></p>
<hr />
<h2>Why does Deparse do this?</h2>
<p>Given:</p>
<code>
#!/usr/bin/perl
use warnings;
use strict 'refs';
use Data::Dumper;
my(@array1) = (1, 2, 3, 4);
my(@array2) = ('a', 'b', 'c', 'd', 'e', 'f');
</code>
<p>If I have this:</p>
<code>
push my @array3, @array1, @array2;
</code>
<p>I get:</p>
<code>
Parentheses missing around "my" list at try.pl line 12.
</code>
<p>If I do:</p>
<code>
push (my @array3, @array1, @array2);
</code>
<p>it doesn't complain...</p>
<p>but if I run the code through <code>-MO=Deparse</code></p>
<p>It changes the:</p>
<code>
push (my @array3, @array1, @array2);
</code>
<p>back to:</p>
<code>
push my @array3, @array1, @array2;
</code>
<p>!!!</p>
<hr />
<p>I'm trying to get the values out of an enum field in MySQL</p>
<p>At the moment I have:</p>
<code>
#!/usr/bin/perl
use warnings;
use strict;
use DBI;
my $db_host = "mysql";
my $db_port = "3306";
my $db_user = 'web-user';
my $db_pass = 'pass4monks';
my $db_name = 'order_dev';
my $dbh = DBI->connect(
"DBI:mysql:database=$db_name;host=$db_host;port=$db_port",
$db_user, $db_pass
) || die ("ERROR: Unable to connect to '$db_name': $DBI::errstr" );
my ($enum_qry) = $dbh->prepare(
"SELECT column_type
FROM information_schema.columns
WHERE table_name = 'orders' AND column_name = 'request_status'
LIMIT 1;"
);
$enum_qry->execute;
my $enum_ref = $enum_qry->fetchrow_hashref;
(my $enum_types = $$enum_ref{'column_type'}) =~ s/^enum\((.*)\).*/$1/;
foreach my $enum_type ( eval $enum_types ) {
print qq[<option value="$enum_type">$enum_type</option>\n];
}
</code>
This can be tested without the DB stuff using:
<code>
my $enum_types = "'On Order','Waiting, Pending Payment','Dispatched','Cancelled','Renewal','Amend\'ed'";
# NB: one value has a , in it and another a ' just to make this challenging... ;-)
foreach my $enum_type ( eval $enum_types ) {
print qq[<option value="$enum_type">$enum_type</option>\n];
}
</code>
<p>Consensus is that [doc://eval] should be spelled 'evil' and should be evoided where possible...
<p>[Anno] wrote this <code>//g</code> syntax which works fine:</p>
<code>
while ( $enum_types =~ m/('(.*?)'|([^']*?))($|,\s*)/g ) {
my $match = $3 || $2;
print qq[<option value="$match">$match</option>\n] if $match;
}
</code>
<p>I'm wondering what syntax I'd need to replace the [doc://eval] using [doc://split]...</p>
<p>The closest I have at the moment is:</p>
<code>
#!/usr/bin/perl
use warnings;
use strict;
my $enum_types = "'On Order','Waiting, Pending Payment','Dispatched','Cancelled','Renewal','Amen'ded'";
foreach my $enum_type ( split /(?:^'|','|'$)/, $enum_types ) {
print qq[<option value="$enum_type">$enum_type</option>\n];
}
</code>
<p>But that also gives me the ^ as a value:</p>
<code>
$ ./try.pl
<option value=""></option>
<option value="On Order">On Order</option>
<option value="Waiting, Pending Payment">Waiting, Pending Payment</option>
<option value="Dispatched">Dispatched</option>
<option value="Cancelled">Cancelled</option>
<option value="Renewal">Renewal</option>
<option value="Amen'ded">Amen'ded</option>
</code>
Any suggestions?
<hr />
Read between the lines... ^^^
<hr />
In the description of "Custom Node Title Definition" in [id://450961] it says "Don't use [ nor ]"</p>
<p>I think "Do not use X nor Y" is a double negative where it is not intended...</p>
<p>"Don't use X ... Y" is the same as "Do not use either X or Y" ("Do not use neither..." would be a double negative and incorrect)</p>
<p>The "or" works like a comma in a list of things that have been negated by the "not" in Don't.</p>
<p>It should either be "Use neither X nor Y" or "Don't use X or Y".</p>
<p>Further reading:</p>
<ul>
<li>[http://www.bartleby.com/64/C001/040.html|bartleby: nor]</li>
<li>[http://www.phrases.org.uk/bulletin_board/25/messages/897.html]</li>
</ul>
<hr />
Efficient use of space on multiple CDs
<ul>
<li>[http://snippets.dzone.com/posts/show/8357]</li>
</ul>
<hr />
Compiling modules for ARM:
<ul>
<li>[http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/]</li>
<li>[http://search.cpan.org/src/NWCLARK/perl-5.8.8/Cross/README]</li>
<li>[id://590383]</li>
</ul>
<hr />
<code>
my $command = '/usr/local/bin/program_with_multiline_output';
chomp(my(@output) = `$command`);
my $output = join($/, grep(/./, @output));
my $returned = $? >> 8;
print "Returned: [$returned]\n";
print "Message: [$output]\n";
</code>
<hr />
<code>
and all is quiet...
</code>
[link://?node_id=3989&BIT=search term|search term] [link://?node_id=3989&BIT=search term|search term]
If you have a look at [link://?node_id=3989&BIT=Ananymous|Super Search:Ananymous]
<br />[id://596792]
<br />[id://96858]