If
you have a question on how to do something in Perl, or
you need a Perl solution to an actual real-life problem, or
you're unsure why something you've tried just isn't working...
then this section is the place to ask.
However, you might consider asking in the chatterbox first (if you're a
registered user). The response time tends to be quicker, and if it turns
out that the problem/solutions are too much for the cb to handle, the
kind monks will be sure to direct you here.
Not really a question. Well, I did ask this question around 3 or so years ago, and I was finally able to figure it out - how to connect to perl with JDBC. One challenge I found was that the documenetation for modern databases was very sparse. I'm including directions here- in case any one runs into this problem.
Perl + JDBC + Trino End-to-End Example
1. Prerequisites
Strawberry Perl with DBI and DBD::JDBC modules installed.
Java Proxy JAR (from DBD::JDBC) running:
java -jar jdbc_bridge.jar -port 12345
Trino JDBC Driver (trino-jdbc-*.jar) in your CLASSPATH.
2. Certificate Setup (Optional SSL)
If your Trino instance requires a trusted connection:
Convert your .crt file to .jks (Java KeyStore):
keytool -import -trustcacerts -alias trino -file your_cert.crt -keystore truststore.jks -storepass changeit
Then use the truststore.jks with your Java command if needed:
java -Djavax.net.ssl.trustStore=truststore.jks -Djavax.net.ssl.trustStorePassword=changeit -jar jdbc_bridge.jar -port 12345
3. Perl Script: trino_connect.pl
use strict;
use warnings;
use DBI;
# -- Your credentials
my $user = "svc-ndevfcollect";
my $password = "yourPasswordHere!"; # Use secure storage in productio
+n
# -- JDBC URL to Trino (443 confirmed)
my $url = "jdbc:trino://query.comcast.com:443?SSL=true&catalog=dx";
# -- JDBC bridge connection (localhost to Java proxy)
my $dsn = "dbi:JDBC:hostname=localhost;port=12345;url=$url";
# -- Optional: Print connection hash for debugging
my %conn_attrs = (
RaiseError => 1,
jdbc_user => $user,
jdbc_password => $password,
jdbc_catalog => "dx", # Change as needed
);
use Data::Dumper;
print Dumper(\%conn_attrs);
# -- Connect to Trino
my $dbh = DBI->connect($dsn, undef, undef, \%conn_attrs)
or die "Failed to connect: $DBI::errstr";
print "Connected successfully!\n";
# -- Run sample query
my $sth = $dbh->prepare("SELECT current_user");
$sth->execute();
while (my @row = $sth->fetchrow_array) {
print "User: $row[0]\n";
}
$sth->finish();
$dbh->disconnect();
4. Launch Instructions
Run your Java proxy:
java -jar jdbc_bridge.jar -port 12345
Run the Perl script:
perl trino_connect.pl
5. Common Issues
Error
Fix
Authentication failed: Unauthorized
Confirm user/pass, and that Trino allows password auth.
unexpected end of stream
Port/firewall/VPN issues. Verify port 443 is reachable.
Connection argument is not a valid property
Use hashref for properties, not in DSN string.
SSL=true not working
Confirm the Java bridge trusts Trino’s cert. Use truststore.jks if needed.
What I really want is to check if the string is not entirely empty. I
would like to be able to do something like if ($string) but this
would exclude "0".
So I hope that there is a shorter and nicer way to do this. For now I have
been using a utility strempty subroutine which runs that check but I doubt
it's idiomatic.
In my own code I try to have it so that empty strings are simply
undef, where applicable, but sometimes it can't be helped and
external modules don't follow this rule hence why I have to write these
conditions.
I've recently learned about the DEFINE predicate and I'm testing it with a simple script that I wrote to practice Perl and regular expressions. The script simply checks for IPv4 or IPv6 addresses (I know there is a CPAN module for that, this is for me to practice), and I re-wrote the regular expression like so:
I was expecting to capture both IP addresses, but only the first is ever captured. Can anyone shed some light on how could I make this work in this way?
The use of HTTP::CookieJar is recommended over HTTP::Cookies, and the core module HTTP::Tiny only supports the former. There exists HTTP::CookieJar::LWP to allow using a HTTP::CookieJar with LWP::UserAgent, but I can't find anything going the other way- I want to use HTTP::Cookies::Mozilla with HTTP::Tiny. In fact, all the modules to read specific browser cookies use the HTTP::Cookies interface. The following seems to work, but I expected to find some minimal documentation or implementation:
use HTTP::Tiny;
use HTTP::CookieJar;
use HTTP::Cookies::Mozilla;
my $cookies = HTTP::Cookies::Mozilla->new(file => $firefox_cookies_sql
+ite_file);
my @cookies = map { s/^Set-Cookie3:\s*//; $_ }
split "\n", $cookies->as_string;
my $cookie_jar = HTTP::CookieJar->new;
$cookie_jar->load_cookies(@cookies);
my $ua = HTTP::Tiny->new(cookie_jar => $cookie_jar);
I'm trying to search for several regexes in some long files. To speed things up, I tried first checking a combined regex, to see if any of them matches the line. Like so:
my $comb=join('|',@ARGV);
while($line=<$infile>){
if($line=~$comb){
for $target(@ARGV){
if($line=~$target){
# do a thing
}}}}
This seems to speed things up, at least when the regexes are just plain words. But: If I try input regexes which are anchored ("^word"), then suddenly it's much slower! Is there some weirdness with alternations and anchors? Or did I make some obvious mistake?
(I could rewrite ^aaa|^bbb|^ccc as ^(aaa|bbb|ccc), but it might be that only some of the inputs are anchored.)
The code below is the smallest example I could come up with.
There are two curiosities that I'd like to figure-out.
When I double-click (left-mouse-button), a small dashed box appears around the entry that's been clicked
When I double-click (left-mouse-button), the entry changes color from green to black (still with Courier 12 bold)
When I single (left-click) the window not containing an entry, then the entry that was clicked returns to being displayed as DarkGreen with no highlight box round it.
Questions (somewhat inter-related):
Is it possible to disable HList from responding to the double-left-click (so that the entry doesn't get a dashed-box and the color of the entry doesn't change)?
On other GUIs I've written, the dashed-box has proved annoying. Is it possible to prevent the dashed-box from appearing?
I have trouble providing a "reliable source" for WP to admit that Perl influenced JS, and am having a lengthy discussion at the talk page of JavaScript
This blog entry lists JS methods which were influenced verbatim by Perl.
Hi. I am using a sub with my Tk module similar to;
sub tick {
# Run every 1000 milliseconds.
if ($toggle_scan_v eq 0) {return}; # Break out of this tick l
+oop
# Do something
$kount++;
print "$kount ";
$mw->after(1000, \&tick); # Suggest loop here
print "No Error; we should get here often. \n";
}
I trust that whenever the "after" is executed, the print is executed, after which a graceful exit of the subroutine occurs. This provides dead time for the thread of execution. In turn other events belonging to this same thread may occur and execute (possibly turning $toggle_scan_v on and stopping this "tick" loop which is earmarked to execute 1000 mSec after the "after" method).
I trust that the subroutine is called and always subsequently returns in such a manner that there is no stack littering.?
Hi. I am using the above serial module and come across the 2 mentioned methods. Both seem to behave the same wrt inputting the characters from a COM port.
What is the difference between the 2 methods and where is there a decent play to get some documentation for the module as a whole and it's methods.?
Also, these methods seem to behave in a non-blocking manner. I would ideally like an input that blocks with a time-out option while it's waits for a line as input.?