Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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
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!
Perl output format
1 direct reply — Read more / Contribute
by voltas
on Aug 29, 2016 at 09:54
    I'm reading a log file and grouping it based on the 'Program' name. LOG FILE
    ------------------------------------------ DEV: COM-1258 Program:Testing Reviewer:Jackie Description:New Entries rev:r145201 ------------------------------------------ QA: COM-9696 Program:Testing Reviewer:Poikla Description:Some random changes rev:r112356 ------------------------------------------ JIRA: COM-1234 Program:Development Reviewer:John Wick Description:Genral fix rev:r345676 ------------------------------------------ JIRA:COM-1234 Program:Development Reviewer:None Description:Updating Received rev:r909276 ------------------------------------------ JIRA: COM-6789 Program:Testing Reviewer:Balise Mat Description:Audited rev:r876391 ------------------------------------------ JIRA: COM-8585 Program:Testing Reviewer:Gold frt Description: yet to be reviewed rev:r565639
    The code I have, (with the help of one of an esteemed perl monk :))
    #!/usr/bin/perl use strict; use warnings; use Data::Dumper; $Data::Dumper::Sortkeys = 1; $Data::Dumper::Terse = 1; my $file = "log.txt"; open FH, $file or die "Couldn't open file: [$!]\n"; my $data = {}; my $hash = {}; while ( <FH> ) { my $line = $_; chomp $line; if ( $line =~ m/(-){2,}/ ) { my $program = $hash->{Program} || ''; my $jira = $hash->{JIRA} || $hash->{QA} || $hash->{DEV} || +''; if ( $program && $jira ) { push @{ $data->{ $program }{ $jira }}, $hash; $hash = {}; } } else { if ( $line =~ m/:/ ) { my ( $key, $value ) = split /:\s*/, $line; $hash->{ $key } = $value; } elsif ( $line =~ m#/# && exists $hash->{Files} ) { $hash->{Files} .= "\n$line"; } } } print 'data = ' . Dumper( $data ); foreach my $prg ( sort keys %{ $data } ) { print "=========================================================== +=\n"; print " PROGRAM : $prg + \n"; print "=========================================================== +=\n"; foreach my $jira ( sort keys %{ $data->{ $prg }}) { print "******************\n"; print "JIRA ID : $jira\n"; print "******************\n"; foreach my $hash ( @{ $data->{ $prg }{ $jira }} ) { foreach my $key ( keys %{ $hash }) { # print the data except Program and JIRA next if $key =~ m/(Program|JIRA|DEV|QA)/; print " $key => $hash->{ $key }\n"; } print "\n"; } } }
    I have a requirement to print the output in the below format and currently unable to do so, any ideas would be really helpful.Thanks. btw I'm very new to perl , so pls. excuse me if its a blunt question. EXPECTED OUTPUT is below,
    PROGRAM: Development Change IDs: 1.JIRA a.COM-1234 PROGRAM: Testing Change IDs: 1.JIRA a.COM-6789 b.COM-8585 2.QA a.COM-9696 3.DEV a.COM-1258
Reading Excel with different format
1 direct reply — Read more / Contribute
by 9mohit2
on Aug 29, 2016 at 08:16
C:\ProgramData\Microsoft\Windows\Start Menu is not an internal or external command,operable program or batch file
2 direct replies — Read more / Contribute
by ankit.tayal560
on Aug 29, 2016 at 06:13
    $me="C:/ProgramData/Microsoft"; $me.="/Windows/"; $me.="Start Menu"; $me.="/WinZip"; system("$me");

    it shows an error " not an external or internal command, operable program or batch file" how can I resolve it?

Installing Perl Modules
3 direct replies — Read more / Contribute
by 9mohit2
on Aug 29, 2016 at 02:42

    Hi, I am new to Perl and having some problems while installing perl modules on my corporate network as CPAN command line does not works neither the PPM gets updates with more modules. Generally I download the tar.gz from metacpan and paste the .pm files in the exact directory where the modules files are searched. But I am facing problem installing the modules like Par::Packer may be as it is based on C files. Please let me know a way in which I can manually install the modules which are based in C with their dependencies. Thanks in Advance.

How to overwrite the response server name in mojolicious
1 direct reply — Read more / Contribute
by vijay_be14
on Aug 29, 2016 at 02:01
    Hello All,

    I created the REST API service using Mojolicious. Done on implement the service. But the question, Is there way to overwrite the server name in rest response.
    For example,

    Content-Length: 22
    Content-Type: application/json;charset=UTF-8
    Server: Mojolicious (Perl)
    Date: Fri, 26 Aug 2016 13:44:39 GMT

    Whether its possible for change the name called 'Mojolicious (Perl)' to 'My Application Name'
    Please help me to clear out this.

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 contemplating the Monastery: (10)
    As of 2016-08-30 17:17 GMT
    Find Nodes?
      Voting Booth?
      The best thing I ever won in a lottery was:

      Results (420 votes). Check out past polls.