Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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
Gtk2::Dialog window size
No replies — Read more | Post response
by smittypaddler
on Jun 30, 2016 at 11:49
    How do I set the dialog window size so the entire title is displayed. set_size_request wants pixels, and I don't know how to get $title size in pixels. Here's my code:
    $title=($answer eq $Answer) ? "Yes" : "No, s/b $Answer"; $dialog=Gtk2::Dialog->new($title,$parent, [qw/modal destroy-with-parent/], 'ok' => 'ok', ); $response=$dialog->run; $dialog->destroy;
Generating ranges of numbers
5 direct replies — Read more / Contribute
by nandymamith
on Jun 30, 2016 at 06:03

    Can anybody help in getting the solution for me. Below are the INPUT and the OUTPUT elements that I am expecting is as shown below :

    INPUT @array = ("1","2","3","5","6","7",9"); OUTPUT @ranges = ("1:3","5:7","9");

    Please Note: Do not use any CPAN libraries to extract the OUTPUT

Are "use constant" constants really inlined?
3 direct replies — Read more / Contribute
by Darkwing
on Jun 30, 2016 at 03:14

    the docu of constant says that constants such as

    use constant DEBUG => 0;
    are inlined. In, the corresponding lines of code are:
    ... if (@_ == 1) { my $scalar = $_[0]; *{"${pkg}::$name"} = sub () { $scalar }; } ...
    But here, a local variable is defined and then used within a sub defined in this block. This should result in a closure rather than in an inlinable subroutine: whenever this block is executed, a new $scalar variable is created and it won't be removed since the subroutine accesses it. So, i understand closures to work. But then the body of the sub isn't a constant value, it is a variable, and so it should not result in an inlinable constant.

    Well, i'm wrong? Are those constants really inlined? Bit if so, why does it work? Why aren't they closures?

Reformat command output inline
3 direct replies — Read more / Contribute
by RenMcCourtey
on Jun 29, 2016 at 08:54

    Hello, I'd like to seek your help on tedious task I'm fighting today. I need to reformat ldapsearch output to acceptable form, and I'd prefer to do that inline with one command. Originally I had complex piped steps of sed and grep and then I realized perl could do that better but I don't know how. Basically I'd like to drop empty or ^dn: lines and merge some other lines together while trimming them. Source looks like this:

    dn: distinguished_name1 cn: common_name1 orclnetdescstring: complex_address_line1 dn: distinguished_name2 cn: common_name2 orclnetdescstring: complex_address_line2 dn: distinguished_name3 cn: common_name3 orclnetdescstring: complex_address_line3
    And the result should go like this:
    common_name1=complex_address_line1 common_name2=complex_address_line2 common_name3=complex_address_line3
    Now I believed this one liner, which I completed with help here would do that: perl -p0e 's/\n^$|\n^dn:*$//mg','s/cn: //g','s/\norclnetdescstring: /=/g' nejms.txt but it doesn't. And as it's getting more complex, I can't see the errors and maybe I'd be better with original sequence of more generic commands, I'm not sure.
Remove html tags to obtain plain text
4 direct replies — Read more / Contribute
by Mj1234
on Jun 29, 2016 at 06:02
    Hello Monks,

    I have a string as shown below. I want to extract only the plain text and assign it to a scalar using HTML::Parser. How can this be done?

    $string = '<style>table{border-collapse: collapse;margin-left: 1cm;fon +t-Family: courier;width: 60%}.hoverTable tr{background: #D8D8D8;} .ho +verTable tr:hover{background-color: #ffff99; }</style><table border=2 + class="hoverTable">[20160628_151916] <tr><td bgcolor="#366092"><font + color="White"> PLAIN TEXT TO BE EXTRACTED</td>';
Remove SOME new lines
4 direct replies — Read more / Contribute
by RenMcCourtey
on Jun 29, 2016 at 05:06

    Hi, I just hit the issue somewhere I wouldn't expect it. Let's say I want to remove new lines from file, but only some of them. It's obvious to me how to get rid of them all, and it's also what is described everywhere. But while it's easy to replace all Us with Os and all new lines with 'bla', how do I remove new lines from lines starting with U only? I tried following without any success:

    perl -pe 's/\nU/U/g' /tmp/nejms.txt perl -pe 's/^U/U/g' /tmp/nejms.txt
state is the root of evil?
4 direct replies — Read more / Contribute
by basiliscos
on Jun 29, 2016 at 05:04

    Hello dear monks,

    My colleges too-frequently use state feature for aggressive caching. That makes some test problematic, and the functions to be unpure. I'm asking them do not use state, but it seems my arguments aren't strong enough.

    I think I've read some article about state feature misuse, but I can't remember it. If you have a link to some blog, please, share it

    PS. May be I'm not right and state isn't so bad?

    WBR, basiliscos.
RegExp: words excepstions list similar to characters' one.
3 direct replies — Read more / Contribute
by nikolay
on Jun 29, 2016 at 02:23
    Hi. How do i use words excepstions list (like [^qwe|asd]) -- similar to characters' one ([^ghjk])? -- I try to write a script, that would exchange word parts, that contains sign '-', where these parts do not contain (exception) given lists? For example, in the code below
    $z='Web-developer, perl-program, explicit-element, function-call, 2-x +speed.'; print "|$z|\n---\n"; $vrm='(?^ui:(\W)([^(\d|web)]+)-([^(proramm|call)]+)) "1>$1<3>$3< 2> +$2<"'; @bz=split "\t", $vrm; for( $i=0; $i<$#bz; $i+=2 ){ while( $z=~s#$bz[$i]#$bz[$i+1]#g ){ print "|$z|\n"; # <STDIN>; } }

    i want that each part in the 2-word combination, except 'explicit-element', will remain the same, and only 'explicit-element' be turned to 'element explicit' -- because their parts are listed in lists: 'Web-developer' remains the same because its first part 'Web' is in the regular expression, before the sign '-', same for '2-x', whereas 'perl-program' and 'function-call' second parts ('program' and 'call') are listed in the regular expression after sign '-'.

    So, what to do in PERL w/ the exception list for words? Thank you for any advance.

show/hide an Entry field
3 direct replies — Read more / Contribute
by dadenn
on Jun 28, 2016 at 20:29
    I have a Perl-Tk script that uses frame/checkbox/Entry widget to ask for a new LDAP password. I use show=>'*' to mask the actual password. I have over 300 group accounts that have complex passwords and have to change every 180 days. We make up an excel spreadsheet (password protected) to create the new passwords, then copy/paste them into the script. I need a way to toggle from the masked password to the clear text password to ensure the copy/paste was what I expected before I issue the LDAP command to alter it. Is this even possible?
Restful Client Query
4 direct replies — Read more / Contribute
by beckmanel
on Jun 28, 2016 at 12:57

    Problem implementing a relatively simple restful client query, that I have already implemented in curl. A request for device information from a cisco ISE server.

    #!/usr/bin/perl use warnings; use REST::Client; use LWP::UserAgent; use JSON; use MIME::Base64; use Data::Dumper; $ENV{HTTPS_VERSION} = 3; $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; ######################################################## # This works in the shell ######################################################## #curl -k 'https://<myuser>:<mypassword>@<myhost>/webacs/api/v1/data/De +vices' my $host = 'https://<myhost>'; my $user = '<myuser>'; my $pwd = '<mypassword>'; my $client = REST::Client->new(host => $host); my $encoded_auth = encode_base64("$user:$pwd", ''); $client->GET("/webacs/api/v1/data/Devices", {'Authorization' => "Basic $encoded_auth", 'Accept' => 'application/json'}); print 'Response: ' . $client->responseContent() . "\n"; print 'Response status: ' . $client->responseCode() . "\n"; foreach ( $client->responseHeaders() ) { print 'Header: ' . $_ . '=' . $client->responseHeader($_) . "\n"; } __END__ Response: Can't connect to <myhost>:443 LWP::Protocol::https::Socket: SSL connect attempt failed with unknown +errorerror:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert h +andshake failure at /usr/lib/perl5/site_perl/5.10.0/LWP/Protocol/http line 47. Response status: 500 Header: Content-Type=text/plain Header: Client-Date=Tue, 28 Jun 2016 13:56:58 GMT Header: Client-Warning=Internal response
    Thank You !!

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 cooling their heels in the Monastery: (10)
    As of 2016-06-30 17:15 GMT
    Find Nodes?
      Voting Booth?
      My preferred method of making French fries (chips) is in a ...

      Results (399 votes). Check out past polls.