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
AIX harddisk sum of storage
3 direct replies — Read more / Contribute
by pjzero@90
on Jul 22, 2018 at 13:21

    Hi perl monks, I'm trying to go through 250 aix lpars and capture. I SSH into each host and attempting to run a for loop within backticks, come to find out this does not work, it fails when it gets to "do" Any ideas or workarouns? Thanks.

    sub aixstorage { my $all_servers = 'path to my AIX list of servers'; my @hosts=`cat $all_servers`; my $filename = '/tmp/aixstorage_report.rtf'; foreach my $one (@hosts){ chomp $one; my $ping = `ping -c 1 -w 1 $one 1>/dev/null 2>&1`; if (defined ($ping)) { my $SSH ="/usr/bin/ssh -o ConnectTimeout=3 -o Stri +ctHostKeyChecking=no"; my $space = $SSH root\@$one for i in lspv | awk '{pri +nt \$1}'; do bootinfo -s \$i; done | awk '{sum+=\$1}END{print (sum\/1 +024)}'}'"`; print "$space\n"; }else { print "\nATTENTION: $one is offline\n" } } }
When did perl change /bin wrappers?
1 direct reply — Read more / Contribute
by Anonymous Monk
on Jul 22, 2018 at 07:48
    /usr/bin/corelist used to be a wrapper for (example) /usr/bin/corelist5.18 but now the wrapper is the numbered program itself. When did that change? Thank you
how to stop command
2 direct replies — Read more / Contribute
by dideod.yang
on Jul 22, 2018 at 05:51
    Hi monks. I wonder how to stop command and keep operating script??. I have many files that I want to search for 5 seconds. Below script,I use alarm but I can not keep my script because of die. If I erase die there is no reason to use alarm.. right? please help me
    my $timeout = 5; eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm $timeout; my @file_list = `ls user/test/`; alarm 0; }; if ($@) { die unless $@ eq "alarm\n"; # propagate unexpected errors # timed out } else { # didn't } # I want to keep go scrip after stop alarm my $file; my @file_list; foreach $file(@file_list){ print "$file\n"; }
option control in script
3 direct replies — Read more / Contribute
by dideod.yang
on Jul 22, 2018 at 00:52
    Hi monks. I wonder that Can script control option by itself?? For example, when I want to use @F(automatic split line by line) , I operate option -ane "perl -ane". also there are many options such as -n -e ... Recently I write some script to open text file and really useful on @F. but I always forgot option -ane :(.. I know I am not man.. So I need your help. When I operate script "perl" then script is operated on "-ane" to use @F. Thank you :)
Counting characters without a space
2 direct replies — Read more / Contribute
by htmanning
on Jul 21, 2018 at 21:52
    I have a form that users are filling in by listing numbers separated by commas, but not adding a space. This results in a very long string which makes the resulting page too wide. My thought it to count the number of characters in each word and target any word more than 15 characters without a space. I would then replace the commas with a comma and space. Anyone have a better way to do it?

    How do I find words that are longer than 15 characters?

Perl/Tk Windows fonts for Linux?
1 direct reply — Read more / Contribute
by tlhackque
on Jul 21, 2018 at 16:08

    I think I have all the pieces, but not how to put them together:

    I have a Perl/Tk application that runs on Windows & Linux (Fedora, if it matters). Originally written on Windows.

    The Linux default fonts are causing some issues - they make a number of widgets larger, and aren't as readable for some. In any case, the goal is a common look and screen size.

    The application users (X display servers) are mostly Windows (VxXsrv), some Linux.

    So, I'd like to have the application request (and the clients use) the Windows fonts for the Tk widgets.

    What I (think I) know:

    • Perl Tk has "Tk Default, Text, Fixed, Monospace, Heading, Caption, Small Caption, Icon and Tooltip fonts.
    • On Windows, the "System" font is Arial, which is used for the widgets without custom fonts
    • The MS TT fonts (including Arial) can be obtained for use using the process at
    • There ought to be some mapping in .Xdefaults to connect the dots

    That's where I get lost.

    • A - having followed the process (built and installed the RPM), xlsfonts doesn't report Arial on Linux clients. It does report a bunch of other -microsoft fonts. xlsfonts | grep ^-microsoft | sort | head starts with -microsoft-comic
    • B - I assume I need to do something to get VcXsrv to recognize the fonts too. I have no clue what.
    • C - Even if it did - what do I put in .Xdefaults (or elsewhere) to have TK adopt the MS Arial (and Courier) fonts?

    I don't want to declare a custom font for every widget - I want the defaults for this application to switch to these as the "system" fonts"

    I don't know why I find all this stuff so confusing - OS internals are simple :-)

    Thanks in advance

unintstall and Install Perl linux
4 direct replies — Read more / Contribute
by yaklichk0719
on Jul 21, 2018 at 02:33
    I would like to uninstall Perl, which has been already per-installed in centOS 6.6 and after that to install Perl 5.10 in configuration I like. Let's say /perl5.10/bin. Can I use command yum remove Perl or there are other commands in Linux?
exec & system
2 direct replies — Read more / Contribute
by dideod.yang
on Jul 20, 2018 at 23:04
    Hi monks. I need your idea to achieve my script.. I understand difference between exec and system. LOCAL is my local command in my linux. My goal is when LOCAL command fail, then script try again command. How can I do that? below script, each case has limit point.. Please help me.
    #LOCAL: local command #case 1 # when LOCAL failed script die exec "LOCAL"; print "success"; #case 2 #when LOCAL failed but print suceess system "LOCAL"; print "success";
Copying a list of files from a directory to a new directory
3 direct replies — Read more / Contribute
by ramjamman
on Jul 20, 2018 at 21:06

    Hi Monks I would welcome any suggestions as to the best way to resolve this problem

    I have on a centos server about 7000 files mostly pdf in one directory. I need to download about 4000 of them for which I have a list in a csv or txt file of their names.

    I am thinking the best way to approach this is to run a script from the command line to copy the files required into a new directory using a script something like that below and then I can download them .

    However I am always open to any suggestions of any other methods that would achieve a solution to this problem Thank You

    #!/usr/bin/perl -w open FILE , '<' , "mylist.txt" || die "$!"; while (<FILE>){ chomp; system("cp $_ newdirectory/"); } close FILE;
XML::Twig - '#CDATA' attribute in hashref disappears after first call to XML::Twig::Elt->new()
2 direct replies — Read more / Contribute
by ateague
on Jul 20, 2018 at 17:56

    Good afternoon!

    I am experiencing a rather unexpected issue creating new elements with XML::Twig's XML::Twig::Elt->new() method where the '#CDATA' key in my attribute hashref gets undefined after passing it to new().


    my $attributes = $sibling_element->atts(); $attributes->{'#CDATA'} = 1; # '#CDATA' attribute is defined here my $elt1 = XML::Twig::Elt->new('present', $attributes, 'This is in CDA +TA'); # '#CDATA' attribute is undefined here my $elt2 = XML::Twig::Elt->new('missing', $attributes, 'This is not in + CDATA');

    Is this supposed to happen? I did not see anything mentioning this in the CPAN docs...

    Thank you for your time.

    Perl info:

    perl -v This is perl 5, version 26, subversion 0 (v5.26.0) built for MSWin32-x +64-multi-thread
    XML::Twig info: 3.52

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.