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

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
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.

How to get line ranges of subroutines from Perl source code
3 direct replies — Read more / Contribute
by rockyb
on Apr 16, 2014 at 01:42

    I'd like to get the start and end ranges of subroutines in a file much the same way that Perl does for the %DB:sub hash when debugging is turned on.

    I can approximate this using B:Utils::all_starts by looking for minimum and maximum COP lines, but that really isn't the same thing since the first executable line might not be on the same line as the sub declaration. For example:

      sub five {
      sub six { 6; }

    Note that the start and end lines of five() are one less and one greater than the single returned expression, 5; For six() though everything is on the same line.

Multiline string and one line comments
3 direct replies — Read more / Contribute
by AskandLearn
on Apr 16, 2014 at 01:17
    Hi everyone

    Another Perl regex question to match comments and strings

    Requirement/regex spec/what should be matched and what should not

    double or single quotes strings are not strings if inside comments

    # inside strings are not comments

    Here is an example, strings and comments needs to be captured and HTML style tags will added to highlight them later

    # this is a comment, should be matched. # "I am not a string" . 'because I am inside a comment' my $string = " #I am not a comment, because I am quoted"; my $another_string = "I am a multiline string with # on each line #, have fun!";

    I tried few things, could not work out a solution to cover all the situations.

better way to escape escapes
5 direct replies — Read more / Contribute
by RonW
on Apr 15, 2014 at 19:48
    I am processing an input format that can use either @ or \ to introduce inline directives. when a literal @ or \ is in the input, either character can be used to escape either character. IE: @@ or \@ or \\ or @\

    Currently, I replace the escape sequences with place holders, then extract directives, then replace the placeholders with the intended literal occurrences of @ and \ in the string.

    s/(?<![\\\@])[\\\@]\@/\x11/g; s/(?<![\\\@])[\\\@]\\/\x12/g; while (/[\\\@]([_A-Za-z]+)/) { print "Extracted code '$1'\n"; s/[\\\@]$1//; } s/\x11/\@/g; s/\x12/\\/g;

    I'm sure there's a better way, but my search-foo is lacking. And so is my regex-foo. (And there's likely an input file that will break this.)

    (and no, it's not LaTeX, despite the similarities)

Perl Directory file extension stats.
3 direct replies — Read more / Contribute
by sidsinha
on Apr 15, 2014 at 17:32

    I had a question regarding Perl directory statistics. Are there any perl packages that I can use to list the number of unique file extentions in a given directory?

    For ex, it should parse through an input directory (including subdir) and return the number of unique file types (for ex, 200 .bmp , 50 jpg ,20 txt) etc.

    Please guide me . thanks.
Lingua: Transform "wasn't" into "was not"
1 direct reply — Read more / Contribute
by Anonymous Monk
on Apr 15, 2014 at 14:09


    As the title suggests, I'm looking for a module which converts various English shortcuts like we're into we are, I'm into I am, etc...

    I couldn't find any module in CPAN which does this. Maybe I haven't looked for the right name.
    So my question is: did anyone worked with something similar before? What module would you recommend for doing this?


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 chilling in the Monastery: (10)
    As of 2014-04-17 07:41 GMT
    Find Nodes?
      Voting Booth?

      April first is:

      Results (441 votes), past polls