×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • 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!
  • Students Click Here

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

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

wats wrong with this code.

wats wrong with this code.

wats wrong with this code.

(OP)
so here im jst tryin to push all lines with todays date into the array.
but all the data is going thru and getting saved in the array.

$var has this thing
adminode Sun Mar 11 01:53:16 EST 2012 - technoman - sleeping nodename
adminnode Sun Mar 11 01:53:37 EST 2012 - superman - awake nodename
adminnode Sun Jul 19 01:53:37 EST 2012 - superman - awake nodename


so logicaly only the last line should go thru (cos im comparing awk '{print $3}' in date command to awk print $4 in the three lines above).. but all the three lines are goin thru


open(fho,"/home/technoman3/$node.txt");
foreach(<fho>)
{
$var=$_;
#chomp($var);
$i=`date | awk '{print $3}'`;
$p=`echo '$var' | awk '{print $4}'`;
if($p==$i)
{
push(@y,"$var");
}
#push(@y,"$var") if $p == $i;

}
}
$p=0;
foreach(@y)
{
print $_ ;

}

RE: wats wrong with this code.

(OP)
Feherke .. thanks a lot .. that was my mistake .. i rem reading that in a book .. but it had slipped from my mind ..
Feherke u suggested that this not a healthy perl practice .. could u please suggest how to do the same in perl .. can this be done without using command line commands.

RE: wats wrong with this code.

Hi

Quote (technoman007)

can this be done without using command line commands.
Certainly can.

This is how your loop should look :

CODE --> (fragment)

my @time=localtime;

foreach (<fho>) {
  my @part=split;
  push @y,$_ if $part[3]==$time[3];
} 

Regarding the use of command line tools, if you want so, Perl itself is also a command line tool :

CODE --> command-line

perl -nae 'BEGIN{@t=localtime}print if$F[3]==$t[3]' /home/technoman3/$node.txt 

Feherke.
http://feherke.github.com/

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

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! Already a Member? Login

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