Beefy Boxes and Bandwidth Generously Provided by pair Networks BBQ
good chemistry is complicated,
and a little bit messy -LW

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
Output web page with Padre ... How ?
1 direct reply — Read more / Contribute
by dofski
on Apr 20, 2014 at 11:49

    I am very newbie ... one week

    I use Windows 7

    I installed Apache ... it works with,

    Http:\\localhost test, and is running.

    I installed Dwimperl. I can run simple Perl programs from the command line and Padre.

    I had great pain but eventual success to get local host to output Hello World as web page,

    code is in, it is:

    #!C:\Dwimperl\Perl\bin\perl print "Content-type:text/html\n\n"; print "<html>\n"; print "<h1>Hello World</h1>\n"; print "</html>\n";

    After many trials it worked when I put in,


    Now I open in Padre. when I run, the code is just output in the command line with the script as above. No web page with just Hello World appears.

    I checked view options in Padre and chose HTML ... but on run get error ... no execution mode was defined etc Perhaps I need to install some CPAN modules ?

    Any advice greatly appreciated as I've surfed and read without success.


sort behavior explanation required
3 direct replies — Read more / Contribute
by ghosh123
on Apr 20, 2014 at 11:02

    When I have an array which comprises both strings and integers , then applying the sort function in below mentioned ways , gives different output. Could anyone please explain me on what basis the sorting is happening in the following two cases :

    @arr = ("jack", 80, "martin", 3, "allan", 'george'); @sort = sort { $a cmp $b } @arr; print "@sort \n";

    output :
    3 80 allan george jack martin

    If the sort function is changed to

    @sort = sort { $a <=> $b } @arr ;

    then the output changes to
    jack martin allan george 3 80

Virtual COM port write
1 direct reply — Read more / Contribute
by jismake
on Apr 20, 2014 at 05:55
    I am not able to write or read to/from virtual serial port. The virtual serial ports are created by a software app. the virtual ports are paired-ie one port can spy on other. if i use a hyperterminal, it works with one write to COM port seen on the other. use Win32::SerialPort; use strict; use warnings; $| = 1; #enable autoflush my $PortName = "COM1"; my $sendData = "12345678"; ### SERIAL PORT SETUP ### my $PortObj = new Win32::SerialPort($PortName) or die "Can't open $PortName: $^E\n"; $PortObj->baudrate(57600); $PortObj->parity("none"); $PortObj->databits(8); $PortObj->stopbits(1); $PortObj->write_settings(); #very important! $PortObj->write($sendData); $PortObj->close() || warn "\nClose failed\n"; what could be wrong? I have windows 7, laptop with no real COM ports. i use a virtual serial port kit software to create virtual ports. any help appreciated. jis
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 is available at /opt/sophos-av/lib/ 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/, but that doesn't do the trick.

    Thanks tons!

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 drinking their drinks and smoking their pipes about the Monastery: (9)
    As of 2014-04-20 16:18 GMT
    Find Nodes?
      Voting Booth?

      April first is:

      Results (485 votes), past polls