Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I have been a grateful member of this site for several years. I love this site and refer everyone to it!..."

Geography

Where in the world do Tek-Tips members come from?

weird if statement problem

technoman007 (IS/IT--Management)
2 Aug 12 18:34
so this piece of code compares the months. The data in node.txt is of this sort.
alpha1 Thu Aug 15 21:08:51 PDT 2012 - disable
alpha1 Thu Aug 15 21:11:43 PDT 2012 - enable
alpha1 Thu Mar 15 21:58:13 PDT 2012 - disable
alpha1 Sat Mar 24 00:41:12 PDT 2012 - enable

so the output basically should print "abc" twice .. but the if statement never passes. not sure wat im doing wrong
i would appreciate some help .. thanks








open(fho, "/home/Techno/$node.txt");
foreach(<fho>)
{
$var=$_;
$k=`date | awk '{print \$2}'`;
$n=`echo '$var' | awk '{print \$3}'`;
chomp($k);
chomp($n);
print "$k,$n";
if ($k eq $n)
{
print "abc\n";
}
technoman007 (IS/IT--Management)
2 Aug 12 18:49
if i print the values of k and n they have
Aug,Aug
Aug,Aug
Aug,Mar
Aug,Mar

the first two values are same .. so not sure y the if statement dosent pass.
technoman007 (IS/IT--Management)
2 Aug 12 19:10
hey all .. i found the problem $var had an extra newline character .. so i jst chomped it and it worked :D ..

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close