Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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
It does not change password in LDAP Windows 2012 R2
No replies — Read more | Post response
by francism8
on Feb 21, 2017 at 09:52

    Dear Perlmonks geeks,

    I'm creating script which will do a password reset that will connect using LDAP in Windows 2012 R2. I have tried this below script and it work using Windows 2008 R2 LDAP connection but when I run this in Wndows 2012 R2 it says successful but the password did not change. Anyone using Windows 2012 LDAP connection to reset password? that can show how its done. Thanks

    #!/usr/bin/perl -w # # changing user passwords in AD # use strict; use warnings; use Net::LDAP; # module needed to encode AD password use Unicode::String qw(utf8); # # ARGV is username password my $username = $ARGV[0]; my $passwd = $ARGV[1]; my $result; my $adsvr='twnlab.local'; my $adbinddn='cn=useradmin,ou=SERVICEDESK,ou=User,dc=twnlab,dc=local'; my $adpw='P@ssw0rd11'; # Connect to the AD server #my $ad=Net::LDAP->new($adsvr, version=>3, scheme=>'ldaps', port=>636, +) or die "can't connect to $adsvr: $@"); # For LDAP Windows 2008 R2 my $ad=Net::LDAP->new($adsvr, version=>3, scheme=>'ldap', port=>389,) +or die "can't connect to $adsvr: $@"); # For LDAP Windows 2012 R2 # Bind as Administrator $result=$ad->bind($adbinddn, password=>$adpw); if ($result->code) { LDAPerror ("binding",$result); exit 1; }; # check for username, get DN $result = $ad->search( base => "ou=User,ou=User,dc=twnlab,dc=local", filter => "(samAccountName=$username)", attrs => ['distinguishedName'] ); $result->code && die $result->error; if ($result->entries != 1 ) { die "ERROR: User not found in AD: $usern +ame" }; my $entry = $result->entry(0); # there can be only one my $dn = $entry->get_value('distinguishedName'); my $unicodePwd = utf8(chr(34).${passwd}.chr(34))->utf16le(); # change password entries etc. #$result = $ad->modify($dn, replace => {unicodePwd=> $unicodePwd,}); # +password change for 2008 AD $result = $ad->modify($dn, replace => {userPassword=> $unicodePwd,}); +#password change for 2012 AD $result->code && die $result->error; print "AD : SUCCESS: ${username} password changed.n"; $ad->unbind();
