Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I have a small Perl script that I need to have the STDIN be numeric, but I need to refer to it as a string also. My script runs, but I get error messages about the strings not being numeric.
#!/bin/perl -w use strict; my $days = 0; while ("$days" ne "q") { print "Please enter a single positive integer that represents a n +umber of days" . , " that you wish to convert into seconds. ,(enter q + to quit): "; $days=<STDIN>; chomp $days; if ($days > 0) { my $seconds = $days * 86400; my $plural = ($days ==1) ? '': 's'; print "\n[$days] day$plural = [$seconds] seconds.\n\n"; } elsif ($days < 0) { print "!!! Invalid input. Value must be a positive integer." +; } elsif ("$days" eq "") { print "!!! You must enter a positive integer.\n\n"; } } print "Goodbye\!\n\n";

Janitored by Arunbear - added code tags

In reply to String/Numeric Manipulation by Ms. T.

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2022-01-19 17:44 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (55 votes). Check out past polls.