Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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.

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
@ARGV ignores quotes
2 direct replies — Read more / Contribute
by ovedpo15
on Jun 19, 2021 at 13:33
    Hello Monks!
    I have script which uses GetOptions to parse options. My script allows the to use the --job option to pass everything the user wants (scripts, additional parameters, etc.). For example:
    my_script.pl --option1 --option2 --job some_job.pl -option1 --option2 +--option3
    My script runs the some_job.pl -option1 --option2 --option3 part at some point. ​Before the GetOptions parse, I have the following code:
    my $job_flag = 0; foreach my $i (0..$#ARGV) { &#8203;$opt{"job"} .= $ARGV[$i]." " if($job_flag); &#8203;$job_flag = 1 if($ARGV[$i] =~ /^(\-\-|\-)job$/); &#8203;undef $ARGV[$i] if($job_flag); }< /code> The code just saves everything after --job into the $opt{job} and remo +ves it from the ARGV so GetOptions won't parse it. Now I noticed that + if there is quotes inside the job part, it will remove those quotes. + For example: <code> my_script.pl --option1 --option2 --job some_job.pl -option1 'some_job2 +.pl -x abc' -option2
    Then the Dumper of ARGS is:
    $VAR1 = [ + + '--option1', '--option2', '--job', 'some_job.pl', '-option1', 'some_job2.pl -x abc', '-option2' ];
    I would expect:
    $VAR1 = [ + + '--option1', '--option2', '--job', 'some_job.pl', '-option1', '\'some_job2.pl -x abc\'', '-option2' ];
    How can I know that there were quotes? I guess I'll need to think of another way to do this.

    So there won't happen and X-Y problem, I'll explain what I'm trying to do. I want to get user's command and execute it at some point. It could have parameters and I don't want the user to insert it into file first. How can it be done?
Using relative paths with taint mode
1 direct reply — Read more / Contribute
by Bod
on Jun 19, 2021 at 13:27

    I'm taking my first tentative steps into using taint mode!
    A problem has quickly got me rather stuck...

    I want to use a module in a relative path but taint mode removes '.' from @INC
    If I do this:

    #!/usr/bin/perl -T use CGI::Carp qw(fatalsToBrowser); use Site::HTML; use strict; use warnings;
    It complains that Site::HTML cannot be found.
    So I called on FindBin to help like this:
    #!/usr/bin/perl -T use CGI::Carp qw(fatalsToBrowser); use FindBin qw($Bin); use lib "$Bin"; use Site::HTML; use strict; use warnings;
    But now get an error Insecure dependency in require while running with -T switch at migrate.pl line 7.

    Is this the correct way to load a relative module under taint mode?
    Is the problem with the way I am loading the module or with the module itself?
    Should I be doing something completely differently?

How to use a private version of a published module?
3 direct replies — Read more / Contribute
by MARKWIN
on Jun 18, 2021 at 10:57
    So I am trying to publish a module that allows access to IG's API directly. This would allow simple listings of your spread bet positions. The module is written and works well for me. Under the hatch it uses the CPAN module Rest::Client for formatting requests.

    In order to test it it needs to be able to be tested without the use of my personal IG login details as these are private to me. The test programs use the unmodified IG.pm module, with a special @INC path from which it picks up a special version of Rest::Client. This version hashes the parameters, and then reads a file based on the hash and returns identical json formatted data as if my account had been used.

    My aim is to test my module, not Rest::Client which is not my module.

    I included the special version of Rest::Client and in my module code as well as a Record::Rest::Client for creating the special data files read by my local Rest::Client module.

    All works well, however when I submit the module, it says I have no permission to publish a version of Rest::Client. I do not actually want to do that, its only used in the testing of my module.

    I seek some suggestions as to what is the best way to proceed in this situation.

Windows and backslashes and replacements oh my!
3 direct replies — Read more / Contribute
by stevieb
on Jun 18, 2021 at 10:28

    Hey there my fellow esteemed Monks!

    I've been having a long-running problem that I'm finally fed up enough with to ask for help.

    In my test suite for berrybrew, I perform a path substitution in a configuration file before the tests load. The specific command which is run out of a batch script looks like this:

    call perl -i.bak -ne "s/berrybrew(?!\\+test)/berrybrew\\test/; print" +test/data/config.json

    Essentially, that's supposed to change the path C:\berrybrew to C:\berrybrew\test.

    On some of my Windows 10 systems, it works just fine, and everything goes on its merry way. On other Win10 systems, the change results in a tab character being inserted, so the path looks like this: C:\berrybrew[TAB]est. If I insert four backslashes in the replacement (ie. berrybrew\\\\test, it works. However, after a git push then a git pull on the other systems that work with just the two backslashes, it breaks.

    What can I do to provide myself some consistency across systems? Is there some unicode trick or something I can use? I've tried replacing the forward slashes in the substitution to single-quotes (eg: s///; to s''';) to no avail.

    I'd really like to get this resolved so that the substitution works reliably across all systems.

    Cheers,

    -stevieb

Escaping or removing quotes
2 direct replies — Read more / Contribute
by htmanning
on Jun 17, 2021 at 17:52
    Monks, I've done this a thousand times before, but for some reason this isn't working. I'm trying to escape or preferably replace double quotes that are copied from a website. I'm doing like this but Perl is not recognizing the quotes at all.
    $string = 'copied from a web page looking like this: “Test.” '; $string =~ s/“//g; $string =~ s/”//g;
    Am I just having a brain fart moment? Perl seems to not even recognize the quotes and just lets them go through. I have ruled out simple things like the string name being wrong or something.
Issue with LWP loading client certificate
3 direct replies — Read more / Contribute
by ffrost
on Jun 17, 2021 at 16:04

    Objective: To connect from my machine to an external server using HTTPS. The connection will use the GET verb and the external server should return a message back to the client. As a security mechanism, the certificate for my client must be sent to the server as authentication.

    I'm using LWP to get the response from the external server. I've run into two problems I'm not sure of. First, I am unsure if the LWP program is actually loading the certificate, which is in DER format. Second, since the server is responding with a 403 error I don't think they are getting my certificate. Am I loading the certificate correctly to send from my Windows machine to their external IIS server?

    The DER certificate is valid and has not expired. It is not a self-signed certificate.

    use LWP::UserAgent; use Data::Dumper; use Cwd; $cdir = getcwd; $endpoint = ‘https://omit/commotest'; $ua = LWP::UserAgent->new; $ua->ssl_opts(SSL_cert_file => "$cdir\\der.cer"); $ua->ssl_opts(SSL_use_cert => '1'); $response = $ua->get($endpoint); if ($response->is_success) { print Dumper $response; } else { print "Error: " . $response->status_line, "\n"; }
reading through dated directories
3 direct replies — Read more / Contribute
by Anonymous Monk
on Jun 17, 2021 at 14:13
    Dear Monks,

    I am reading though a large set of dated directories with a large number of dates where the number of <date> directories is much larger than the number of parent <dir> directories. There is only one date "dir" per parent in the future--the rest are in the past. I just have to find these future dates.

    dir1 / <date1> dir1 / <date2> dir2 / <date3> dir3 / <date4>

    I am currently using glob("*/*") to loop through all the dates to find all the ones in the future. My glob has become annoyingly slow and I'd like to speed it up. Any ideas how I can use readdir() to return an array of "dir / <date> " of only the future dates

    Thank you for your time--always appreciate the help & advice.

    Best,

    Michael
Mojo pp html_entities.txt
1 direct reply — Read more / Contribute
by Anonymous Monk
on Jun 17, 2021 at 12:45

    How can I override at run time the directory where Mojo searches for the file "html_entities.txt"? The reason is that I am trying to use PAR pp to create an executable of an application using Mojo on Windows 10, but the exe fails with the following error:

    Unable to open html entities file (C:\Users\de\AppData\Local\Temp\par-6663\cache-9973dd41d00e8bee27c9630746780ae38da71709\inc\lib\Mojo\resources\html_entities.txt): No such file or directory at C:\Users\de\AppData\Local\Temp\par-6663\cache-9973dd41d00e8bee27c9630746780ae38da71709\inc\lib/Mojo/Base.pm line 14.

    I already tried to add to the file explicitly:

    -a "C:\Strawberry\perl\vendor\lib\Mojo\resources;Mojo/resources"

    with no effect. So probably copying and pasting the file into my data structure and instruct Mojo to search there could be a fix. Any suggestion?

compare two arrays if both are equal and have same elements irrespective of their position
5 direct replies — Read more / Contribute
by noviceuser
on Jun 16, 2021 at 13:20

    i have to compare two arrays to check if both are exactly same or not irrespective of which elements come at which position

    here @failedTestsuites is first array and @referenceTestsuites is second array, i have tried below code but it is not giving desired result. one of the case is: suppose @failedTestsuites array contains 'a','b','c' and @referenceTestsuites array contains 'a','b' then also it is printing both array as same. please help

    my $comp = Array::Compare->new; if ($comp->compare(\@failedTestsuites, \@referenceTestsuites)) { print "same arrays\n"; } else { print "different arrays\n"; }
how to ignore spaces, commas or new line of an array when comparing
1 direct reply — Read more / Contribute
by noviceuser
on Jun 16, 2021 at 04:01

    I am trying to compare two arrays which may have strings/elements separated by newline, spaces or comma, how can i ignore those special characters while comparing

    e.g: suppose @array1 has contents like below

    abc xyz

    and @array2 has contents like below

    abc xyz
    my $comp = Array::Compare->new; if ($comp->compare(\@array1, \@array2)) { print "array same\n"; } else { print "array not same\n"; }

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":


  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
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 surveying the Monastery: (5)
As of 2021-06-19 18:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (93 votes). Check out past polls.

    Notices?