Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Seekers of Perl Wisdom

( #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. Post a new question!

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.

User Questions
Firefox warns that cookies generated by Catalyst will be rejected in future
1 direct reply — Read more / Contribute
by martell
on Jul 04, 2020 at 10:32

    Dear Monks,

    I'm using Catalyst::Plugin::Session::State::Cookie to have sessions within my pages. While developing I noticed that Firefox in its most recent version is complaining in the console that my cookies are misusing the sameSite attribute:

    Cookie “my_site_session” will be soon rejected because it has the “sam +eSite” attribute set to “none” or an invalid value, without the “secu +re” attribute. To know more about the “sameSite“ attribute, read http +s://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie/SameSite p +hotos

    In catalyst I have following code to configure my site and the Cookie Plugin:

    use Catalyst qw/ ConfigLoader Static::Simple Session Session::Store::FastMmap Session::State::Cookie Authentication Authorization::Roles /;

    If found that I can set the secure flag by adding to my config:

    __PACKAGE__->config('Plugin::Session' => { cookie_secure => 1, });

    This solves my immediate concern because now Firefox doesn't complain any more. (In reality I use the value "2" because on my development machine I don't use https .). But it doesn't feel like a fundamental good solution.

    Looking through the code of the module I don't see the variable "SameSite" explicitly set. Hence I suppose Firefox detects it as having the value "None". I'm not familiar with the innards of Catalyst and I don't know if the cookie is handled somewhere else in Catalyst before sending. But I was wondering if this module should not set the "SameSite" variable in a Cookie by default to "Lax" as it is the expected default.

    Any thoughts, insights on this observation before I report it as a bug on the module?

    Kind regards

Caching DB rows transparently and with SQL search
3 direct replies — Read more / Contribute
by bliako
on Jul 04, 2020 at 07:13

    Esteemed Monks, I need some advice on DB caching,

    A typical web-app, let's say using Mojolicious and DBIx::Class, has a lot of semi-static data stored in the DB. For example the list of registered users, the set of allowed tags, phone numbers of associates. This data does not change often (perhaps once a week/month) so why do I fetch it every time a user looks up another user's phone. (forget at the moment issues of privacy - all users are allowed to see all other users details). Another example is a business phone directory with 100 entries. Fairly static and very much in use. This data is not so big in size so I want to keep it in the memory of my app and serve this instead of fetching it from db each time a webpage with a dropdown menu of all phones is loaded.

    So, I thought on starting up the app, create a helper and store these semi-static data (fetched once and only from DB). Then serve this and never bother the DB again. That's fine but how about providing SQL-style search for this data? Because sometimes I will get requests from the client (e.g. when it loads a user's profile page) of /user/list?id=xyz in addition to /usr/list?id=all and also /usr/list?name=*abc*. These are all implemented as SQL searches in DBIx::Class and work fine but they are not cached.

    This is what I would like (and this is the 21st century and I want to have it): either tell DBIx::Class that specific table should be cached unconditionally until I say so. This transparency will be ideal for using existing code. OR, less preferred, store the static data in Perl and via a module have SQL searches on it, as if it was residing in a DB.

    thanks, bw bliako

    EDIT: I have asked a similar question at https://webchat.freenode.net/#mojo (which was part of a more general question)

Crash at perl_parse() function
3 direct replies — Read more / Contribute
by prabakar.bhatt
on Jul 03, 2020 at 11:39

    We are seeing following crash in Perl 5.24.3 version when multiple clients are connected. Each client is a new thread and each thread creates its own perl interpreter.

    #0 0x00007f338c774638 in __strchr_sse42 () from /usr/lib64/libc.so.6

    #1 0x00007f33654e1d2e in S_init_postdump_symbols () f

    #2 0x00007f33654e8468 in S_parse_body ()

    #3 0x00007f33654e9016 in perl_parse ()

    #4 0x00007f33654a2e77 in MappingRule_intern (event=..., ruleParameter=..., c_AMName=0x7f33400435d8 "AM", b_reset_perl=false, i_timeout=@0x7f334ec327ec: 0)at ../alarm_mapping.cxx:3384

    #5 0x00007f33654bfc41 in MappingRule (event=..., ruleParameter=...) at 1.cxx:891

