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
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.
Perl:Use of array elements in pattern matching
2 direct replies — Read more / Contribute
by rahulme81
on Aug 29, 2016 at 00:17

    I need to use array elements while pattern matching.

     @myarr = (ELEM-1, ELEM-2, ELEM-3,ITEM-1,ITEM-2,ITEM3);

    ELEM-1, ELEM-2, ELEM-3,ITEM-1,ITEM-2,ITEM3 are the distinct column values from a file which I read in beginning of my scripts and store them in @myarr.

    Basically What I intend to do is

    1. If my @myarr = (ITEM-1,ITEM-2,ITEM3) ==> I print all the information from items.txt file.

    2. If my @myarr = (ELEM-1, ELEM-2, ELEM-3) ==> I print all the information from elem.txt file.

    3. If my @myarr = (ELEM-3,ITEM-1,ITEM-2,ITEM3)

    ==> I want to print all the information from items.txt file + Some few lines for elem.txt (Based on Pattern Match in file with keyword ELEM-3 in @myarr)

    I am able to code the things for 1 and 2 but not not able to achieve my Point 3 If my @myarr = (ELEM-3,ITEM-1,ITEM-2,ITEM3)

    I need a generic code instead of hardcoding the array elements inside the code since array elements are not known & may vary.

    Thanks in advance.

Archive::Extract - error handling
2 direct replies — Read more / Contribute
by luxs
on Aug 28, 2016 at 21:21
    I'm using Archive::Extract, as in the original example.
    use Archive::Extract; my $ae = Archive::Extract->new( archive => 'myfile.tgz' ); my $ok = $ae->extract or die $ae->error;
    And the file myfile.tgz is broken. This code produce error on the screen
    Unable to extract 'myfile.tgz': at ./data_sort.pl line 156.
    and continue to execute the further code, but it should die!!! What was wrong? How to catch this error?
Feedback for programming a UI in Perl
2 direct replies — Read more / Contribute
by stevieb
on Aug 28, 2016 at 19:52

    I'm looking for recommendations on which UI platform to use under Perl.

    As someone who has developed or used Perl-based User Interfaces, please share your experiences with what you have found.

    Feedback on all aspects welcome... integration, ease-of-coding, ease of use, look, feel, documentation, availability of help/guidance here at PM or external etc.

    I'm looking at writing small, short and simple GUI apps that'll be on touch-screens to control events and situations with button pushes. Ease of configuration of text, grey-out, displaying small images etc is what I'm looking for.

    After you have an opinion, answer this...

    What led you to choose what you're using?

Changing font colour in a Wx StaticText or Button
5 direct replies — Read more / Contribute
by stevieb
on Aug 28, 2016 at 17:05

    I'm working on a GUI for one of my projects (I dislike UI programming, specifically non-web), which will be as basic and simple as possible. I chose Wx, simply because it's a tad bit prettier (than Tk). This UI is being designed for a 5" touch-screen, and doesn't need many features.

    I'm wondering with Wx, how I can change the font colour of a simple StaticText (or even a button). The docs are sparse, but even the perl and XS code don't seem to have anything relating to changing colours.

    Am I missing something, or is this just the way Wx is? If Tk or (insert suggestion here) can be manipulated to do simple things like change the colour of a font, I'll seriously consider changing to that (to begin with, Wx was a PITA to get set up on a Raspberry Pi, so I'm half-way toward changing as-is).

    my $font = Wx::Font->new(16); $self->{t_header} = Wx::StaticText->new( $panel, 1, "Temperature", $self->{xy}{t_header} ); $self->{t_header}->SetFont($font);

    update: The code and references to other code in this and subsequent nodes require trunk installs of certain modules. CPAN versions will not have the updates to render things properly...

Perl with redistributable web server and mysql?
6 direct replies — Read more / Contribute
by whiteperl051
on Aug 28, 2016 at 14:02

    I love Perl. It's awesome.

    I've been thinking of writing software in Perl that can be used on Windows but for it to work I will require a redistributable web server and perhaps Mysql? to go with that.

    So, the way it would work is that I have a setup.exe file that I offer for download. When setup.exe is run to install my app it will install a webserver on port 12345 with mysql and then execute my Perl scripts - and this is all done on the host machine. Hope this makes sense.

    Is there perhaps a web server I can borrow or redistribute with my Perl app so that I don't have to re-create a web server myself which can execute and run the Perl scripts.

    Some apps that work this way (you simply install it and the app runs in a web browser on a server running on the local host) that come to mind is:

    sabnzbd / deluge / sonarr / etc.

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.