473,396 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

error in check_time function

10
if pass the values to check_time like this its getting different values:
Expand|Select|Wrap|Line Numbers
  1. use Date::Calc qw(:all);
  2.  
  3. $hh="jjjjjjjjjjjjjjjjj";
  4.  
  5. $mm="bnsdgs";
  6.  
  7. $ss="kdhhgfdfdh";
  8.  
  9. if(check_time($hh,$mm,$ss))
  10. {
  11.  print "valid time:";
  12.  
  13. }
  14. else
  15.  
  16. {
  17.  print "Inva;id time";
  18.  
  19. }
  20.  
here i am getting the valid time as output..


please tell me the reason..

thank u,

Manogna..........
Feb 8 '08 #1
3 1715
numberwhun
3,509 Expert Mod 2GB
if pass the values to check_time like this its getting different values:
Expand|Select|Wrap|Line Numbers
  1. use Date::Calc qw(:all);
  2.  
  3. $hh="jjjjjjjjjjjjjjjjj";
  4.  
  5. $mm="bnsdgs";
  6.  
  7. $ss="kdhhgfdfdh";
  8.  
  9. if(check_time($hh,$mm,$ss))
  10. {
  11.  print "valid time:";
  12.  
  13. }
  14. else
  15.  
  16. {
  17.  print "Inva;id time";
  18.  
  19. }
  20.  
here i am getting the valid time as output..


please tell me the reason..

thank u,

Manogna..........
I am not really sure why. What version of Perl are you using and what OS are you working on?

Here is the code I used (only slight modification for using the two pragmas you should have already been using, plus their issues resolution(s)):

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
  4. use Date::Calc qw(:all);
  5.  
  6. my $hh="jjjjjjjjjjjjjjjjj";
  7.  
  8. my $mm="bnsdgs";
  9.  
  10. my $ss="kdhhgfdfdh";
  11.  
  12. if(check_time($hh,$mm,$ss))
  13. {
  14.  print "valid time:";
  15. }
  16. else
  17. {
  18.  print "Inva;id time";
  19.  
  20. }
  21.  
And here is what was output when I ran the script:

Expand|Select|Wrap|Line Numbers
  1. C:\coding\perl>perl Perl-2.pl
  2. Argument "jjjjjjjjjjjjjjjjj" isn't numeric in subroutine entry at Perl-2.pl line
  3.  12.
  4. Argument "bnsdgs" isn't numeric in subroutine entry at Perl-2.pl line 12.
  5. Argument "kdhhgfdfdh" isn't numeric in subroutine entry at Perl-2.pl line 12.
  6. valid time:
  7.  
To me, this is more like what should have been output. You should have not gotten as far as you say you did.

Regards,

Jeff
Feb 8 '08 #2
Manogna
10
In this if I pass a valid parameters the outcome should be valid time.
Otherwise the outcome should be an Invalid time..

But I am sending Invalid parameters but I am getting the out come as valid time .why?

I am doing this to do some functionalities if hh,mm,ss exactly valid.otherwise the functionalities should not work..

Please help me..as I am new to Perl.

thank U,
Manogna....
Feb 11 '08 #3
nithinpes
410 Expert 256MB
check_time() function works only for numerical values. It returns "true" ("1") if the given three numerical values "$hour", "$min" and "$sec" constitute a valid time.
If you want to catch exception due to non-numeric values, put a separate test statement. Like:

Expand|Select|Wrap|Line Numbers
  1. use Date::Calc qw(:all);
  2.  
  3. $hh="jjjjjjjjjjjjjjjjj";
  4.  
  5. $mm="bnsdgs";
  6.  
  7. $ss="kdhhgfdfdh";
  8.  
  9. foreach($hh,$mm,$ss)
  10. {
  11.   if($_ =~ /\D/)  ##check for non-digit characters
  12.   {
  13.    print "Invalid Time.Enter only numerical values" ;
  14.    exit; 
  15. }
  16. }
  17.  
  18.  
  19. if(check_time($hh,$mm,$ss))
  20. {
  21.  print "valid time:";
  22.  
  23. }
  24. else
  25.  
  26. {
  27.  print "Inva;id time";
  28.  
  29. }
  30.  
  31.  
Feb 11 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Morten Gulbrandsen | last post by:
mysql> USE company; Database changed mysql> mysql> DROP TABLE IF EXISTS EMPLOYEE; -------------- DROP TABLE IF EXISTS EMPLOYEE -------------- Query OK, 0 rows affected (0.00 sec)
12
by: Nohman Ishtiaq | last post by:
MySQL 4.1 Im not very well versed with databases, but as soon as I include 129th row in my table called 'demainpark', I get Table is Full error. I have searched thru the newsgroup, checked the...
9
by: Mairhtin O'Feannag | last post by:
Hello, We have two machines we wish to use DPF. They are both RH ES 2.1, with DB2 8.2. I read the documentation CAREFULLY, and added the following line to my db2nodes.cfg file : 1 egret 0
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
1
by: developer | last post by:
Hi All I have made a .NET project. the files included are borland c++ files that i am migrate to VC++ .NET I am using Microsoft Visual C++ .NET 2003. the compilation goes through properly,...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
4
by: jk2l | last post by:
Error 10 error LNK2019: unresolved external symbol __imp__glBindTexture@8 referenced in function "public: void __thiscall GLTexture::Use(void)" (?Use@GLTexture@@QAEXXZ) GLTexture.obj Error 11 error...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.