Unable to use WWW-Mechanize
2 direct replies — Read more / Contribute
by rich_d_thomas
on Jul 03, 2020 at 04:25
    Hi, I have been trying to use this with the following code and result. I have tried forcing different versions of TLS and ignoring the server certificate. I have version 2.00 of the WWW-Mechanize module installed. The site itself supports TLS 1.1 and 1.2 I can wget to https://customer.bookingbug.com from the same machine that I'm trying this perl script from. Can anybody help please?
    #!/usr/bin/perl use constant VERSION => "v1.06"; use strict; use warnings; use IO::Socket::SSL; use LWP; use LWP::UserAgent; use LWP::Debug; use WWW::Mechanize; LWP::Debug::trace('()'); $| = 1; # perform flush after each write to STDOUT my $url="https://customer.bookingbug.com"; my $initial_user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_ +3) AppleWebKit/534.53.11 (KHTML, like Gecko) Version/5.1.3 Safari/534 +.53.10'; my $mech; $mech=WWW::Mechanize->new( agent => $initial_user_agent, ); $mech->add_handler("request_send", sub { shift->dump; return }); $mech->get( $url ); printf($mech->content)
    This is the result I get:
    ./s.pl GET https://customer.bookingbug.com Accept-Encoding: gzip User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit +/534.53.11 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10 (no content) Error GETing https://customer.bookingbug.com: Can't connect to custome +r.bookingbug.com:443 (LWP::Protocol::https::Socket: SSL connect attem +pt failed with unknown errorerror:140770FC:SSL routines:SSL23_GET_SER +VER_HELLO:unknown protocol) at ./s.pl line 35.
Combine duplicated keys in Hash array
3 direct replies — Read more / Contribute
by Tikplay
on Jul 02, 2020 at 21:52

    Hello, I’m having issues with this and wondering if someone could provide some help. I'm parsing a .txt file and want to combine duplicated keys and it's values. Essentially, for each identifier I want to store it's height value. Each "sample" has 2 entries (A & B). I have the file stored like this:

    while(...){ @data= split ("\t", $line); $curr_identifier= $data[0]; $markername= $data[1]; $position1= $data[2]; $height= $data[4]; if ($line >0){ $result[0] = $markername; $result[1] = $position1; $result[2] = $height; $result[3] = $curr_identifier; $data{$curr_identifier}= [@result]; } }

    This seems to work fine, but my issue is that when I send this data to below function. It prints the $curr_identifier twice. I only want to populate unique identifiers and check for the presence of it's $height variable.

    if (!defined $data{$curr_identifier}[2]){ $output1= "no height for both markers- failed"; } else { if ($data{$curr_identifier}[2] eq " ") { $output1 = $markername; } } print $curr_identifier, $output1 . "\t" . $output1 . "\n";

    Basically, if sample height is present for both markers (A&B), then output is both markers. '1', 'A', 'B'

    If height is not present, then output is empty for reported marker.

    '2', 'A', ' '

    '3', ' ', 'B'

    My current output is printing out like this:

    1, A

    1, B

    2, A

    2, ' '

    3, ' '

    3, B'

    _DATA_

    Name Marker Position1 Height Time

    1 A A 6246 0.9706

    1 B B 3237 0.9706

    2 A 0

    2 B B 5495 0.9775

    3 A A 11254 0.9694

    3 B 0

$c->flash Not Dereferencing Data Objects
2 direct replies — Read more / Contribute
by phildeman
on Jul 02, 2020 at 15:48

    Hi All,

    I encountered something unusual with Perl 5.14.2.

    I am using DBIx::Class to query my database. The data object is returned to Root to be passed to a View.
    I pass the data object to the View via $c->flash. However, in the View it has a problem dereferencing the
    data object.

    For example, I query a person's name and address and store it in bio_object. Then I pass it to $c->flash like so:

    In Root.pm:

    my $bio_obj = $model->get_bio_info( $id ); $c->flash->{ 'bio' } = $bio_obj; $c->res-redirect( 'myviewpage' );

    In myviewpage, using Mason in HTML page:

    <p>My name is <% $bio->name %><br /> My residence is at <% $bio->address %> <%init> my $bio = $c->flash->{ 'bio' } if $c->flash->{ 'bio' }; </%init>

    The view error message states it cannot find the method 'name' or 'address'. However, I created a test script
    that calls the same query method, "get_bio_info". I display the results without issues, using a print statement.

    Has anyone experienced this before?

