Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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
Google keep api
1 direct reply — Read more / Contribute
by morgon
on Apr 14, 2018 at 13:14
    Hi,

    I just came across https://github.com/kiwiz/gkeepapi which is an (inofficial - there is no offical api yet afaik) python module to create google keep notes programmatically.

    I could not find anything like that for perl.

    Is there?

    Many thanks!

process monitoring script
4 direct replies — Read more / Contribute
by xtremenet
on Apr 14, 2018 at 12:42

    hello there, can anyone help me making a scrip please?

    my assignment is to write a script to monitor a process.

    it is checking a process for every 30 sec,

    and whenever the process is gone (or done closing) then restart it again.

    I am so bad at coding yet i try to study it.. please help me : )

Compound statements within the conditional (ternary) operator
3 direct replies — Read more / Contribute
by Fendo
on Apr 14, 2018 at 08:04
    Hello wise monks! I come to ask for your kind advice and enlightenment on the following matter:

    I've been trying to print a character a certain number of times, if a certain condition is met. For the printing, I use an “until” loop. For the condition, I would like to use the conditional (ternary) operator. However, this apparently results in a syntax error. Below is example code which produces the error. My intention was to print the equals sign ten times instead.

    #!/usr/bin/perl use strict; use warnings; my $count = 0; ( defined $count ) ? ( print "=" until ( $count ++ == 10 ) ) : ( print "Undefined count.\n" );

    This results in the error: syntax error at ./example.pl line 8, near ""=" until". I have tried using a different form for the loop:

    ( defined $count ) ? ( until ( $count ++ == 10 ) { print "=" } ) : ( print "Undefined count.\n" );

    However, that results in a similar error: syntax error at ./example.pl line 8, near "( until". When I try to achieve this using “if” and “else”, it works very well, using this code:

    if ( defined $count ) { print "=" until ( $count ++ == 10 ); } else { print "Undefined count.\n"; }
    Is it possible to use such constructions within the conditional (ternary) operator, as I've been trying to do? And if yes, how may I do so correctly? Thank you in advance!
