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 script to run for x hours
3 direct replies — Read more / Contribute
by t-rex
on Sep 27, 2016 at 06:41

    Hello Monks,

    In my script i give user a parameter where he mentions he wants to run this script for x number of hours, how should i implement this? I read online , one way could be using SIGALRM and writing handler for this so that when this is achieved I stop the script,

    please suggest other efficient ways if there exist, thanks

error : can't locate object method "getAttribute" via package XML::DOM::NodeList
2 direct replies — Read more / Contribute
by ankit.tayal560
on Sep 27, 2016 at 04:02
    use strict; use warnings; use Data::Dumper; use XML::DOM; my $parser=new XML::DOM::Parser; my $doc=$parser->parsefile('C:\perl\perl_tests\xmlin.xml') or die$!; my $config=$doc->getElementsByTagName("config"); my $config_attr=$config->getAttribute("logdir"); print("$config_attr");

    XML file :<config logdir="var/log/foo/" debugfile="tmp/foo.debug"> <server name ="sahara" osname ="solaris" osversion="2.6"> <address>10.0.0.101</address> <address>10.0.1.101</address>Text </server> <server name="gobi" osname="irix" osversion="6.5"> <address>10.0.0.102</address>text1 </server> <server name="kalahari" osname="linus" osversion="2.0.34"> <address>10.0.0.103</address> <address>10.0.1.103</address>Text2 </server> </config> when I try to run this script I get an error saying : can't locate object method "getAttribute" via package "XML::DOM::NodeList" at C:\perl\perl_tests\xmlin.pl line 10. what is the problem with my script?

One-liner's quoting and subroutine
3 direct replies — Read more / Contribute
by reisinge
on Sep 27, 2016 at 01:42

    Dear Monks :-), I have two questions related to the following one-liner:

    find /opt/splunk/syslog/ -iname "*log*" -type f -mtime +30 | perl -wne + 'BEGIN { $sum = 0 }; chomp; $sum += (stat)[7]; END { print "$sum\n" +}'

    1) How should I quote it (escape the single quotes) when I want to execute it on a remote machine via SSH? Ex. ssh root@HOST 'ONE-LINER'

    2) Is there is a (smart) way to incorporate the following subroutine into the one-liner?

    sub scaleIt { my $size_in_bytes = shift; return unless defined $size_in_bytes; my ( $size, $n ) = ( $size_in_bytes, 0 ); ++$n and $size /= 1024 until $size < 1024; return sprintf "%.0f%s", $size, (qw[ B KB MB GB TB ])[$n]; }

    You can talk and talk and have great ideas, but if you don't have a way of sharing those ideas then you are just saying it in you own bubble. -- Tom Limoncelli
how to jump to some specific line in my code ?
6 direct replies — Read more / Contribute
by ankit.tayal560
on Sep 27, 2016 at 00:51
    use strict; use warnings; print("Enter the number of flags which needs to be generated..\n"); my $num=<STDIN>;

    this is some part of my code. If the input number is 0 or less than 0 than it should jump to some other part say line number 32 of my code. how can I achieve that? any specific function which I can use?

Win 10 Anniversary killed Perl
1 direct reply — Read more / Contribute
by cxgy
on Sep 26, 2016 at 23:20
    Help! I've been running ActivePerl for years now & have scores of scripts running to manipulate data & update websites. Last night Windows 10 did a major update to Build 1607 (the 'Anniversary Edition'). Perl no longer works! The cmd window opens but nothing happens. When clicking on a .pl file, I get a UAC warning about 'no publisher' and then the same dead cmd window. I tried installing Strawberry. That eliminated the UAC warning, but still won't run. I've had to fire up my Win 7 machine as backup. Has this happened to anyone else?
compare two files on the basis of Two IDs
2 direct replies — Read more / Contribute
by genome
on Sep 26, 2016 at 17:26
    Hi, I want to compare two files on the basis of two different Ids, and want to print something, if the Ids matched.

    I opened the two files and used while loop (i.e. while within while). The if condition of this prog. is working good, but else condition will give lots of lines, because of while within while.. "last;" is also not working here..

    Please help me to solve this

    file 1

    chr17 69112551 chr7 151046672 chr7 151047369
    file 2
    chr1 66953622 66953654 chr1 67200451 67200472 chr1 67200475 67200478 chr1 67058869 67058880 chr1 67058881 67058885 chr1 67058887 67058895

    Perl prog.

    #!/usr/bin/perl -w $pwd = `pwd`; chomp($pwd); $file=$ARGV[0]; $file1=$ARGV[1]; open(IN,$file); while ($line=<IN>){ chomp($line); @ary = split(/\t/,$line); chomp($ary[0]);chomp($ary[1]); open(SK,$file1); while($line1=<SK>) { @any = split(/\t/,$line1); chomp($any[0]); chomp($any[0]);chomp($any[1]);chomp($any[2]); if ($ary[0] eq $any[0] and $ary[1] == $any[1]) or ($ary[0] eq $any[0] +and $ary[1] == $any[2]) { print "$line\tE\n"; } else { print "$line\tM\n"; } } }
