Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Seekers of Perl Wisdom

( [id://479]=superdoc: print w/replies, xml ) Need Help??

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.

Post a new question!

User Questions
Self-signed certificates and Net::MQTT::Simple::SSL
1 direct reply — Read more / Contribute
by mldvx4
on Aug 20, 2024 at 11:29

    Greetings. With the code down below I get the this error:

    connect: SSL connect attempt failed error:0A000086:SSL routines::certificate verify failed

    What is the right way to allow Net::MQTT::Simple::SSL to manage self-signed certificates?

    #!/usr/bin/perl use Config::Tiny; use Net::MQTT::Simple::SSL; use strict; use warnings; my $config = $0; $config =~ s/\.pl$/.config/; my $configuration = Config::Tiny->read($config) or die("Could not read configuration file '$config': $!\n"); my $cpath = '/home/me/Certs'; my $mqtt = Net::MQTT::Simple::SSL->new("203.0.113.46:8883", { SSL_ca_file => "$cpath/certificate-authority.crt", SSL_cert_file => "$cpath/notifications-client.crt", SSL_key_file => "$cpath/notifications-client.key", # SSL_verify_mode => 0, }); $mqtt->login($configuration->{mqtt}->{account}, $configuration->{mqtt}->{password} ); $mqtt->subscribe('notifications', \&received); $mqtt->run(); $mqtt->disconnect(); exit(0); sub received { my ($topic, $message) = (@_); if ( $message =~ m/\x3b/ || $message =~ m/[\x00-\x08\x0a-\x1f]/ ) { warn "notify\tMalformed message\n"; } elsif ( $topic =~ m/\x3b/ || $topic =~ m/[\x00-\x08\x0a-\x1f]/ ) { warn "notify\tMalformed message\n"; } else { my ($title, $message) = ( $message =~ m/^([^\x09]+)\t(.*)$/ ); system("notify-send", "--icon=info", $title, $message); } }

    If I uncomment SSL_verify_mode then it connects, but that seems rather unsafe and may partially defeat the encryption I would guess. I would like to find a way to verify the self-signed certificates here.

Hash syntax
4 direct replies — Read more / Contribute
by mvanle
on Aug 19, 2024 at 03:37

    Why are the below hash values not equal ?

    use feature 'say'; my $hash; $hash{key1}{key2} = 'val1'; $hash->{key1}->{key2} = 'val2'; say $hash{key1}{key2}; say $hash->{key1}->{key2}; =comment Expected: val2 val2 Actual: val1 val2 =cut
ST7789V2 LCD Controller
3 direct replies — Read more / Contribute
by Bod
on Aug 18, 2024 at 15:08

    WoW! Just realised I haven't been on PM for far too long...where does the time go???
    I've not been developing anything new recently as my time has been spent in other parts of the business...

    Anyway, enough rambling...

    As a bit of a hobby project, I'm trying to make a RaspberryPi power this LCD unit. Pretty much new ground for me, and I'm hoping to learn more about Debian and some of the lower-level Perl modules through this...

    I've followed the instructions to get the LCD connected and the C demo program works so I know both the RaspberryPi and the LCD work and are connected together correctly.

    So I'm left with several options on how to tackle this...here are some of them I've thought of, no doubt there are others:

    So far, I've installed RPi::WiringPi which was a mission to do...

    But, I haven't managed to get any code to operate the LCD.

    Who has experience of this kind of LCD unit and which approach would you start with?

OT: Why does malloc always give me 24? [SOLVED]
3 direct replies — Read more / Contribute
by karlgoethebier
on Aug 18, 2024 at 07:59
    #include <malloc.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define N 1 typedef struct _acme { int data; } * acme; int main(void) { acme gizmo[N]; gizmo[0] = (acme)malloc(sizeof(struct _acme)); size_t msize = malloc_usable_size(gizmo[0]); printf("malloc_usable_size(gizmo[0]) %lu\n", msize); free(gizmo[0]); return (1); }

    This always allocates 24 bytes - whatever i pass to malloc. I’m a bit confused. What do i miss? Thanks in advance for enlightenment.

    Update: Thanks to all for the kind and helpful replies.

set proto string
3 direct replies — Read more / Contribute
by vincentaxhe
on Aug 17, 2024 at 08:04
    my @a; my $proto1 = \@a; my $proto2 = "@{\@a} 3 4"; @a = (1, 2); print "@{$proto1}", "\n"; #OUTPUT: 1 2 print $proto2; #OUTPUT: 3 4, not what I want
    How could I properly write $proto2 to defer @a evaluation?
"my" cost
6 direct replies — Read more / Contribute
by Danny
on Aug 16, 2024 at 19:46
    The following code seems to show that using "my" in a loop has a noticeable cost. I thought that maybe "it" would "see" how my was nested and just deal with it once. The output is:
    0.0232839584350586 my outside 0.0305099487304688 my inside
    use Time::HiRes qw(time); my ($i); my $start = time; { my $x; for $i (1..1e6) { $x = 1; } } my $end = time; printf "%s my outside\n", $end - $start; $start = time; for $i (1..1e6) { my $x = 1; } $end = time; printf "%s my inside\n", $end - $start;
windows login
2 direct replies — Read more / Contribute
by Danny
on Aug 16, 2024 at 01:01
    Very sorry to ask this here, but this is the only place I use. For some reason I can't login to windows after reboot. It doesn't let me login. It doesn't seem to be recording my key strokes, but it finally too me to a login screen for a secondary disk, but it doesn't seem to be seeing my keystrokes. Before that in the main login it didn't see my keystrokes either.

    ps. normally, I auto login without passwd etc

    UPDATE: Thanks for the responses. I woke up today, unplugged the keyboard and plugged it back in, and it started working.
regex to match double letters but not triple or more
5 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 15, 2024 at 12:01

    I have tried

    /([A-Za-z])\1{1}/

    but this finds pairs of letters. My intent is to match only paired letters, not singular and not three or more.

    "caab" should match

    "cdaaadc" should not match

    The reason is a puzzle I have been making for personal use. More in the nature of expanding my RE chops than anything else. Please let me know if I can provide more information or if there are any solutions to this. Thank you!

Returning to Perl after almost 3 decades
9 direct replies — Read more / Contribute
by DaWolf
on Aug 14, 2024 at 11:32
    Hello, fellow monks.

    I've been away from Perl for almost 3 decades and I have a technichal interview coming for a Perl position. While I've already did some coding and coming back to write Perl feels comfortable, I wonder if you could enlighten me with some relevant issues for the Perl marketplace nowadays, and of course, provide some links.

    Here's a few I've came up with but please feel free to add your own:
    • Frameworks for web development: what are the most popular ones?
    • Changes to the language itself
    • OO Perl?
    I'd really appreciate your help on getting back to a language that I've always loved.
    TIA,


    Er Galvão Abbott
    www.galvao.eti.br
Tags in TK Text widgets
2 direct replies — Read more / Contribute
by colintu
on Aug 14, 2024 at 06:06

    I have a Text widget in which I need to mark 'invalid' characters by changing their colour. This works except for two cases:

    If the char is a newline/return then the whole of the rest of the line in the Text widget has it's colour changed rather than just the single char position after the last word.

    I am highlighting space characters with a tag. When the text widget word wraps the text all of the remainder of the line is highlighted as if there were multiple spaces filling the end of the line.

    It appears that the text widget is treating all of the white space displayed at the end of each word wrapped line as a single character.

    Is this expected? Is this a bug? Is there a way of preventing this?

    Colin


Add your question
Title:
Your question:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":


  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others admiring the Monastery: (4)
    As of 2024-09-08 21:50 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.