Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

The Monastery Gates

( #131=superdoc: print w/replies, xml ) Need Help??

Donations gladly accepted

If you're new here please read PerlMonks FAQ
and Create a new user.

New Questions
Will 'when()' be removed or deprecated in upcoming version of Perl?
1 direct reply — Read more / Contribute
by Darkwing
on Jun 22, 2018 at 02:57
    Every now and then i use something this in my code:
    for ($foo) { when (/blah/) {...} when (/xyz/) {...} ... }
    Now this page Beware of the removal of when in Perl v5.28 tells that when() will be removed in perl 5.28, meaning that i would need to change such code. But on this page perldeprecation there is nothing written about removing when() or marking it deprecated. Now, what is correct about the when()?
PERL-CGI on shared unix server
1 direct reply — Read more / Contribute
by rahu_6697
on Jun 22, 2018 at 01:43

    Hello to all! I am new to perl-cgi, just trying to execute my first program and stored it as in my home directory. I am working on a shared unix based server so I don't have access to var/www/cgi-bin folder of my directory and there is not any webserver package installed. So how should i run this type of files. Please provide step by step procedure for running this file such that on browser Hello World! should display.

    #!/usr/local/bin/perl print "Content-Type: text/html\n\n"; print "<html> <head>\n"; print "<title>Hello, world!</title>"; print "</head>\n"; print "<body>\n"; print "<h1>Hello, world!</h1>\n"; print "</body> </html>\n";
How to print data between tags from file sequentially?
2 direct replies — Read more / Contribute
by TonyNY
on Jun 21, 2018 at 23:15

    Hi, I have a text file that contains the follwoing that I want to print one line at a time. is it possible to print only the data between > < sequentiallly?

    <Answer type="string">ServerName</Answer> <Answer type="string"></Answer> <Answer type="string">Windows Server 2012</Answer>

    output would be something like:

    Commputer: ServerName IP Address: OS: Windows Server 2012

    This is what I have so far but it only prints out the entire lines at the same time:

    #!/usr/bin/perl # open file open(FILE, "data.txt") or die("Unable to open file"); # read file into an array @data = <FILE>; # close file close(FILE); # print file contents foreach $line (@data) { print $line; }


Using a thread to provide visual feedback.
3 direct replies — Read more / Contribute
by Anonymous Monk
on Jun 21, 2018 at 10:54

    I have been working on a command line script that makes several system calls, some of which take a few seconds (minutes?) to return. The long pauses give the impression that the script has hung, which isn't great. I figured I could address this by adding some kind of visual "still processing" feedback, like an hourglass or pinwheel. Because it's just a command line script, I do it with dots.
    My code is below. I would appreciate any feedback or suggestions for improvement. Thank you.

Extracting text from MS Word files on a Linux box
3 direct replies — Read more / Contribute
by Laurent_R
on Jun 21, 2018 at 06:30
    Dear fellow monks,

    I need to extract some textual information from a large bunch of MS Word files, mostly at the .doc format (i.e. Office 2003 version or before, if I remember correctly); there also may be some .docx files but let's concentrate on the .doc format for now.

    This is quite new to me, I've never had before to do that, and I am usually not working on Windows platform and Microsoft Office document formats, except for a few cases with Excel documents. So I am not sure how to handle this requirement.

    I also found that there seem to be surprisingly few CPAN solutions for extracting data from MS Word documents (especially in the pre-2003 format).

    The Text::Extract::Word module may be doing what I need, but it has a dependency on the OLE::Storage_Lite module (and perhaps some others). My understanding is the OLE::... domain modules will only work on Windows boxes (because they are presumably using Windows and/or MS Office libraries). Is this a correct assumption? If such is the case, then it would be a problem for us, because, ultimately, the whole much larger process should run on a Linux server.

    Does any monk here have some experience on this type of needs, i.e., to summarize, how to extract textual data from MS Word files (pre-2003 format) on a Linux box, where OLE modules would presumably not run? Any suggestions? Any other module that I overlooked? Thank you very much for any help in this respect.

Searching a pattern in a xlsx
2 direct replies — Read more / Contribute
by kaushik9918
on Jun 21, 2018 at 01:50
    Hi Can anyone here point me to an existing thread or suggest me a good short routine/function to find a user defined pattern in an xlsx and return its row and col number? thanks in advance
Path parsing from full to relative
7 direct replies — Read more / Contribute
by Kaplah
on Jun 20, 2018 at 15:56
    Greetings all. I was wondering how I would accomplish the following. Given a full file path how can I trim it down to the last folder? For instance:


    needs to become:

    The trick here is that the directories are not hard coded. My only life saver is that the "WorkingDirectory" has a naming standard and starts with the same three characters (for argument "ABC"). Is there a way to grab this folder once and then build the other strings? Or can I pull the reverse and subtract the unwanted beginning portion out of my path string? How would I do this?
list of four digit lock combinations without repeated digits
6 direct replies — Read more / Contribute
by Lotus1
on Jun 20, 2018 at 14:58

    I have a spare key lock for my front door that takes four digits without repeated digits and the order doesn't matter. I've forgotten the combination so I wrote a script to give me a list of the possible combinations. I'm planning to replace this since I don't like that it only has 210 possible combinations but I have to open it before I can remove it. Here is my solution. I found the text at the top in one of the answers at

    I'm wondering if there is a way to do this with some modules or if anyone else has interesting solutions.

    use strict; use warnings; # Four digit mechanical lock: no repeated digits, order doesn't matter +. # # +bers-with-no-repeated-digit # Start by finding the permutations: For the first choice, you have 10 + possible digits to choose from. #For the second choice, you have 9 digits because you used one for the + first choice. #The third choice comes from 8 possibilities and the fourth from 7 pos +sibilities. #Now we multiply these together: 10 x 9 x 8 x 7 = 90 x 56 = 5040. That +'s the number of permutations. #No digits repeat, but 0123 is different from 0321. # Now to find the number of combinations, I have to know how many diff +erent ways there are of arranging four digits. #That's the same kind of problem: the first position could be from 4 p +ossibilities, the second from 3 possiblities, #the third from 2 choices and the last has to be the 1 left. So there +are 4 x 3 x 2 x 1 = 24 possible ways of #arranging 4 items. # Therefore I divide 5040 / 24 = 210. So there are 210 different combi +nations of four digits chosen #from 0-9 where the digits don't repeat. my %output; foreach(123..9876){ my $num = sprintf "%04d", $_; next if $num =~ /(\d).*\1/; my @digits = sort split //, $num; my $num_sorted = join '', @digits; #print "$num: @digits - $num_sorted\n"; if (not exists $output{$num_sorted} ) { #print "adding $num_sorted\n"; $output{$num_sorted}=1; } } print "found ", scalar keys %output, " combinations.\n"; print "$_\n" foreach sort keys %output;

    Here are the results:

    Edit:After posting I realized I remembered one of the digits which narrowed the list down by a lot. My $spouse remembered the code before I started trying but the lock would have been opened within my first few attempts from the list.

5 direct replies — Read more / Contribute
by horace
on Jun 20, 2018 at 13:22

    I have several Perl, use CGI qw(:standard) - scripts that are fine and well-tested, uses function style programming. I would like to upgrade our servers OS from Wheezy to Debian Stretch which does not have in the Perl core. I believe the upgrade to Stretch will leave intact (which the scripts need), but if not, what do I do? Should I consider PSGI/Plack? I'm happy with everything now but eventually something will have to be done. Is there an easy work-around?

remove a comma
5 direct replies — Read more / Contribute
by luupski
on Jun 20, 2018 at 13:22

    I have the following list in a notepad file called CUSTOMER.txt

    --- this is CUSTOMER.txt (input) ---
    0001 20000001 john CA
    0002 30000002 neill WI
    0003 40000003 joe GA
    0004 50000004 will IL
    0005 60000005 mike IN
    0006 70000006 bill AK

    I feed this into the script and get the following output which is placed in the CUSTOMER_NEW.txt file
    All good for except 1 thing.
    I want the last ' , ' (comma)to be removed before the closing bracket.
    Tried several things after googling, but no success

    So i was wandering if anybody has an idea how to add to the code given that will remove the last ' , '

    --- this is CUSTOMER_NEW.txt (output) ---

    --- script used ---
    sub customer {system ("notepad ./CUSTOMER.txt"); $dir="./"; $custom=$dir."CUSTOMER.txt"; $dir="./CUSTOMER_DIR/"; $ofile=$dir."CUSTOMER_NEW.txt"; open (IN,"$custom") || die "Cannot open CUSTOMER.txt!!!\n"; open (OUT,">$ofile") || die "Cannot open CUSTOMER_NEW.txt!!!\n"; print OUT "SELECT CUSTOMERID, ORDERID, CUSTOMERNAME, CUSTOMERLOCATION FROM DB.CUSTOMER_DATA WHERE (CUSTOMERID, ORDERID, CUSTOMERNAME, CUSTOMERLOCATION) IN (\n"; @CUST=<IN>;close IN; foreach $infile (@CUST){ chomp($infile); $i=0; @a=split(/\|/,$infile); @BAGO=$a[$i]; foreach $infile1 (@BAGO){ @b=split(/\s+/,$infile1); print OUT "($b[0],$b[1],$b[2],$b[3])\,\n"; $i++;}} print OUT ")\n"; system ("notepad ./CUSTOMER_DIR/CUSTOMER_NEW.txt"); close OUT; goto START; }
Input Validation and pattern matching in Template Toolkit
5 direct replies — Read more / Contribute
by dipit
on Jun 20, 2018 at 03:57
    [% META title = 'Add xyz' %] [% attack = params.taskid_login %] [% IF'<script>') ||'</script>') || attac'alert') %] [% attack = params.taskid_login | uri | html %] [% ELSE %][% attack = params.taskid_login %] <p> To add a new task ID member to <b>[% attack %]</b>, select one or +more users from the table below. </p> [% WRAPPER filterTitle='Users filter' filterAction='add_task +id_member' %] [% INCLUDE fieldName='filter_login' fieldValue=p +arams.filter_login maxLength=100 %] [% END %] [%# Show global message is one or more members have been added... %] [% IF NumberOfAddedRecords %] [% INCLUDE globalMessage=NumberOfAddedRecords _ +' users have been added.' %] [% END %] [% INCLUDE table=PossibleMembersTable %]

    Hello All. Here i have created a varibale named "attack" and checking some validation over it. params.taskid_login is the input value to "attack" variable here. I want to detect <script> and alert tags here. I think my syntax is wrong so my page containing this template is not loading. Please help?

Module Ideas, Suggestions, and Requests
4 direct replies — Read more / Contribute
by oducs
on Jun 19, 2018 at 08:34

    I am looking for new and interesting ideas for Perl modules!

    The chosen modules will be uploaded to the new oducs CPAN:

    If you have a module which you would like to abandon into my care, let's hear about it.

    Also, I have an interest in simultaneously developing Pure-Perl and XS versions.

    Appreciated, Charlie Root (
New Cool Uses for Perl
Why is it so easy to make Perl apps for Apple Mac?
2 direct replies — Read more / Contribute
by Anonymous Monk
on Jun 17, 2018 at 13:40
    Compile your Perl to a portable binary application for Apple Mac (99k):
    echo 'display alert (do shell script "perl -v")' | osacompile -o perl. +app
    Write apps for Apple Mac in Perl: Pt.1, Pt.2, Pt.3
New Perl Poetry
Sex !
No replies — Read more | Post response
by usemodperl
on Jun 21, 2018 at 13:06
    perl -v|perl -pe's\(?<=r)[l]\x\g;s\(?<=pe)r\\gi;s\p(e)\S$1\gi'
    perl -MO=Deparse -e 'E S I X G S O O D'
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 examining the Monastery: (8)
As of 2018-06-22 07:50 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (122 votes). Check out past polls.