Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Do you know where your variables are?

Seekers of Perl Wisdom

( #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
$SIG{ALRM} to just log something?
1 direct reply — Read more / Contribute
by philkime
on Apr 16, 2014 at 15:54
    I am trying to use alarm() to log/send email/open ticket after a process has been running for a certain amount of time:
    local $SIG{ALRM} = sub { write_log('TIMEOUT ALERT'); }; alarm 20; my ($run_ok, undef, $full_buf, undef, undef) = run(command => $cmd); alarm 0;
    This is using IPC::Run to run the command. I am running many commands, some taking more than 20 seconds but the message "TIMEOUT ALERT" never appears in the log and all commands run to completion as normal. I don't want to kill anything (contrary to most alarm() examples I find), I just want to let the command run but send some warning somewhere if it takes X amount of time. Is there something obviously wrong here?
python YAML output, perl Loader, which version?
2 direct replies — Read more / Contribute
by mgwmgw
on Apr 16, 2014 at 12:05

    I am writing tests in perl 5.10.1 of a part of a product written in python 2.6.6.

    The python, which I think is using PyYAML, outputs YAML which is acceptable to pylint, but not acceptable to the YAML Loader in perl. I find multiple different examples of this. I think the perl is using YAML::Old.

    I suspect that the best solution would involve moving to a newer YAML Loader in perl, but I seek advice about which one. The PyYAML port to perl supposedly is not finished yet.


How to get the path coverage (or lines of code executed) after running a perl test file
2 direct replies — Read more / Contribute
by perl_help26
on Apr 16, 2014 at 11:11

    Hello Everyone, I wrote a test file using LWP::Simple. How can I know the path coverage of my test file or the lines of code being executed in my program? Is there an easy way? Preferably not with Devel::Cover since it just won't install using cpan!... (there's a test that's failing aeval_merge.t does anyone know why? Thank you...

Help required in find command.
3 direct replies — Read more / Contribute
by maestromani
on Apr 16, 2014 at 09:36
    Hi There, I got a log file which is as follow.
    Name -> Name of the person,Path -> include \\path1\\path2\file.txt
    #user: machinename\name
    #log forward
    #Date setup: 12/01/2010
    # can be n number of line
    Name -> Name of the person
    writing a perl script which accept file name as input and match file name with the path and if matches I need to print the name in the last. log file will have n number of block like that and file name can match n number of time. how to proceed. Don';t like to use $flag, looking for best option. my piece of code looks like $file_name is command line parameter. while (<DATA_FILE>) { $str = $_ ; if ($str =~ /include/) { if ($str =~ /\b$file_name\b/) { $flag = "TRUE" ; } } if ($flag eq "TRUE") { if ($str =~ /View Name/) { print $str ; ($junk,$view_name) = split(\->\,$str) ; print $view_name ; $flag = "FALSE" ; } } #print "$_\n"; }
First Question, why something works? (-M)
1 direct reply — Read more / Contribute
by i255d
on Apr 16, 2014 at 08:26
    I am new to Perl and working my way through one of the more popular Learning Perl Books. It usually takes me a while, but I can usually figure out why a certain piece of code in the Example sections works, but this time I am just not sure why. Here is the code:
    #!/usr/bin/perl use strict; use warnings; use 5.010; die "No file names supplied!\n" unless @ARGV; my $oldest_name = shift @ARGV; my $oldest_age = -M $oldest_name; foreach (@ARGV) { my $age = -M; ($oldest_name, $oldest_age) = ($_, $age) if $age > $oldest_age; } printf "The oldest file was %s, and it was %.1f days old\n", $oldest_name, $oldest_age;
    How does $age know to apply -M to the file going through the foreach loop?
Duplicate emails using MIME::Lite with smtp
1 direct reply — Read more / Contribute
by sandor.farkas
on Apr 16, 2014 at 05:36


    I have an issue sending emails via MIME::Lite module. I have to set some header parameters (return-path and reply-to) therefore I have to use $msg->send('smtp', $SMTP_HOST);

    If I understand right in this case the message now sent via Net::SMTP. Unfortunately it results that if an email address is included in both to and cc fields the message is delivered twice. I'm googling for a while now, but I can't figure out what is the reason behind. Can anyone please give me a hint on this?

    Thank you in advance!
Comparing results of math operations
7 direct replies — Read more / Contribute
by stangoesagain
on Apr 16, 2014 at 05:12
    Little real life problem
    #!/usr/bin/perl use strict; use warnings; use 5.010; my $x=0.95*806; my $y=1.3*589; say $x <=> $y; $x == $y ? say 'equal' : say $x.' '.$y; say $x cmp $y; $x eq $y ? say 'equal' : say $x.' '.$y; #now with simpler math $x=2*1.25; $y=5*0.5; say $x <=> $y; $x == $y ? say 'equal' : say $x.' '.$y; say $x cmp $y; $x eq $y ? say 'equal' : say $x.' '.$y;
    -1 765.7 765.7 0 equal 0 equal 0 equal
    Why? What's wrong?
DBI::Oracle - fails on apache ( ORA-12154) - but works fine local
2 direct replies — Read more / Contribute
by Yaerox
on Apr 16, 2014 at 04:41

    My script works fine when doing local on terminal. When getting this on my apache I'm getting: DBI connect('_DBNAME_','_DBUSER_',...) failed: ORA-12154: TNS:could not resolve the connect identifier specROR: OCIServerAttach) at /srv/www/cgi-bin/ line 14.

    My script is:

    #!/usr/bin/perl -w use strict; use DBI; # Deklaration der lokalen Variablen my ($dbh); my $db_name = "_DBNAME_"; my $db_user = "_DBUSER_"; my $db_pwd = "_DBUSER_PWD_"; $dbh = DBI->connect("dbi:Oracle:$db_name", $db_user, $db_pwd, {RaiseEr +ror=>0, PrintError=>0 , AutoCommit => 0}); if (!defined $dbh) { print "DB-Connect-Fehler: $!\n"; exit; } my $hStatement = $dbh->prepare("SELECT count(*) FROM tbl"); $hStatement->execute; my @count = $hStatement->fetchrow_array(); print "Content-Type: text/html\n\n"; foreach (@count){ print "$count[0]\n"; } $hStatement->finish; $dbh->disconnect;

    Already researched and tried to get where the problem is, but in case that i can use sqlplus without any problems it seems like the problem has to be with apache ... i did:

     perl -e 'use CGI ":all";print header;print "<pre>\n";map { print "$_ $ENV{$_}\n" } sort keys %ENV;print "</pre>\n";'

    to get my Apache-Environment-Variables and imo everything should be okay. Oracle-Base, Oracle-Home, Tns-Admin, Ld-Library-Path everything is set ...

    I don't have a clue how to go on ...

Pattern Matching
6 direct replies — Read more / Contribute
by sunil@perl
on Apr 16, 2014 at 03:46

    Hi all, I need to extract a part of a string. The strings are as below, /ba/mn/first one /ba/mn/second /ba/mn/third and so on. There are hundreds of such strings. I need to extract the below parts from the strings, first one second third and so on Can you monks please help me out in doing this as i am new to world of pattern matching and i am learning it. Thanks, Sunil.

HTML static output
4 direct replies — Read more / Contribute
by unixdisk
on Apr 16, 2014 at 02:45

    I collect data from 'n' servers and redirect the output to TXT file & email my Manager however now requriment is to attach the output in HTML as it's easy to read rather than TXT file.

    Please let me know how to store the data in html & send it via email. Thanks.

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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 avoiding work at the Monastery: (16)
    As of 2014-04-16 20:35 GMT
    Find Nodes?
      Voting Booth?

      April first is:

      Results (434 votes), past polls