Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Seekers of Perl Wisdom

by gods
on Sep 07, 1999 at 20:28 UTC ( #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
Sending mails via gmail
2 direct replies — Read more / Contribute
by morgon
on Aug 30, 2016 at 16:57
    Hi all,

    I just realize that I am not up to date with emails in Perl anymore.

    Last time I wanted to programatically to send an email I was using MIME::Lite, but that won't impress the kids today...

    What I want to do is to send mails using my gmail-account and I am bit baffled so see that there is plethora of options:


    So as I am too lazy to read lots of reviews my question is:

    Is there currently a canonical/best/preferred way to send mails via gmail or are all the different ways equally valid options and it only comes down to taste?

    Many thanks!

How to print months in proper order from array
1 direct reply — Read more / Contribute
by dirtdog
on Aug 30, 2016 at 15:43

    Hi Monks

    I'm trying to figure out how to print unique months in their proper order. I have a Hash of Hashes and I'm storing the unique values into an array, but that may not be the best way to do it in order to achieve my goal, which is to display all the unique months in proper order from my available data...jan,feb,mar, etc.

    I'm hoping someone can help with this and maybe even show a better(using less lines of code) way to accomplish this task. My code is as follows.

    #!/usr/bin/perl use strict; my %HoH; my $months; my $key; my %seen; my @uniq; my $client; my $Months_count; while (<DATA>) { ($client,$Months_count) = split /\|/, $_; my %by_month = split ' ', $Months_count; $HoH{$client} = \%by_month; } while ( ($client, $months) = each %HoH ) { while (defined ($key = each %$months)) { $seen{$key}++; } @uniq = keys %seen; } print "@uniq\n"; __DATA__ IBM | February 1 March 5 July 4 Oracle| January 3 March 4 April 6 May 5 RedHat | March 2 June 3 August 1

    Any help is greatly appreciated!

Stuck trying to use Win32::API
1 direct reply — Read more / Contribute
by newbieperlperson
on Aug 30, 2016 at 14:43
Oh my, PERL Data
3 direct replies — Read more / Contribute
by ichinyo
on Aug 30, 2016 at 14:03
    I like the way PERL looks, though I am watching video, as boring as anything. I have a guide book, makes things look easier. Here is a question, how would a data field work. In BASIC there is read, then that does a data function. like. Read N$, A,B,C print n$,A,B,C data Bob Jones, 23,45,67 end Run Bob Jones 23 45 67. How could PERL be used like spread sheet? Thanks
Take last instance of a string
4 direct replies — Read more / Contribute
by porsche5k
on Aug 30, 2016 at 13:13

    Hi Perk Monks,

    The words "Significant Accounting Policies" are referenced multiple times in my document. I am interested in taking the last reference of "Significant Accounting Policies" and extracting the next text to the end of the document.Is there a Perl function that does this?

    Short, simple example


    Wal-mart talks about its Significant Accounting Policies in its 10k.

    Significant Accounting Policies are important for a firm.

    Here is a list of the Significant Accounting Policies




    As I said, I'm hoping to take from "1)Lifo..." down to "...Expenses". Thank you for your help!

Store only object data but not the whole class
3 direct replies — Read more / Contribute
by exilepanda
on Aug 30, 2016 at 06:38
    package Whatever; sub new { bless { foo => 'bar' }, shift; } 1; package main; use Storable; my $obj = new -> Whatever; store $obj , "somefile.sto";

    Given a condition like the code above, the Storable file will store the data structure with it's class. But what I want to do is only store { foo => 'bar' } without the blessed ref.

    I can actually do this with unbless from Data::Structure::Util qw( unbless );

    However, I remember I did get this job done with a simpler way yrs ago without using module. Seem I had played with of sort of de-referencing trick, but I really forget how to make that up anyway. Do you know how?

How to Deal with Pop ups when trying to automate a software through perl
1 direct reply — Read more / Contribute
by ankit.tayal560
on Aug 30, 2016 at 00:22

    hi,i am trying to automate a software through perl.I am able to open it through a script file but as soon as the software opens it generates a pop up asking for "I accept" how to handle these pop ups in perl to automate the software? please help

Mojolicious to and from buttons
1 direct reply — Read more / Contribute
by docdurdee
on Aug 29, 2016 at 17:57
    Dearest Monks, I am dipping my feet into all things webapp with a simple application. I would like to build web app to render a list of files in a filesystem directory and attach and actionable button to each one. In the attempt below, the get method sends the list of files to the stash and then renders the list of files/button as expected. The trouble seems to be in how the button is templated. How can the button be set up to attach the filename to the button which sends it off to another method on the click? Eventually, I would like to get resulting output posted into a frame on the righthand side of the page with the list of files remaining on the left and side; I know this will take a few more steps, but for now I am stuck. Thanks in advance.
    #!/usr/bin/env perl use Mojolicious::Lite; use Path::Tiny; plugin 'TagHelpers'; get '/' => sub{ my $c = shift; my $path = path("/Foo/Bar/Baz"); $c->stash(filepath => $path, files => [$path->children(qr/\.txt/)] + ); $c->render('index'); }; post '/' => sub{ my $c = shift; my $file = $c->param('id'); print $file; # print to console $c->render(text => $file); }; app->start; __DATA__ @@ index.html.ep % layout 'default'; % title $filepath ; <h1>Let's test the files in <%= $filepath %>!</h1> <table border="1"> <tr> <th>File</th> <th>Action</th> </tr> % foreach my $file (@$files) { <tr><td><%= $file %></td> <td> %= form_for '/' => (method => 'POST') => begin %= submit_button 'validate', id => $file % end </td> </tr> % } </table> @@ layouts/default.html.ep <!DOCTYPE html> <html> <head><title><%= title %></title></head> <body><%= content %></body> </html>
    EDIT: I think I figured it out the first step. I got rid of the post command, and added a new get with a route placeholder:
    get '/validate/*filename' => sub{ my $c = shift; print $c->param('filename'),"\n\n\n\n"; # print to console $c->render('index'); };
    Then I mixed a little JQuery into the button:
    <input type='button' value='validate' onclick = "$.get('/validate/<%= +$file %>');">
    And that sends back the file name. Very cool. Thanks in advance if you point out a better way or provide any other tips.
How to stuff space separated column into Hash
4 direct replies — Read more / Contribute
by dirtdog
on Aug 29, 2016 at 14:22

    Hi Monks

    I'm having a very hard time trying to get some results from a sql statement using WriteExcel module into a Hash.

    The results from my sql statement yield 2 columns: Client is column 1 and Month followed by total orders for that month as column 2

    for example,

    Client|Counts by Month

    IBM | February 1 March 5 July 4

    Oracle| January 3 March 4 April 6 May 5

    RedHat | March 2 June 3 August 1

    The first result would be in @row so @row[0] would be equal to IBM and @row1 would be equal to 'February 1 March 5 July 4'.

    Somehow I need to split the values of @row1 into a hash so the Key->value pair would be February->1, March->5, July->4, but that is where I'm getting stuck.

    Any help would be greatly appreciated!

pdf libraries for Strawberry Perl
3 direct replies — Read more / Contribute
by Dr. D
on Aug 29, 2016 at 14:18
    Hello, I'm using Strawberry Perl v.5.10.0 under 64-bit Windows Server 2008 R2. I wrote a script which generates some output, and my goal is to generate a pdf file. I tried to install different CPAN libraries, but they all have same issue - they require NMake utility. It used to be available from Microsoft, but no longer is. I did extensive search but couldn't find a single place where I could download it from. Please help. How can I use pdf format in my script. 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 browsing the Monastery: (3)
    As of 2016-08-31 02:18 GMT
    Find Nodes?
      Voting Booth?
      The best thing I ever won in a lottery was:

      Results (426 votes). Check out past polls.