Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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
checking command suggestions with Net::SSH::Expect
No replies — Read more | Post response
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.



Perl/Tk stdin NOT text box, only one part of code
2 direct replies — Read more / Contribute
by cniggeler
on Jul 01, 2020 at 11:50
    Hi, in a large-size perl/Tk program we are adding tags. Sometimes there are tens of thousands of tags to add, and this can take a lot of user real-time. Our window has a status bar, so I'd like to have something in it like,

    Adding 1500 of 37885 tags. Press 's' to stop adding tags...

    and have that update every 500 tags. My question is, how can I detect the user entered 's' at this point in the code? I thought of adding a key binding, which I guess is the only way to do so, but would this intercept the user, say, typing a filename containing a 's' in a dialog box? In that case, is there a way to enable the key binding at just the point I need it, then disable it at the end? Or do I have to use something more unlikely, like CTRL+S?

    Or is there a better way? Online searches have not been fruitful. Thank you!
Is there a problem with using barewords as filehandles ?
7 direct replies — Read more / Contribute
by syphilis
on Jul 01, 2020 at 05:39

    In following the kerfuffle on p5p about the planned release of perl 7, I've noticed a repeated claim that use of barewords as filehandles will be disallowed in perl 7.
    What's so wrong with doing open RD, '<', 'file.txt' ?

    Is there some official perl documentation about any such issue ?

regex to extract value from a string
1 direct reply — Read more / Contribute
by Anonymous Monk
on Jul 01, 2020 at 02:59

    i am trying to fetch a value from a string after _ using regex and try to store that value in a variable that i can use somewhere else, like below....also we can have any number in place of 5 like 8, 9 , 10 or 20

    my $job = "50.10-d557_5"; my $Path = ""; $path = /home/data/5/file1.log
HTML::Template nested Table
2 direct replies — Read more / Contribute
by Takamoto
on Jun 30, 2020 at 17:11

    Hello, I am experimenting with templating a table. I have no issues with fixed data structures... but now I need to generate a table with HTML::Template where the number and the names of the columns may vary. I generate my data like this:

    my $dictionary = [ { 'Spanish' => 'uno', 'English' => 'one', 'Italian' => 'uno', }, { 'Spanish' => 'dos', 'English' => 'twho', 'Italian' => 'due', }, { 'Spanish' => 'tres', 'English' => 'Three', 'Italian' => 'tre', } ]; use HTML::Template; my $template = HTML::Template->new(filename => 'dictionary.tmpl'); $template->param(DICTIONARY => $dictionary); $template->output;

    However, my data may also look like this:

    my $dictionary = [ { 'Spanish' => 'uno', 'French' => '1', }, { 'Spanish' => 'dos', 'French' => '2', }, { 'Spanish' => 'tres', 'French' => '3', } ];

    How could I template this?

Perl: Extracting the value from --rsync-path=PROGRAM key/value pair
1 direct reply — Read more / Contribute
by nysus
on Jun 30, 2020 at 14:12

    I want to extract the value from a string that (I assume) could look a mix of any of the following formats:

    --rsync-path = 'blah blah' # might be spaces before/af +ter equal sign --rsync-path=/usr/bin/rsync # no quotes around value (a +ssuming this is allowed by rsync) --rsync-path="blah blah \"blah" # double quotes, with possi +ble escaped quotes --rsync-path='blah blah \'blah' # single quotes, with possi +ble escaped quotes --rsync-path='blah blah' --another-option # additional options might +follow --another-option --rsync-path='blah blah' # additional options might +precede (and follow) # any other tricky alternatives I'm forgetting?

    So basically, I want to simulate how bash extracts the value but with perl.

    I could probably create some regexes for this but I'm quite sure some obscure scenario will be left out not to mention the possibility of badly malformed user input. So is there any module out there that might make extracting this value more of a no-brainer?

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

'Can't locate object method "status" via package "HTTP::Headers"' error using LWP::UserAgent
4 direct replies — Read more / Contribute
by Cody Fendant
on Jun 29, 2020 at 21:11

    I'm getting this error when trying to access a URL (https).

    Can't locate object method "status" via package "HTTP::Headers" at /opt/local/lib/perl5/site_perl/5.30/HTTP/ line 653.

    LWP::UserAgent, HTTP::Headers and HTTP::Message are all up to date according to CPAN so I'm a bit baffled as to how to proceed.

Add your question
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?

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

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (6)
    As of 2020-07-02 17:18 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found