why are hex values not numbers?
4 direct replies — Read more / Contribute
by perl-diddler
on Sep 26, 2016 at 16:36
    Why are hex values not interpreted as numbers:
    printf "dec(%d) hex(%x)", "65", "0x41"; Argument "0x41" isn't numeric in printf at -e line 2. dec(65) hex(0) # vs. shell: > printf "dec(%d) hex(0x%08x)\n" "65" "0x41" dec(65) hex(0x00000041)

    I know about hex, that doesn't explain why perl shouldn't be able to DWIM, no?

    p.s. maybe the latest perl should allow "0x41"->$* ? (tongue-in-cheek)

Online Tutorial To Get Started
6 direct replies — Read more / Contribute
by Svetlana
on Sep 26, 2016 at 15:25
    As a followup to my previous thread(http://www.perlmonks.org/?node_id=1172488) I was wondering if someone could recommend a good on line tutorial to get started with Perl. I come from a background of Java/C# and I understand the concept of classes/polymorphism etc.. I know I said that I don't trust websites and prefer books, but, it's going to be some time before I get my hands on Learning Perl.
What is this process
2 direct replies — Read more / Contribute
by yellowta
on Sep 26, 2016 at 14:46
    The environment is AIX 7.1 and perl 5.10. I run a script that emulates a tail -f on a log file and writes some records to another file. When looking at the output of a "ps" statement, I see processes called "perl" pop up and then go away. Usually there are two, one has a parent of 1, and the other has a parent of the original script. Anybody have any information was to what these process are doing and what creates them? Thanks!
ActivePerl (x64) is not working with MS SQL Server CE Database
3 direct replies — Read more / Contribute
by talk2chakra
on Sep 26, 2016 at 11:08

    Before anything, I need to tell my Software Environment as follows.

    Installed Software :-
    SQL Server Compact 3.5 Books Online ENU
    SQL Server Compact SP2 ENU
    SQL Server Compact 3.5 SP2 x64 ENU
    MS Office Enterprise 2007
    MS .NET Framework 4.5.2
    CompactView 1.4.12.0
    ActivePerl Ver 5.24.0.2400 (x64)
    OS : Windows 7 Pro x64

    I installed IIS 7.5.7600.16385 and configured it properly for use with ActivePerl. Apart from that, I changed Physical Path of Site to E:\PUCC. The PUCC Folder has been assigned proper security for IUSR and IIS_IUSRS as FULL CONTROL. I tested IIS for use with PERL and succeeded.

    I've 2 .SDF Files (Password Protected) stored in PUCC\DB Folder. As I know the Password, I can access both the Files through CompactView. However I cannot access it through ActivePerl. Whenever, I run PERL SCRIPT from Command Prompt, following errors popped up. My ultimate goal is to furnish the Tables with specific Rows, Columns in Web Browser through IIS.

    PERL Code:

    01 use strict; 02 use warnings; 03 use DBI; 04 05 my $user=""; 06 my $pass="myPass"; 07 08 my $dbh = DBI->connect("dbi:ADO:Provider=Microsoft.SQLSERVER.CE.OLE +DB.3.5;Data Source=E:\\PUCC\\DB\\D_stud.sdf", $user, $pass); 09 10 11 my $sth = $dbh->prepare("SELECT * FROM INFORMATION_SCHEMA.TABLES WH +ERE TABLE_TYPE = 'TABLE'"); 12 13 $sth->execute(); 14 15 while (my $href = $sth->fetchrow_hashref()) { 16 print $href->{TABLE_NAME} . "\n"; 17 }

    ERROR Details:
    DBI connect('Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=E:\PUCC\DB\D_stud.sdf','',...) failed: Can't Open Connection 'Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=E:\PUCC\DB\D_stud.sdf'
    Package : DBD::ADO::dr
    Filename : C:/Perl64/site/lib/DBD/ADO.pm
    Line : 158
    Last error : -2147217887

    OLE exception from "ADODB.Connection":

    Provider could not set DATASOURCE, USERID, or PASSWORD property.

    Win32::OLE(0.1712) error 0x80040e21
    in METHOD/PROPERTYGET "Open" at test.pl line 8.
    Can't call method "prepare" on an undefined value at test.pl line 11.


    Can someone help me out of the Problem?


Add your question
Title:
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.