pre-preprocess Moose args in constructor
1 direct reply — Read more / Contribute
by Anonymous Monk
on Apr 14, 2018 at 02:21
    Esteemed and hallowed Monks: Trying to force upper case on Moose args taken from command line - eg FX currency codes - e.g.
    $lookup usd eur gbp chf
    Yes - I could put it into the calling code - but how would I get Moose to force it itself - I tried this from Moose docs:
    trigger => sub { $_[0]->code( uc( $_[0]->code ) );
    but I get message that I am unable to to modify read-only value despite Moose docs saying that trigger can modify RO values. What is correct way to force upper case (and thus in general) 'pre-preocess' object constructor arguments? Thank-you.
How to get foreground color from a TK::Listbox
3 direct replies — Read more / Contribute
by jsteng
on Apr 14, 2018 at 00:40
    I am referring to TK::Listbox http://search.cpan.org/dist/Tk/pod/Listbox.pod I have a Listbox:
    $frames{"Account.List"} = $mw->Scrolled( "Listbox", -bg => $config{'background'}, -fg => '#FFFFFF', -font => [$config{'font'},$config{'fontsize'},'normal'], -relief => 'raised', -scrollbars => 'e', -cursor => 'left_ptr', );
    And bounded <Double-1>:
    $frames{"Account.List"}->bind( '<Double-1>', $frames{'Account.List'}->itemconfigure($frames{"Account.List"}->cu +rselection(), -foreground=> "#FF0000", );
    Here is the question: How do I retrieve the foreground value #FF0000? Docs says to use itemconfigure without value: $frames{'Account.List'}->itemcget($frames{"Account.List"}->curselection(), "-foreground") but that does not work. I am stuck! My ultimate task for that is to: 1st. flip-flop the color of the text. 2nd: flip-flop the font from normal to bold. How? Thanks!
indented here-doc "delimiter"
4 direct replies — Read more / Contribute
by ibm1620
on Apr 13, 2018 at 19:48
    I'm reading the Perl 5.26.1 perlop documentation about the indented here-doc. It says:
    The here-doc modifier ~ allows you to indent your here-docs to make the code more readable:
    if ($some_var) { print <<~EOF; This is a here-doc EOF }
    This will print...
    This is a here-doc
    ...with no leading whitespace.

    The delimiter is used to determine the exact whitespace to remove from the beginning of each line.

    It's not obvious to me what "the delimiter" is and how was it declared. To me, it's an odd use of the word "delimiter".

    Am I correct in assuming that what's meant is: when you write "<<~EOF;", Perl will take the initial whitespace characters from the following line as an "indentation definition" and remove it from the beginning of every line in the here-doc?

DBIx and MySQL's binary data type
1 direct reply — Read more / Contribute
by Anonymous Monk
on Apr 13, 2018 at 19:09
    Got saddled with a project that involves utilizing DBIx for CRUD operations in a MySQL database. One of the fields is something I haven't had to deal with in Perl and particularly in DBIx. I have a binary(60) field in MySQL that will store a bcrypt hash for passwords. In some testing and discovery, I am having a hard time storing properly and ultimately authenticating passwords correctly. In my testing been using Crypt::Eksblowfish::Bcrypt. I've googled about for the morning and have unfortunately found nothing that applies to a best practice in the situation. Does anyone have any suggestions?
how to sort an array of (Moose) objects
1 direct reply — Read more / Contribute
by Anonymous Monk
on Apr 13, 2018 at 12:52
    given:
    foreach my $obj (@ArrayofObjects){ $obj->print }
    How do I sort that to print in price order? I tried something like this:
    foreach my $obj (sort @ArObj[$a]->price <=> @ArObj[$b]->price} @ArObj) + { # stuff here ... }
    but does not work...What am I missing? Cheers...
parse /etc/passwd and output it as csv in hundred servers
4 direct replies — Read more / Contribute
by garcimo
on Apr 13, 2018 at 09:46
    Hello,

    I need to scan about 190 servers for the presence of some users and output in csv in the following format:

    hostname,user1,user2..userx

    this snip of code grabs the desired lines from all the /etc/passwd but I do not know how to output the csv.
    ... chomp (my @hosts = `cat ssh-list.txt`); #print "@hosts\n"; my (%ssh, %ls); for my $host (@hosts) { $ssh{$host} = Net::OpenSSH->new($host, user=> $user_name, password= +> $password,master_stderr_discard => 1, async=>1, master_opts => [-o => "StrictHostKeyChecking no" ] ); } for my $host (@hosts) { chomp (my $user = $ssh{$host}->capture('egrep "^dba|^sea|^adm|^mwa|^ae +" /etc/passwd'));

    could I use getpwent to parse the output of $user?

    I am rather new to perl so sorry if the code is bad.
Override printing to STDOUT/ERR
4 direct replies — Read more / Contribute
by bliako
on Apr 13, 2018 at 08:53

    Hello wise Monks,

    I would like to override Perl's printing to STDOUT/STDERR with my own version which simply adds the line number the print function call happened. Ideally, ALL the line numbers/filenames/packagenames in the case of nested calls all the way to the top/main because I want to separate a program's STDOUT depending on which part of the program it originated.

    You can assume I have complete control over the source code (of the program which I want to override its print statements) and can change anything I like. HOWEVER, I do not have control of the source-code of the many packages the program may be using and the print statements therein.

    Initially I thought to just replace print with my_own_print in the source code and run that. Then I realised that it should only affect print in a function-call context and I used PPI for this purpose. And then I realised that there are other ways of printing to STDOUT/STDERR including the croaks etc. And finally I also realised that print statements in the packages will be out of my control. So this plan collapsed fairly quickly.

    Now, I have already read the thread !Overriding Builtin print

    and the more recent https://stackoverflow.com/questions/387702/how-can-i-hook-into-perls-print/6281636

    However, I wonder if there are any recent developments since then or a definite HOWTO.

    thanks, bliako


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 all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (3)
    As of 2018-04-19 16:08 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?