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
Can a defined value be of zero length?
9 direct replies — Read more / Contribute
by j0se
on Apr 19, 2014 at 05:06

    Dear Monks, why would I need to check for the length of the string? Is it not enough to check for the "definedness"?

    use strict; use warnings; my $dir = '/etc'; while (1) { print "Enter pattern> "; chomp( my $pattern = <STDIN> ); ## I'm talking about this line last unless defined $pattern and length $pattern; my @matched = eval { grep { /$pattern/ } glob "$dir/*"; }; print "Error: $@" if $@; print map { "$_\n" } @matched; }

    And like that ... he's gone. -- Verbal

Beginner's guide for Perl Dancer.
5 direct replies — Read more / Contribute
by pmu
on Apr 19, 2014 at 03:17

    Respected Monks,

    I have been through the Dancer documentation and have searched the net as well. Yet, I do not come across a document that explains Dancer in complete details or something that written for folks who know basic Perl.

    I have some basic Perl Scripting knowledge created a few scripts that capture, filter and e-mail outputs of certain commands. I now want to put the same reports on a webpage, where people can type in the serial number of the array and get the alerts. I want to build a webpage wherein, say for example, a user can put in the name of a server and get the details such as how much storage its accessing and from which storage arrays etc etc.

    I also feel that my lack of knowledge is preventing me from understanding the basic dancer concepts. So how do I go about it?

    Any pointers, suggestions would really help.

    -------------------------------------------------------------- Perspectum cognitio aeterna --------------------------------------------------------------
The 'eval "require $module; 1"' idiom
5 direct replies — Read more / Contribute
by sedusedan
on Apr 19, 2014 at 01:04

    Could someone refresh me on why the ; 1 part is necessary again? In other words, why is this idiom safer/better/more correct than just eval "require $module", especially in the context of using the expression in conditional (e.g.: eval "require $module; 1" or warn "Can't load $module";). I've used this idiom for years, and recently even submitted a patch to Log::Log4perl related to this. But for the love of heaven, I forgot why it's needed in the first place. Let's consider the cases:

    Case 1. Module cannot be not found on the filesystem. require dies with message "Can't locate $module in @INC ...", eval traps it and sets $@ and returns undef. ; 1 part in idiom is not needed (unreached).

    Case 1b. Like case 1, but previous attempt has been made. Ditto.

    Case 2. Module has compile errors. require dies with compile error message, eval traps it and sets $@ and returns undef. ; 1 part in idiom is not needed (unreached).

    Case 2b. Like case 2, but previous attempt has been made. After the first attempt, the entry in %INC is set to undef. At the second attempt, require will die with message "Attempt to reload $module aborted", eval traps it, sets $@, and returns undef. ; 1 part in idiom is not needed (unreached).

    Case 3. Module is loaded successfully and returns a true value (in other words, the normal success case). require will return 1. ; 1 part in idiom is not needed.

    Case 3b. Like Case 3, but previous loading has been made. require will return 1. ; 1 part in idiom is not needed.

    Case 4. Module is loaded successfully but returns a non-true value. require will die with message "$module did not return a true value ...". eval traps it, sets $@, and returns undef. ; 1 part in idiom is not needed (unreached).

    Case 4b. Like case 4, but previous attempt has been made. Ditto.

    There are other cases possible (like a permission error when reading source file, require() being overriden, etc) but the above are the common/majority cases. So what cases does the ; 1 part cover? Does this have something to do with older versions of perl (I'm testing this on 5.18.2).

Will script terminate with window closing
3 direct replies — Read more / Contribute
by htmanning
on Apr 19, 2014 at 00:28
    Monks, I have a database of 100 email addresses. I wrote a script that will present a form to be filled out. When the form is submitted, the contents get emailed to all email addresses through a while routine. My question is if I present a "success" HTML page after the form is submitted, will the script continue to run and complete the sending of all emails if the user closes the browser window or clicks to another page? If I make them wait until the emails are sent it could take a long time so I'd rather just present the success page. Thanks.
accessing subroutines of a module
2 direct replies — Read more / Contribute
by ghosh123
on Apr 18, 2014 at 23:20

    is it possible to access sub routines of a module without using Exporter and creating object ?

Printing without a newline?
3 direct replies — Read more / Contribute
by system("clear");
on Apr 18, 2014 at 20:51

    I am building a simple timer script and I wanted to make a loading bar that corresponded to the time. But unfortunately I can't get it to print without making a new line Thanks... I'm not to good a perl

    #!/usr/bin/perl use Math::Round qw(:all); print "Minutes?\n"; $minutes = <>; chop $minutes; $timeleft = 60*$minutes; system("clear"); while($timeleft >= 0){ $devided = $timeleft/60; $rounded = nlowmult (1, $devided); $seconds = $timeleft-($rounded*60); print "$rounded minutes and to $seconds seconds left\n"; $ran = 30/$timeleft; $count = $ran*$timeleft; while ($count >=0 ){ print "#"; $count--; } sleep (1); system("clear"); $timeleft--; } print "TIME UP!!!!!!\a"; while (1){ print "\a"; print "\a"; }
How to tell cpan where a missing library is?
1 direct reply — Read more / Contribute
by cantelow
on Apr 18, 2014 at 15:31

    On redhat-

    I'm coming up unsuccessful trying to install the SAVI module with the command:

    cpan SAVI

    -probably because of this message when I try:

       Warning (mostly harmless): No library found for -lsavi

    But libsavi.so is available at /opt/sophos-av/lib/libsavi.so. Can someone point me to how to tell cpan where this is? I tried softlinks in /usr/lib and /lib pointing to /opt/sophos-av/lib/libsavi.so, but that doesn't do the trick.

    Thanks tons!
Error running prove "Archive is not a known format type! at /usr/lib/perl5/5.8.8/App/Prove.pm line 538."
2 direct replies — Read more / Contribute
by kamal
on Apr 18, 2014 at 15:19
    When i try to run prove, i get error, here is the command and stdout:
    find test/ -name '*.t' ! -name '*falcon*' | xargs prove -v --norc -r t +est/ -formatter=TAP::Formatter::JUnit | tee test_results.xml Archive is not a known format type! at /usr/lib/perl5/5.8.8/App/Prove. +pm line 538.
[Resolved]Perl inheritance
4 direct replies — Read more / Contribute
by ivanovic3001
on Apr 18, 2014 at 14:27
    Dear anyone,

    I need some serious help. Been trying to figure out inheritance. Was given an assignment to practice inheritance. the code given was.

    use v5.10.0; use warnings; use strict; package Animal; sub new { my $class = $_[0]; my $self = {text => "I am an abstract animal.\n"}; return bless($self, $class); } sub speak { my $self = shift; print $self->{"text"} } package Duck; our @ISA = qw(Animal); # qw(Animal) je ekvavilentno ("Animal") sub new { return bless({text => "I am a a duck.\n"}, shift); }

    So this is the given code and I'm just supposed to make another package named Cow, Horse, etc. However reading online this is different from the stuff I had and the code doesn't print out anything when running and testing it. From what I gathered it's supposed to print "I am a duck" but it does nothing at all.

    I apologize in advance if this is a newbie question but i really can't figure it out tried asking my peers but no one new anything. Thanks in advance for any help.

How to get WWW::Mechaize::Firefox to get text?
1 direct reply — Read more / Contribute
by zerocred
on Apr 18, 2014 at 14:15
    Hi, I'm trying to automate logging in to a complex javascript webpage.

    After inputting username/password the javascript asks an extra question from a list of 6 known questions & answers before actually logging in. The question is in a iframe popup.

    The question appears like this - simple text: <span id="LoginQuestion">What is your pets name?</span>

    I have an xpath&css locators too

    I can't figure out how to lift simple text with WWW-Mechanize-Firefox given the xpath that points at it.

  • How to grab get_text with Mechanize_Firefox?

  • How to select a particular iframe in Mechanize/Firefox (like in Selenium), is it even necessary in Mech FF?

  • Should I look at another tool?

  • I tried $mech->content (with a regex), but it returns some other html not what I see with Firefox/Firebug...I think it comes from wrong iframe.

    I did it before using Selenium which has $sel->get_text(xpath) sort of thing

    Thanks in advance

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.