[31640] in Perl-Users-Digest
Perl-Users Digest, Issue: 2903 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 6 14:09:26 2010
Date: Tue, 6 Apr 2010 11:09:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 6 Apr 2010 Volume: 11 Number: 2903
Today's topics:
Re: FAQ 1.2 Who supports Perl? Who develops it? Why i <pgp@doc.ic.ac.uk>
Re: help: sessioning, SoapServer, setObject <lskatz@gmail.com>
Posting Guidelines for comp.lang.perl.misc ($Revision: tadmc@seesig.invalid
Re: software requirements again, take 483 <jurgenex@hotmail.com>
Re: STDIN number only <stevem_clipthis_@clubtrout.com>
Re: STDIN number only <jurgenex@hotmail.com>
Re: STDIN number only <tadmc@seesig.invalid>
Re: STDIN number only sln@netherlands.com
Re: STDIN number only <stevem_clipthis_@clubtrout.com>
Re: STDIN number only <pgp@doc.ic.ac.uk>
Re: STDIN number only <stevem_clipthis_@clubtrout.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 06 Apr 2010 11:14:19 +0100
From: Philip Potter <pgp@doc.ic.ac.uk>
Subject: Re: FAQ 1.2 Who supports Perl? Who develops it? Why is it free?
Message-Id: <hpf1hp$gkq$1@speranza.aioe.org>
On 06/04/2010 11:00, PerlFAQ Server wrote:
> This is an excerpt from the latest version perlfaq1.pod, which
> comes with the standard Perl distribution. These postings aim to
> reduce the number of repeated questions as well as allow the community
> to review and update the answers. The latest version of the complete
> perlfaq is at http://faq.perl.org .
>
> --------------------------------------------------------------------
>
> 1.2: Who supports Perl? Who develops it? Why is it free?
>
[snip]
> http://dev.perl.org/perl5/docs/p5p-faq.html , or you can subscribe to
> the mailing list by sending perl5-porters-request@perl.org a
> subscription request (an empty message with no subject is fine).
That should be perl5-porters-subscribe@perl.org. I just send a test
email from a nonsubscribed account to perl5-porters-request@ and got:
--8<--------------------------
Hi! This is the ezmlm program. I'm managing the
perl5-porters@perl.org mailing list.
I'm working for my owner, who can be reached
at perl5-porters-owner@perl.org.
This is a generic help message. The message I received wasn't sent to
any of my command addresses.
[...etc...]
--8<--------------------------
Phil
------------------------------
Date: Tue, 6 Apr 2010 08:12:15 -0700 (PDT)
From: Lee <lskatz@gmail.com>
Subject: Re: help: sessioning, SoapServer, setObject
Message-Id: <a4c8993e-415c-46a1-9c1c-7b35bd8c7176@y17g2000yqd.googlegroups.com>
> Yes, I got your example running with "setClass".
>
> I used this server:http://www.jsp-hotel.dk/test/soappersistence-setClass.php
> (source:http://www.jsp-hotel.dk/test/soappersistence-setClass.txt)
>
> with this client:http://www.jsp-hotel.dk/test/soapclient.php
> (source:http://www.jsp-hotel.dk/test/soapclient.txt)
Jonathan, you have been very helpful. Thank you! This example
works. However, I cannot get it to work in a client Perl Soap::Lite
script (which is my ultimate goal). I will CC comp.lang.perl.misc to
continue this conversation. The first part of this conversation can
be found at comp.lang.php (http://groups.google.com/group/
comp.lang.php/browse_thread/thread/7657d5bf882f287b/
4f89ac2542e7ba7c#4f89ac2542e7ba7c)
Basically, I want to use a PHP Soap Server with a Perl client script.
Above is Jonathan's example PHP server and client that work
together.
Below is the Perl script that works, but it does not keep the session
alive I think. In other words, it is not maintaining a class variable
between soap calls.
use strict;
use warnings;
use Data::Dumper;
use SOAP::Lite;# on_debug => sub{print@_};
my($response,$value);
my $soap = SOAP::Lite
-> uri('http://mgip2.biology.gatech.edu')
-> proxy('http://mgip2.biology.gatech.edu/api/apiServer4.php')
;
$response=$soap->subtractOne;
$response=$soap->subtractOne;
$response=$soap->subtractOne;
print valueToString($response);
# put the response's value into a string
sub valueToString{
my($response)=@_;
my $value=$response->faultstring||$response->result||"";
if(ref($value) eq "HASH"){
# get all keys and values from hash
my $str="";
while(my($k,$v)=each(%$value)){
$str.="$k=>$v, ";
}
$value=$str;
}
elsif(ref($value) eq "ARRAY"){
# join the array
$value=join(" ",@$value);
}
return $value;
}
------------------------------
Date: Tue, 06 Apr 2010 02:14:11 -0500
From: tadmc@seesig.invalid
Subject: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.9 $)
Message-Id: <T7KdnfAlKM3eQifWnZ2dnUVZ_uWdnZ2d@giganews.com>
Outline
Before posting to comp.lang.perl.misc
Must
- Check the Perl Frequently Asked Questions (FAQ)
- Check the other standard Perl docs (*.pod)
Really Really Should
- Lurk for a while before posting
- Search a Usenet archive
If You Like
- Check Other Resources
Posting to comp.lang.perl.misc
Is there a better place to ask your question?
- Question should be about Perl, not about the application area
How to participate (post) in the clpmisc community
- Carefully choose the contents of your Subject header
- Use an effective followup style
- Speak Perl rather than English, when possible
- Ask perl to help you
- Do not re-type Perl code
- Provide enough information
- Do not provide too much information
- Do not post binaries, HTML, or MIME
Social faux pas to avoid
- Asking a Frequently Asked Question
- Asking a question easily answered by a cursory doc search
- Asking for emailed answers
- Beware of saying "doesn't work"
- Sending a "stealth" Cc copy
Be extra cautious when you get upset
- Count to ten before composing a followup when you are upset
- Count to ten after composing and before posting when you are upset
-----------------------------------------------------------------
Posting Guidelines for comp.lang.perl.misc ($Revision: 1.9 $)
This newsgroup, commonly called clpmisc, is a technical newsgroup
intended to be used for discussion of Perl related issues (except job
postings), whether it be comments or questions.
As you would expect, clpmisc discussions are usually very technical in
nature and there are conventions for conduct in technical newsgroups
going somewhat beyond those in non-technical newsgroups.
The article at:
http://www.catb.org/~esr/faqs/smart-questions.html
describes how to get answers from technical people in general.
This article describes things that you should, and should not, do to
increase your chances of getting an answer to your Perl question. It is
available in POD, HTML and plain text formats at:
http://www.rehabitation.com/clpmisc.shtml
For more information about netiquette in general, see the "Netiquette
Guidelines" at:
http://andrew2.andrew.cmu.edu/rfc/rfc1855.html
A note to newsgroup "regulars":
Do not use these guidelines as a "license to flame" or other
meanness. It is possible that a poster is unaware of things
discussed here. Give them the benefit of the doubt, and just
help them learn how to post, rather than assume that they do
know and are being the "bad kind" of Lazy.
A note about technical terms used here:
In this document, we use words like "must" and "should" as
they're used in technical conversation (such as you will
encounter in this newsgroup). When we say that you *must* do
something, we mean that if you don't do that something, then
it's unlikely that you will benefit much from this group.
We're not bossing you around; we're making the point without
lots of words.
Do *NOT* send email to the maintainer of these guidelines. It will be
discarded unread. The guidelines belong to the newsgroup so all
discussion should appear in the newsgroup. I am just the secretary that
writes down the consensus of the group.
Before posting to comp.lang.perl.misc
Must
This section describes things that you *must* do before posting to
clpmisc, in order to maximize your chances of getting meaningful replies
to your inquiry and to avoid getting flamed for being lazy and trying to
have others do your work.
The perl distribution includes documentation that is copied to your hard
drive when you install perl. Also installed is a program for looking
things up in that (and other) documentation named 'perldoc'.
You should either find out where the docs got installed on your system,
or use perldoc to find them for you. Type "perldoc perldoc" to learn how
to use perldoc itself. Type "perldoc perl" to start reading Perl's
standard documentation.
Check the Perl Frequently Asked Questions (FAQ)
Checking the FAQ before posting is required in Big 8 newsgroups in
general, there is nothing clpmisc-specific about this requirement.
You are expected to do this in nearly all newsgroups.
You can use the "-q" switch with perldoc to do a word search of the
questions in the Perl FAQs.
Check the other standard Perl docs (*.pod)
The perl distribution comes with much more documentation than is
available for most other newsgroups, so in clpmisc you should also
see if you can find an answer in the other (non-FAQ) standard docs
before posting.
It is *not* required, or even expected, that you actually *read* all of
Perl's standard docs, only that you spend a few minutes searching them
before posting.
Try doing a word-search in the standard docs for some words/phrases
taken from your problem statement or from your very carefully worded
"Subject:" header.
Really Really Should
This section describes things that you *really should* do before posting
to clpmisc.
Lurk for a while before posting
This is very important and expected in all newsgroups. Lurking means
to monitor a newsgroup for a period to become familiar with local
customs. Each newsgroup has specific customs and rituals. Knowing
these before you participate will help avoid embarrassing social
situations. Consider yourself to be a foreigner at first!
Search a Usenet archive
There are tens of thousands of Perl programmers. It is very likely
that your question has already been asked (and answered). See if you
can find where it has already been answered.
One such searchable archive is:
http://groups.google.com/advanced_search
If You Like
This section describes things that you *can* do before posting to
clpmisc.
Check Other Resources
You may want to check in books or on web sites to see if you can
find the answer to your question.
But you need to consider the source of such information: there are a
lot of very poor Perl books and web sites, and several good ones
too, of course.
Posting to comp.lang.perl.misc
There can be 200 messages in clpmisc in a single day. Nobody is going to
read every article. They must decide somehow which articles they are
going to read, and which they will skip.
Your post is in competition with 199 other posts. You need to "win"
before a person who can help you will even read your question.
These sections describe how you can help keep your article from being
one of the "skipped" ones.
Is there a better place to ask your question?
Question should be about Perl, not about the application area
It can be difficult to separate out where your problem really is,
but you should make a conscious effort to post to the most
applicable newsgroup. That is, after all, where you are the most
likely to find the people who know how to answer your question.
Being able to "partition" a problem is an essential skill for
effectively troubleshooting programming problems. If you don't get
that right, you end up looking for answers in the wrong places.
It should be understood that you may not know that the root of your
problem is not Perl-related (the two most frequent ones are CGI and
Operating System related), so off-topic postings will happen from
time to time. Be gracious when someone helps you find a better place
to ask your question by pointing you to a more applicable newsgroup.
How to participate (post) in the clpmisc community
Carefully choose the contents of your Subject header
You have 40 precious characters of Subject to win out and be one of
the posts that gets read. Don't waste them. Take care while
composing them, they are the key that opens the door to getting an
answer.
Spend them indicating what aspect of Perl others will find if they
should decide to read your article.
Do not spend them indicating "experience level" (guru, newbie...).
Do not spend them pleading (please read, urgent, help!...).
Do not spend them on non-Subjects (Perl question, one-word
Subject...)
For more information on choosing a Subject see "Choosing Good
Subject Lines":
http://www.cpan.org/authors/id/D/DM/DMR/subjects.post
Part of the beauty of newsgroup dynamics, is that you can contribute
to the community with your very first post! If your choice of
Subject leads a fellow Perler to find the thread you are starting,
then even asking a question helps us all.
Use an effective followup style
When composing a followup, quote only enough text to establish the
context for the comments that you will add. Always indicate who
wrote the quoted material. Never quote an entire article. Never
quote a .signature (unless that is what you are commenting on).
Intersperse your comments *following* each section of quoted text to
which they relate. Unappreciated followup styles are referred to as
"top-posting", "Jeopardy" (because the answer comes before the
question), or "TOFU" (Text Over, Fullquote Under).
Reversing the chronology of the dialog makes it much harder to
understand (some folks won't even read it if written in that style).
For more information on quoting style, see:
http://web.presby.edu/~nnqadmin/nnq/nquote.html
Speak Perl rather than English, when possible
Perl is much more precise than natural language. Saying it in Perl
instead will avoid misunderstanding your question or problem.
Do not say: I have variable with "foo\tbar" in it.
Instead say: I have $var = "foo\tbar", or I have $var = 'foo\tbar',
or I have $var = <DATA> (and show the data line).
Ask perl to help you
You can ask perl itself to help you find common programming mistakes
by doing two things: enable warnings (perldoc warnings) and enable
"strict"ures (perldoc strict).
You should not bother the hundreds/thousands of readers of the
newsgroup without first seeing if a machine can help you find your
problem. It is demeaning to be asked to do the work of a machine. It
will annoy the readers of your article.
You can look up any of the messages that perl might issue to find
out what the message means and how to resolve the potential mistake
(perldoc perldiag). If you would like perl to look them up for you,
you can put "use diagnostics;" near the top of your program.
Do not re-type Perl code
Use copy/paste or your editor's "import" function rather than
attempting to type in your code. If you make a typo you will get
followups about your typos instead of about the question you are
trying to get answered.
Provide enough information
If you do the things in this item, you will have an Extremely Good
chance of getting people to try and help you with your problem!
These features are a really big bonus toward your question winning
out over all of the other posts that you are competing with.
First make a short (less than 20-30 lines) and *complete* program
that illustrates the problem you are having. People should be able
to run your program by copy/pasting the code from your article. (You
will find that doing this step very often reveals your problem
directly. Leading to an answer much more quickly and reliably than
posting to Usenet.)
Describe *precisely* the input to your program. Also provide example
input data for your program. If you need to show file input, use the
__DATA__ token (perldata.pod) to provide the file contents inside of
your Perl program.
Show the output (including the verbatim text of any messages) of
your program.
Describe how you want the output to be different from what you are
getting.
If you have no idea at all of how to code up your situation, be sure
to at least describe the 2 things that you *do* know: input and
desired output.
Do not provide too much information
Do not just post your entire program for debugging. Most especially
do not post someone *else's* entire program.
Do not post binaries, HTML, or MIME
clpmisc is a text only newsgroup. If you have images or binaries
that explain your question, put them in a publically accessible
place (like a Web server) and provide a pointer to that location. If
you include code, cut and paste it directly in the message body.
Don't attach anything to the message. Don't post vcards or HTML.
Many people (and even some Usenet servers) will automatically filter
out such messages. Many people will not be able to easily read your
post. Plain text is something everyone can read.
Social faux pas to avoid
The first two below are symptoms of lots of FAQ asking here in clpmisc.
It happens so often that folks will assume that it is happening yet
again. If you have looked but not found, or found but didn't understand
the docs, say so in your article.
Asking a Frequently Asked Question
It should be understood that you may have missed the applicable FAQ
when you checked, which is not a big deal. But if the Frequently
Asked Question is worded similar to your question, folks will assume
that you did not look at all. Don't become indignant at pointers to
the FAQ, particularly if it solves your problem.
Asking a question easily answered by a cursory doc search
If folks think you have not even tried the obvious step of reading
the docs applicable to your problem, they are likely to become
annoyed.
If you are flamed for not checking when you *did* check, then just
shrug it off (and take the answer that you got).
Asking for emailed answers
Emailed answers benefit one person. Posted answers benefit the
entire community. If folks can take the time to answer your
question, then you can take the time to go get the answer in the
same place where you asked the question.
It is OK to ask for a *copy* of the answer to be emailed, but many
will ignore such requests anyway. If you munge your address, you
should never expect (or ask) to get email in response to a Usenet
post.
Ask the question here, get the answer here (maybe).
Beware of saying "doesn't work"
This is a "red flag" phrase. If you find yourself writing that,
pause and see if you can't describe what is not working without
saying "doesn't work". That is, describe how it is not what you
want.
Sending a "stealth" Cc copy
A "stealth Cc" is when you both email and post a reply without
indicating *in the body* that you are doing so.
Be extra cautious when you get upset
Count to ten before composing a followup when you are upset
This is recommended in all Usenet newsgroups. Here in clpmisc, most
flaming sub-threads are not about any feature of Perl at all! They
are most often for what was seen as a breach of netiquette. If you
have lurked for a bit, then you will know what is expected and won't
make such posts in the first place.
But if you get upset, wait a while before writing your followup. I
recommend waiting at least 30 minutes.
Count to ten after composing and before posting when you are upset
After you have written your followup, wait *another* 30 minutes
before committing yourself by posting it. You cannot take it back
once it has been said.
AUTHOR
Tad McClellan and many others on the comp.lang.perl.misc newsgroup.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Mon, 05 Apr 2010 15:44:04 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: software requirements again, take 483
Message-Id: <5mpkr5pie43e0nhh0vr6up3dict6cd8a3o@4ax.com>
"Dr.Ruud" <rvtol+usenet@xs4all.nl> wrote:
>Shmuel (Seymour J.) Metz wrote:
>
>> IMHO, if the business process owner signs off on the specifications then
>> it's his responsibility if they're wrong.
>
>Do they really still exist, these environments where they write up
>specifications and sign them off and such? What a waste!
I most definitely want something in writing, even if it is for my own
purposes only. Maybe you have a memory like an elephant but I can't
remember what was discussed or agreed upon or even what I was thinking
at the time when a month later that part of the project is due for
implementation.
And I cannot imagine how email or the Internet or Usenet would work
without any written specs and protocols.
jue
------------------------------
Date: Mon, 05 Apr 2010 15:29:55 -0700
From: Steve M <stevem_clipthis_@clubtrout.com>
Subject: Re: STDIN number only
Message-Id: <oBtun.5828$kj3.3321@newsfe08.iad>
On 4/5/2010 1:16 PM, Don Pich wrote:
> Thank you, Steve! I am still in elementary school writing perl scripts.
> So this helped my efforts out. It worked great!
Ah... you're welcome. But note the remark about no error trapping at
all.... I posted that as more of a 'concept' than anything else, though
it does/did work.
I would not use that exact code in production as it is not nearly
paranoid enough. :-) And you might want to error out with any bad input
as opposed to stripping off non-numerics, and..... well, you get the drift.
Enjoy,
\s
------------------------------
Date: Mon, 05 Apr 2010 15:39:36 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: STDIN number only
Message-Id: <s4pkr5pukipa594hmicc007k64o4afpbat@4ax.com>
Don Pich <dpich@polartel.com> wrote:
[...]
You should always
use strict;
use warnings;
unless you know exactly why you want to disable them for a specific part
of your code.
> $OCT1 = <STDIN> ;
You should do a chomp() here, otherwise $oct will contain the newline,
too.
> if (($OCT1 < -1) || ($OCT1 > 255))
> {
> print "That number is not between 0 and 255. Please enter a real
>number.\n";
[...]
>What I want to do is that if a user enters anything but a number from 0
>to 254, they will get the print statement above. If it is a number, then
>flow it through. I am having a very tough time trying to have this just
>entered as a number.
I would solve this in two steps:
- first make sure the input is numeric: see "perldoc -q whole":
"How do I determine whether a scalar is a number/whole/integer/float?"
- then check if the number is in the desired range as you are doing
already
And as for why your simple approach doesn't work: the numerical value of
any text is 0 (*) and thus indistinguishable from the number 0.
*: Or more accurate: the numerical value of text is the value of the
leading number in that text. If there is no leading number then it is 0.
jue
------------------------------
Date: Mon, 05 Apr 2010 19:41:29 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: STDIN number only
Message-Id: <slrnhrl0i0.jli.tadmc@tadbox.sbcglobal.net>
Jürgen Exner <jurgenex@hotmail.com> wrote:
> Don Pich <dpich@polartel.com> wrote:
>>What I want to do is that if a user enters anything but a number from 0
>>to 254, they will get the print statement above.
> I would solve this in two steps:
I'd do it in two (different) steps:
chomp $num;
if ( $num =~ /\D/ or $num > 255 ) {
print "'$num' is not between 0 and 254\n";
}
:-)
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Mon, 05 Apr 2010 20:44:59 -0700
From: sln@netherlands.com
Subject: Re: STDIN number only
Message-Id: <adblr5h4p35ca1h46q671toi0dg18jv2rg@4ax.com>
On Mon, 05 Apr 2010 12:54:17 -0500, Don Pich <dpich@polartel.com> wrote:
>What I want to do is that if a user enters anything but a number from 0
>to 254, they will get the print statement above. If it is a number, then
>flow it through. I am having a very tough time trying to have this just
>entered as a number. I have tried various regex examples to fix this.
>But none will kick out an error if I enter a string of text.
>
>different regex strings I've tried:
>
>$OCT1 =~ s/.*?(\d+).*/$1/;
>m/^-?\d+$/
>m/^-?\d+[\/|\.]\d+$/
>
You could always do it all at once instead of single quad parts.
use strict;
use warnings;
my (@quad,$ip);
EnterIP:
while (1)
{
@quad = ();
print "\n*> enter IP: ";
$ip = <STDIN>;
chomp $ip;
last EnterIP if ($ip eq lc('Q'));
while ($ip =~ / (?:\b (\d+) (?:\.|$)) | (?=.) /xg)
{
if (defined $1) {
if ($1 >= 0 && $1 <= 255) {
push @quad, int($1);
if (@quad == 4) {
if (length($ip) != pos($ip)) {
print " _ extra text in ip address: '",
substr($ip, pos($ip)), "'\n";
redo EnterIP;
}
last EnterIP;
}
}
else {
print " _ ",int($1), " is out of range\n";
redo EnterIP;
}
}
else {
print " _ '", substr($ip, pos($ip)), "' is invalid\n";
redo EnterIP;
}
}
print " _ not enough quad parts ('q' quits)\n";
}
if (@quad != 4) {
print "user exit ..\n";
exit 1 ;
}
print "\nvalid ip: @quad\n";
exit 0;
----------
-sln
------------------------------
Date: Tue, 06 Apr 2010 09:34:13 -0700
From: Steve M <stevem_clipthis_@clubtrout.com>
Subject: Re: STDIN number only
Message-Id: <XtJun.39860$ao7.38503@newsfe21.iad>
On 4/5/2010 5:41 PM, Tad McClellan wrote:
> Jürgen Exner<jurgenex@hotmail.com> wrote:
>> Don Pich<dpich@polartel.com> wrote:
>
>
>>> What I want to do is that if a user enters anything but a number from 0
>>> to 254, they will get the print statement above.
>
>> I would solve this in two steps:
>
>
> I'd do it in two (different) steps:
>
> chomp $num;
> if ( $num =~ /\D/ or $num> 255 ) {
> print "'$num' is not between 0 and 254\n";
> }
>
> :-)
>
>
Certainly cleaner than the verbose thought I'd posted, and it works well
except for the situation where the user just hits the enter key without
entering a value... perhaps:
chomp $num;
if ( !$num or $num =~ /\D/ or $num > 255 ) {
print "Entry ('$num') is not an acceptable integer (0 to 255)\n";
}
else{ print "'$num' is acceptable\n"; }
\s
--
------------------------------
Date: Tue, 06 Apr 2010 18:02:19 +0100
From: Philip Potter <pgp@doc.ic.ac.uk>
Subject: Re: STDIN number only
Message-Id: <hpfpep$nb0$1@speranza.aioe.org>
On 06/04/2010 17:34, Steve M wrote:
> On 4/5/2010 5:41 PM, Tad McClellan wrote:
>> Jürgen Exner<jurgenex@hotmail.com> wrote:
>>> Don Pich<dpich@polartel.com> wrote:
>>
>>
>>>> What I want to do is that if a user enters anything but a number from 0
>>>> to 254, they will get the print statement above.
>>
>>> I would solve this in two steps:
>>
>>
>> I'd do it in two (different) steps:
>>
>> chomp $num;
>> if ( $num =~ /\D/ or $num> 255 ) {
>> print "'$num' is not between 0 and 254\n";
>> }
>>
>> :-)
>>
>>
>
> Certainly cleaner than the verbose thought I'd posted, and it works well
> except for the situation where the user just hits the enter key without
> entering a value... perhaps:
>
> chomp $num;
> if ( !$num or $num =~ /\D/ or $num > 255 ) {
> print "Entry ('$num') is not an acceptable integer (0 to 255)\n";
> }
> else{ print "'$num' is acceptable\n"; }
You can't enter 0 with this solution, although 00 should work.
How about
if ( $num =~ /^\d+$/ || $num > 255)
or
use Data::Types 'is_whole';
if (!is_whole($num) || $num > 255)
Phil
------------------------------
Date: Tue, 06 Apr 2010 10:39:46 -0700
From: Steve M <stevem_clipthis_@clubtrout.com>
Subject: Re: STDIN number only
Message-Id: <orKun.95783$sx5.79501@newsfe16.iad>
On 4/6/2010 10:02 AM, Philip Potter wrote:
> On 06/04/2010 17:34, Steve M wrote:
>> On 4/5/2010 5:41 PM, Tad McClellan wrote:
>>> Jürgen Exner<jurgenex@hotmail.com> wrote:
>>>> Don Pich<dpich@polartel.com> wrote:
>>>
>>>
>>>>> What I want to do is that if a user enters anything but a number from 0
>>>>> to 254, they will get the print statement above.
>>>
>>>> I would solve this in two steps:
>>>
>>>
>>> I'd do it in two (different) steps:
>>>
>>> chomp $num;
>>> if ( $num =~ /\D/ or $num> 255 ) {
>>> print "'$num' is not between 0 and 254\n";
>>> }
>>>
>>> :-)
>>>
>>>
>>
>> Certainly cleaner than the verbose thought I'd posted, and it works well
>> except for the situation where the user just hits the enter key without
>> entering a value... perhaps:
>>
>> chomp $num;
>> if ( !$num or $num =~ /\D/ or $num> 255 ) {
>> print "Entry ('$num') is not an acceptable integer (0 to 255)\n";
>> }
>> else{ print "'$num' is acceptable\n"; }
>
> You can't enter 0 with this solution, although 00 should work.
>
Oops. :-)
> How about
>
> if ( $num =~ /^\d+$/ || $num > 255)
>
Well, except 'fred' will return true above, ($num < 255 ) maybe....
if( $num =~ /^\d+$/ and $num < 255 ){ print "$num\"; }
^^^
Which seems to work as expected for the various values I've plugged into
it....
> or
>
> use Data::Types 'is_whole';
> if (!is_whole($num) || $num> 255)
>
> Phil
--
"There is no use in your walking five miles to fish when you can depend
on being just as unsuccessful near home." M. Twain
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 2903
***************************************