checking command suggestions with Net::SSH::Expect
2 direct replies — Read more / Contribute
by himanshu.chauhan
on Jul 02, 2020 at 11:20
    Hi Monks,

    I'm new here and need to implement a certain automation for linux process. But I'm stuck at a point where first I need to check a command suggestions before executing the actual command depending on certain condition. By command suggestion, I mean the suggestion or next steps displayed for a command when we press <TAB><TAB>. I have tried doing the following things but not even a single one worked:

    $connection = Net::SSH::Expect(); #connection to a server $connection->send("\t\t"); $connection->get_expect()->send("\t\t"); $connection->send("011"); $connection->get_expect()->send("011"); # octal for tab

    So basically once sending <TAB><TAB> characters, I can read suggestions using $connection->read_all() but not able to figure out how to get suggestions using tab. It would be great if any of you amazing monks can guide me through this mountain!

    Thank you in advance!
Multiple numeric not or compare in if statement
7 direct replies — Read more / Contribute
by RedJeep
on Jul 02, 2020 at 00:41

    Ok, this should be very basic. For the life of me I can't figure it out. I searched and searched. Maybe you can help?

    In one of my programs I found this wrong way

    if ($sender_transaction_type !~ /3|21/)

    The above code is wrong, is bad, works sometimes. I know this is wrong. Trying to figure out the right way. I wrote the little test script below.

    In the below script the multi-compare Option Equals works fine. But the multi-compare Option Not Equal does not work. Why? How to fix?

    For example, set $a = 77 and the Option Not Equal does not work.

    Thanks for the help!

    use strict; $a = 8; #Try using 7 and see how second loop does not evaluate correct +ly ## Examples # $a = 44 evaluates ok for both options # $a = 33 evaluates ok for both options # $a = 3 does not evalute correctly on Option Not Equal # $a = 77 does not evalute correctly on Option Not Equal # $a = 8 does not evalute correctly on Option Not Equal ## Option Equal if (($a == 3) || ($a == 77) || ($a == 8)) { print "$a must be a 3 77 or 8\n"; } else { print "$a is not a 3 77 or 8\n"; } print "\n"; ## Option Not Equal if (($a != 3) || ($a != 77) || ($a != 8)) { print "$a is not a 3 77 or 8\n"; } else { print "$a is a 3 77 or 8\n"; }
Where to put data that goes with a module?
3 direct replies — Read more / Contribute
by Lady_Aleena
on Jul 02, 2020 at 00:21

    I have been documenting my Random modules in a readme for GitHub when I came across some that have external data. Two of them have text files that I open, chomp, and make into an array; nothing special. However, the data for those two are in my general data directory. If I people want to use these modules (and if I ever get them properly written), I will need to put the data closer to them. Now, I just don't know where to put them. (The other modules with external data need hashes made, and that is a bigger problem.)

    You might be wondering why I did not put the data directly into the module. It is because two of the lists are over 100 items long and the other two are over 10 with longer strings.

    I am also looking to move these Random modules away from using any of my Util modules. My Util modules are messes and for my personal use. (So many PODs to update with their dependencies, hopefully without using any of those Util modules one day.)

    I know it may be a matter of taste, but where you would put data files relative to the module that uses them?

    My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.8.8 on web host.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
Read file after download
4 direct replies — Read more / Contribute
by kepler
on Jul 01, 2020 at 13:32

    Good afternoon

    Can someone please tell me how do I read and process some data only after the download of that data (from a get url request for example) is done/completed? Otherwise, I get an error...logically.

    Thanks

    Kepler


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
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (5)
    As of 2020-07-05 04:34 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?