Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

weird if statement problem

Status
Not open for further replies.

technoman007

IS-IT--Management
Jul 17, 2012
9
US
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";
}
 
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.
 
hey all .. i found the problem $var had an extra newline character .. so i jst chomped it and it worked :D ..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top