Sponsored Content
Full Discussion: Perl Script Integer Test
Top Forums Shell Programming and Scripting Perl Script Integer Test Post 303000219 by LinQ on Thursday 6th of July 2017 01:57:55 PM
Old 07-06-2017
Perl Script Integer Test

Working out a small problem, I have a need of a Perl snippet which might look something like this:
Code:
use integer;

...

if ($changingNumber / 2)
{
    do something;
}

else
{
    do something else;
}

...

What I want to happen is for "if" to resolve as "true" every time a whole number is produced by the quotient of "$changingNumber / 2"; allowing the "do something" block only then to be executed.

But what I get, instead, is the eval of "true" and the consequent "do something" block execution for every value of "$changingNumber" of 2 and greater.

I know this is probably a simple error on my part, but I can't quite elucidate what would do the trick here...

Any ideas?

Thanks!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Integer/Float Script Problem

Hi, I have a script which takes a value from a file and performs calculations on it. Trouble is that this value is a float not an integer and it errors at the decimal point! eg. 94.62 I would like to be able to detect the length of the float (in this above case, 5 characters), and simply do a... (2 Replies)
Discussion started by: danhodges99
2 Replies

2. Programming

C function to test string or integer

Hi everyone , Is there any predefined C function that tests whether an input is string or an integer? Thank's in advance :) (3 Replies)
Discussion started by: qqq
3 Replies

3. UNIX for Advanced & Expert Users

test the string is char or integer

How will test the string contains numeric character or alphabet, is there any script to test ? (10 Replies)
Discussion started by: rajesh08
10 Replies

4. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

5. Shell Programming and Scripting

Perl - automating if statement test

Hello all, I'm trying to automate an if statement in my Perl script. The script opens an input file for reading, checks each line in the file for a particular substring, and if it finds the substring, writes it to an output file. There are approximately 200 different input files. Each has... (3 Replies)
Discussion started by: Galt
3 Replies

6. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

7. Shell Programming and Scripting

PERL - traverse sub directories and get test case results

Hello, I need help in creating a PERL script for parsing test result files to get the results (pass or fail). Each test case execution generates a directory with few files among which we are interested in .result file. Lets say Testing is home directory. If i executed 2 test cases. It will... (4 Replies)
Discussion started by: ravi.videla
4 Replies

8. Shell Programming and Scripting

how to compare string integer with an integer?

hi, how to I do this? i="4.000" if ; then echo "smaller" fi how do I convert the "4.000" to 4? Thanks! (4 Replies)
Discussion started by: h0ujun
4 Replies

9. Shell Programming and Scripting

Perl: backslash in front of integer like \32768

In Perl, what does a backslash preceding an integer do like \32768 ? The $/ section of perlvar writes: local $/ = \32768; # or \"32768", or \$var_containing_32768 How is \32768 different from just 32768 without backslash? I do not understand the backslashes in \"32768" and... (1 Reply)
Discussion started by: LessNux
1 Replies

10. Shell Programming and Scripting

Perl inserting random negative integer

Hi All, i have problem here whenever i run this perl script that is pasted here, it inserts a negative number in place of PO_nbr . What the script does is reads a pipe delimited file and then using some values on the file it will query db to get few other values and then it inserts the... (4 Replies)
Discussion started by: selvankj
4 Replies
IO::Async::Channel(3pm) 				User Contributed Perl Documentation				   IO::Async::Channel(3pm)

NAME
"IO::Async::Channel" - pass values into or out from an IO::Async::Routine DESCRIPTION
A "IO::Async::Channel" object allows Perl values to be passed into or out of an IO::Async::Routine. It is intended to be used primarily with a Routine object rather than independently. For more detail and examples on how to use this object see also the documentation for IO::Async::Routine. A Channel object is shared between the main process of the program and the process running within the Routine. In the main process it will be used in asynchronous mode, and in the Routine process it will be used in synchronous mode. In asynchronous mode all methods return immediately and use "IO::Async"-style callback functions. In synchronous within the Routine process the methods block until they are ready and may be used for flow-control within the routine. Alternatively, a Channel may be shared between two different Routine objects, and not used directly by the controlling program. The channel itself represents a FIFO of Perl reference values. New values may be put into the channel by the "send" method in either mode. Values may be retrieved from it by the "recv" method. Values inserted into the Channel are snapshot by the "send" method. Any changes to referred variables will not be observed by the other end of the Channel after the "send" method returns. Since the channel uses Storable to serialise values to write over the communication filehandle only reference values may be passed. To pass a single scalar value, "send" a SCALAR reference to it, and dereference the result of "recv". CONSTRUCTOR
$channel = IO::Async::Channel->new Returns a new "IO::Async::Channel" object. This object reference itself should be shared by both sides of a "fork()"ed process. After "fork()" the two "setup_*" methods may be used to configure the object for operation on either end. While this object does in fact inherit from IO::Async::Notifier for implementation reasons it is not intended that this object be used as a Notifier. It should not be added to a Loop object directly; event management will be handled by its containing "IO::Async::Routine" object. METHODS
$channel->configure( %params ) Similar to the standard "configure" method on "IO::Async::Notifier", this is used to change details of the Channel's operation. on_recv => CODE May only be set on an async mode channel. If present, will be invoked whenever a new value is received, rather than using the "recv" method. $on_recv->( $channel, $data ) on_eof => CODE May only be set on an async mode channel. If present, will be invoked when the channel gets closed by the peer. $on_eof->( $channel ) $channel->send( $data ) Pushes the data stored in the given Perl reference into the FIFO of the Channel, where it can be received by the other end. When called on a synchronous mode Channel this method may block if a "write()" call on the underlying filehandle blocks. When called on an asynchronous mode channel this method will not block. $channel->send_frozen( $record ) A variant of the "send" method; this method pushes the byte record given. This should be the result of a call to "Storable::freeze()". $data = $channel->recv When called on a synchronous mode Channel this method will block until a Perl reference value is available from the other end and then return it. If the Channel is closed this method will return "undef". Since only references may be passed and all Perl references are true the truth of the result of this method can be used to detect that the channel is still open and has not yet been closed. $channel->recv( %args ) When called on an asynchronous mode Channel this method appends a callback function to the receiver queue to handle the next Perl reference value that becomes available from the other end. Takes the following named arguments: on_recv => CODE Called when a new Perl reference value is available. Will be passed the Channel object and the reference data. $on_recv->( $channel, $data ) on_eof => CODE Called if the Channel was closed before a new value was ready. Will be passed the Channel object. $on_eof->( $channel ) $channel->close Closes the channel. Causes a pending "recv" on the other end to return undef or the queued "on_eof" callbacks to be invoked. AUTHOR
Paul Evans <leonerd@leonerd.org.uk> perl v5.14.2 2012-10-24 IO::Async::Channel(3pm)
All times are GMT -4. The time now is 03:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy