Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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
removing the need for tmp files from script
3 direct replies — Read more / Contribute
by novice2015
on Jul 22, 2016 at 12:09
    I have this script in which I am trying to clean up the tmp file output and use only arrays and variables. It does work, I created it a while back.
    open my $bpl_fh, '<', '/tmp/bpl.txt' or die $!; chomp(my @words = <$bpl_fh>); close $bplist_fh; my $pattern = join '|', @words; my @lines; open my $fh, '<', '/tmp/lst.txt' or die "unable to open file '$file' f +or reading : $!"; open my $fh2, '>', '/tmp/lst2a.txt' or die "unable to open file '$file +' for reading : $!"; while (<$fh>) { push @lines, $_ if /$pattern/; } print $fh2 "$_\n" foreach @lines; close $fh2;
    So I have made bpl and bpout into an arrays but I am unsure of how to write the while statement. I want it to perform the same task as the above script but without using the /tmp/files to read from and output
    chomp(my @words = @bpl); my $pattern = join '|', @words; #my @lines; my $item; while (@bpout) { my $item = (@bpout); push $item, $_ if /$pattern/; } print "$_\n" foreach $item;
    Does anyone have suggestions?
Decoding an email body, into utf8
1 direct reply — Read more / Contribute
by ultranerds
on Jul 22, 2016 at 08:55

    I'm trying to decode an email body, with stuff like:

    =C2=A0 *Email:*=C2=A0 =C2=A0=C2=A0

    I'm trying to use this module:

    But it doesn't seem to want to work for me :(

    my $message = q|testing a reply *Do it as *html=C2= =A0I guess Andy Newby=C2=A0 *Email:*=C2=A0 =C2=A0=C2=A0 +k =C2=A0 * WWW: =C2=A0 =C2=A0=C2=A0 * uk =C2=A0 Mobile:=C2=A0* = =C2=A002269 201 576 =C2=A0=C2=A0 |; use MIME::Words qw(:all); my $test = decode_mimewords($message); print "FOO: $test \n";

    All I get outputted, is the exact same input. Could someone please advise on how I can do this? (I've never really dabbled with reading emails before, so this is a bit new to me)


Install perl packages using yum
2 direct replies — Read more / Contribute
by ravi45722
on Jul 22, 2016 at 06:56

    I want to install perl modules in the CentOS using yum. I tried yum install perl-Search-Elasticsearch. Its saying no such module. I tried

    yum install perl-Excel-Writer-XLSX Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: * epel: * extras: * rpmforge: * updates: Package perl-Excel-Writer-XLSX-0.84-1.el7.noarch already installed and + latest version Nothing to do

    But it is an older version. For this I updated my yum also. Still the problem is same. I need to update my perl library for this??? Then how to update the library ????

    perl -v This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-li +nux-thread-multi
Net::Google::WebmasterTools: GWMT error: 404 Not Found
1 direct reply — Read more / Contribute
by Frosch
on Jul 22, 2016 at 06:09


    when trying to use Net::Google::WebmasterTools I am getting the following error: +searchAnalytics/query GWMT error: 404 Not Found Not Found at ./ +line 43, <DATA> line 2231.
    Here the used script (the credentials in this example like $client_id, $client_secret and $refresh_token have been certainly substituted by my own credentials).
    #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Net::Google::WebmasterTools; use Net::Google::WebmasterTools::OAuth2; # Insert your website URL here. my $site_url = ""; # See GETTING STARTED for how to get a client id, client secret, and # refresh token my $client_id = ""; my $client_secret = "rAnDoMsEcReTrAnDoMsEcReT"; my $refresh_token = "RaNdOmSeCrEtRaNdOmSeCrEt"; my $wmt = Net::Google::WebmasterTools->new; # Authenticate my $oauth = Net::Google::WebmasterTools::OAuth2->new( client_id => $client_id, client_secret => $client_secret, ); my $token = $oauth->refresh_access_token($refresh_token); $wmt->token($token); # Build request my $req = $wmt->new_request( site_url => "$site_url", report_name => "searchAnalytics", method => "query", dimensions => ['country','device'], search_type => 'web', start_date => "2016-07-01", end_date => "2016-07-20", row_limit => 1000, ); # Send request my $res = $wmt->retrieve($req); die("GWMT error: " . $res->error_message) if !$res->is_success; # Print results print "Results: 1 - ", $res->items_per_page, " of ", $res->total_results, "\n\n"; for my $row (@{ $res->rows }) { print $row->get_source, ": ", $row->get_visits, " visits, ", $row->get_bounces, " bounces\n"; } print "\nTotal: ", $res->totals("visits"), " visits, ", $res->totals("bounces"), " bounces\n";

    Any ideas what might be wrong?

    Best regards, Frosch
Parse cmd line args in this file
4 direct replies — Read more / Contribute
by pawarr
on Jul 22, 2016 at 05:07

    Wanted to parse the file parse4 Want to parse script in command line with "Cadence". Please Help. Sorry for the previous post perl monks.

    #!/usr/bin/perl use strict; use warnings; open(my $fh,'data4.txt'); while(my $row = <$fh>){ chomp $row; print "$row \n"; }

    Subject: Cadence rivals openly laugh at 2nd secret CDNS management reorg SHHHH! IT'S SECRET!: Starting on Monday of this week, I got emails and phone calls citing a secret weekend Cadence management reorg that Cadence Corporate Marketing was hoping the world wouldn't notice... Note how the CDNS e-staff web page "mysteriously" changed from Friday to Monday: Chi-Ping Hsu Anirudh Devgan Friday, SVP of the Cadence not seen anywhere on Nov 8th Digital & Signoff Group CDNS e-staff page! ??? \ then (*poof!*) \ Monday, Chief of Staff ----> SVP of the Cadence Nov 11th to Cadence CEO ??? Digital & Signoff Group No press release. Nothing on their home page. No announcement. Just POOF! The change secretly "happens". I wouldn't have noticed it at all -- except that Cadence's many rivals monitor and they looove to gossip... ---- ---- ---- ---- ---- ---- ---- Hey, John, Look at today's Cadence e-staff page. Anirudh took digital inplementation from Chi-Ping. - An Anon EDA Vendor ---- ---- ---- ---- ---- ---- ---- The other shoe dropped. After losing Virtuoso to Beckley back in August, Chi-Ping has now lost EDI to Devgan. No press release, but check their Executive Team web page. - An Anon EDA Vendor ---- ---- ---- ---- ---- ---- ---- Looks like Chi-Ping's second wing has been clipped. He's no longer SVP of Digital Implementation. - An Anon EDA Vendor ---- ---- ---- ---- ---- ---- ---- Anonymous please. Chip-Ping has been demoted on the page. - An Anon EDA Vendor ---- ---- ---- ---- ---- ---- ---- Another stealth mgmt shuffle at CDNS. Anirudh is now in Chip's old job. Chip's now on Special Projects. - An Anon EDA Vendor ---- ---- ---- ---- ---- ---- ---- Hi, John, Anirudh should have been made head of EDI two years ago. CDNS is missing too many big PNR renewals. It'll take too long to repair the damage organically with EDI revs. Writing is on the wall. Wished I owned ATOP shares. - An Anon EDA Vendor ---- ---- ---- ---- ---- ---- ---- This is a good move. Anirudh is revitalizing fresh blood which will bring Cadence back into PNR. Mark my words. - An Anon EDA Vendor ---- ---- ---- ---- ---- ---- ---- If they didn't empower Anirudh soon, they might have lost him along with Cadence's chance at taking Synopsys back on. - An Anon EDA Vendor ---- ---- ---- ---- ---- ---- ---- Re: Chi-Ping Hsu & John Chilton Cadence is matching Synopsys. Aart moved John Chilton out of Corp Marketing so he could become GM of SNPS Strategy. Lip-bu needs Chi-Ping as Chief of CDNS Strategy to keep up. - An Anon EDA Vendor ---- ---- ---- ---- ---- ---- ---- Q: How many months did the prior Cadence Chief of Staff last? ---- ---- ---- ---- ---- ---- ---- Internally inside Cadence, most of the employees see this as a positive move. It ensures that Lip-bu gets tight guidance from Chi-Ping as an EDA veteran who really knows the business. The CDNS sales force is excited about Anirudh taking over because they think he's the only viable executive who could lead a total R&D turnaround at Cadence. The only people afraid inside CDNS are the employees who've worked on products that haven't improved in years. He will be a day of reckoning for this dead wood. Best case is Anirudh will turn CDNS digital around in 9 to 12 months. I hear TSMC's top customers approve of this change. - An Anon EDA Vendor ---- ---- ---- ---- ---- ---- ---- And if this story sounds familiar to you -- it should. CDNS did a similar unannounced stealth reorg of its Palladium and Virtuoso senior management 14 weeks ago. See ESNUG 531 #4. Shhhh! It's secret! :) - John Cooley Holliston, MA

Quoting each word in an arrayref
3 direct replies — Read more / Contribute
by soundX
on Jul 22, 2016 at 04:41
    Hi monks,

    I have a number of database queries that return array references. I'm then putting each array reference into a hash so I can return it as json.

    I want to modify each arrayref to produce a comma separated string. I've tried using the following to convert each reference and add it to my hash:

    $return->{$w} = [join(', ', map { $_->[0] } @$rows)];
    This returns "key":["val1, val2"] but I need each word to be quoted like this "key":["val1", "val2"].

    Can anyone spot what I'm doing wrong?

Regex on a variable with special characters
3 direct replies — Read more / Contribute
by jaydee
on Jul 22, 2016 at 04:40
    I have 2 variables one is simple like below.
    $x = "SERVER-NAME";
    and I am trying to see if $y starts with $x, but $y sometimes contains regex special characters like ()[], also ** which can give me errors.

    How can I safely check if $x at the start of $y?

    $y =~ /^$x/;
    is the current regex I am using.
LWP::UserAgent how to download captcha and access web
1 direct reply — Read more / Contribute
by liuweichuan
on Jul 22, 2016 at 03:25
    1. LWP::UserAgent is as a object for browser 2. open url and download captcha, and captcha info wait for input, like $x = <> 3. requirst post to login. my issue is i can't see the captcha info. my $url=""; $Lwp->post($url); open FILE,">abc.jpg" or die "$!"; my $outcome=get ($url); binmode(FILE); print FILE $outcome; ..... $
Convert an array of numbers into a range
3 direct replies — Read more / Contribute
by rmocster
on Jul 21, 2016 at 19:20
    Is there a library to convert an array with padded numbers to a padded range and separated ranges with comma. For example, I like to convert (0001,0002,0003,011,012,013,015) to "0001-0003,011-013,015". Thanks. I found something similar but it doesn't do padded numbers.
Getting a list of directories matching a pattern
2 direct replies — Read more / Contribute
by Perlfan.Felix
on Jul 21, 2016 at 17:11
    Hi, is there a 'glob' for directories in perl ?

    I want to find a list of directories matching a pattern.
    For example, $pattern is set to tomcat_????_?? and $directory is set to /var/log/tomcat.
    Now I want to find these subdirectories:


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 surveying the Monastery: (6)
    As of 2016-07-28 01:56 GMT
    Find Nodes?
      Voting Booth?
      What is your favorite alternate name for a (specific) keyboard key?

      Results (252 votes). Check out past polls.