cgi progressbar
2 direct replies — Read more / Contribute
by bigup401
on Feb 21, 2017 at 07:03

    i have tried to look around the proper way of progressbar in html. bt no good information i have been playing around with progrssbar in commandline bt not in cgi. as they say perl is good for open source bt web apps not easy too much time to take and alot tests

    any idea or simple. i appreciate

    if (execute code){ # execute code to run } while (the code is runing ) { # show the progress .. show the progressbar from 1 } elsif (the code has finished running) { #stop the progressbar at 100% } else (the code has not executed) { # dont let the progressbar to run } print "Content-type: text/html\n\n"; print <<START_HTML; <!DOCTYPE html> <html> <style> #myProgress { width: 100%; background-color: #ddd; } #myBar { width: 1%; height: 30px; background-color: #4CAF50; } </style> <body> <h1>JavaScript Progress Bar</h1> <div id="myProgress"> <div id="myBar"></div> </div> <br> <button onclick="move()">Click Me</button> <script> function move() { var elem = document.getElementById("myBar"); var width = 1; var id = setInterval(frame, 10); function frame() { if (width >= 100) { clearInterval(id); } else { width++; = width + '%'; } } } </script> </body> </html> START_HTML
multiple machines disk space alert
1 direct reply — Read more / Contribute
by vikas330
on Feb 21, 2017 at 06:38
    Hello Monks,

    I'm new to perl, so maybe I'm asking a simple perl script but for me its typical.

    Please help me with a script for getting alerts on mail if FS utilization on machines exceeds 90% utilization and the output should be in tabular format.

    I have the command to list all the FS having more than 80% utilization but I'm unable to print those outputs in a tabular format by writing perl script,

     $ssh $u@$i "df -P | /usr/bin/awk '0 + \$5 >= 80 {print}'" >> $FILE output to a file then I want to list all those FS with fields like

    Server_Name FS_mount_point Utilization(in %)

    and print all those in a mail in tabular format with fields like above. Thanks
Solved : decimal to hex in an array
3 direct replies — Read more / Contribute
by t-rex
on Feb 21, 2017 at 05:31

    hello monks,

    I have an array where I need to convert every even index element to hex , I have written a code but the output is not what i expected

    my @a = "1 10 5 345 2 12"; my $indx=1; foreach my $ind (@a) { print "IND = $ind and index = $indx\n"; if ($ind%2==0) { $ind = sprintf("0x%x",$ind); } $indx++; } print "final conversion input array = @a\n";

    actual output : 1 0xa 5 345 0x2 0xc

    expected output : 1 0xa 5 159 2 0xc

    please let me know where I am going wrong ?

    edit : i got my error , just because of same names i made a silly mistake and couldn't see , sorry for the trouble guys

how extract and group data in a array
4 direct replies — Read more / Contribute
by Anonymous Monk
on Feb 21, 2017 at 00:41

    Hello monks,

    look below data:
    my @dd = qw/AA JJ CC M 1 1 3 4 D JJ 1 1 D M 3 3 4 D C M 3 3 3 D P Z/;
    I'd like to extract all data in M and D(including M & D), and group them respectively like
    my @res1 = qw/M 1 1 3 4 D/; my @res2 = qw/M 3 3 4 D/; my @res3 = qw/M 3 3 3 D/;
    before I manually(ugly)treat them by a loop or recursion, I'd like to ask monks if any module treat this problem.

    Thanks in advance.

Take reference of the return result from a function
3 direct replies — Read more / Contribute
by daveola
on Feb 20, 2017 at 22:19
    Is there a syntax to simply turn the value of something returned from a function into a reference? For example, I want to return an array reference for an array built by map. Right now I am doing:
    my @tmp = map { ... } @somearray; return \@tmp;
    I'd prefer something like:
    return ref_of map { ... } @somearray;
    I know I could do it by writing another routine or using a library, but I was wondering if there was anything in plain old perl that can accomplish this?
Control:CLI or Net::SSH2 - Send <ctrl>_
4 direct replies — Read more / Contribute
by ImJustAFriend
on Feb 20, 2017 at 12:50
    Monks, in the process of creating some automation I have ran into a roadblock. I need to send the device the key sequence <ctrl>_ but nothing I have tried has worked so far. My efforts include:


    Any help would be greatly appreciated!!
Devel::Peek Dump() not printing out
1 direct reply — Read more / Contribute
by ultranerds
on Feb 20, 2017 at 11:56
    Hi, I'm try to write a script that accesses a "curl" command to grab a paypal transaction back. The "grab" works ok, but I'm having fun with the utf8 characters. I'm trying to do some debugging using Devel::Peek, but it doesn't want to work. I literally get no output. I know the command is running, as I'm putting debug text either side of the code, and they print fine. Surely this is right?
    use Devel::Peek; Dump("foo");
    I've even tried:
    use Devel::Peek; Devel::Peek::Dump("foo");
    use Devel::Peek; print Dump("foo");

    What am I doing wrong? I'm baffled


How to read compressed (gz) file in xml::twig
1 direct reply — Read more / Contribute
by CSharma
on Feb 20, 2017 at 04:47
    Hi Monks,

    Purpose: I've hundreds of compressed (.gz) xml files from which I've to create distribution of values of 'EstimatedCPC' tags from xml files. Issue: I'm not sure how to read gzipped file in xml::twig; I don't want to unzip each file then read. Is there any way to read directly? Please help. Also code:2 is throwing "Wide character in print at /usr/local/share/perl/5.22.1/XML/ line 8628." this error. How to fix this?

    Perl Code 1:

    my $file = 'file.xml'; my $twig = new XML::Twig; ## Get twig object $twig->parsefile($file); ## parse the file to build twig my $root = $twig->root; ## Get the root element of twig my @elements = $root->children; ## Get elements list of twig foreach my $e (sort @elements){ my $cpc = ($e->first_child('EstimatedCPC')->text)*100; print $cpc,"\n"; }
    Perl Code 2:
    $twig->parsefile( "file.xml"); # build the twig my $root= $twig->root; # get the root of the twig (stats) my @players= $root->children; # get the player list # sort it on the text of the field my @sorted= sort { $b->first_child( $field)->text <=> $a->first_child( $field)->text } @players; print '<?xml version="1.0"?>'; # print the XML declaration print '<!DOCTYPE stats SYSTEM "stats.dtd" []>'; print '<stats>'; # then the root element start tag foreach my $player (@sorted) # the sorted list { $player->print; # print the xml content of the elemen +t print "\n"; } print "</stats>\n"; # close the document
    Example of xml:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <CatalogListings> <Offer id="af94bdd18ff9ffbf66afb5286dcb68fa"> <Command>new</Command> <Title>Puma Pitch Shorts</Title> <Description>Pitch Shorts: Let your football team look like pr +os and play like pros with these lightweight shorts from PUMA. Highly + functional materials draw sweat away from your skin and help keep yo +u dry and comfortable during exercise. Get ready for dry with dryCELL +. Bio-based wicking finish to keep you dry.</Description> <EstimatedCPC>0.0434</EstimatedCPC> <LastModified>2017-02-15 21:31:41</LastModified> <Images> <Image available="true"> <Url> +/ +_01_EEA%3F%24PUMA_GRID%24/d4qCltxt.0XARAbgLGRcGsAKxgSY3iHhaVcF_7bEuPg +-</Url> </Image> </Images> <Url> +45527057&amp;.sig=Ch1dMBKSr5hhrL8bNhlNkv_GMSg&amp;catId=100353523&amp +;localCatId=100353523&amp;comId=11210623&amp;offerId=af94bdd18ff9ffbf +66afb5 286dcb68fa&amp;searchId=null&amp;affiliationId=96951977&amp;country=uk +&amp;wait=true&amp;contextLevel=2&amp;service=11</Url> <MobileFriendly>false</MobileFriendly> <Merchant id="11210623"/> <Category id="100353523"> <Name>Miscellaneous</Name> </Category> <Price currency="GBP"> <Price>20.0</Price> <DeliveryCost>3.95</DeliveryCost> <TotalPrice>23.95</TotalPrice> </Price> <ProductClass>0</ProductClass> <Availability>1</Availability> <OffensiveContent>false</OffensiveContent> <Ean>4055261425365</Ean> <MerchantCategory>Male|Mens Sports Football Pants &amp; Sho +rts</MerchantCategory> <Brand>Puma</Brand> <BrandId>2571</BrandId> <Model>Pitch Shorts</Model> <Currency>GBP</Currency> </Offer> </CatalogListings>
url results
3 direct replies — Read more / Contribute
by bigup401
on Feb 20, 2017 at 04:41

    any idea how i can get off this


    so that even if i submit data. it remains http://localhost/

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

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (13)
    As of 2017-02-21 16:57 GMT
    Find Nodes?
      Voting Booth?
      Before electricity was invented, what was the Electric Eel called?

      Results (314 votes). Check out past polls.