CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [eminempark] Perl to compare value and to print certain line: Edit Log



eminempark
Novice

May 30, 2013, 12:33 AM


Views: 305
Re: [eminempark] Perl to compare value and to print certain line

I have did some code

Code
#! /usr/bin/perl -w 
#
# compare.pl
#
# Usage: compare.pl burst1.txt
#
#
use strict;

my $pre_x = 0;
my $pre_pri_x = 0;
my $pre_pre_pri_x = 0;

while(<>){
my( $ID, $x) = split;
if ($ID == 1)
{
printf ("%d %.3f %.3f %.3f\n", $ID, $x, $pre_x, $pre_pri_x);
$pre_pre_pri_x = $pre_pri_x;
$pre_pri_x = $pre_x;
$pre_x = $x;
}
elsif ($ID != 1)
{
my $vector = abs($x-2*$pre_x+$pre_pri_x);
if ($vector >= 0.072)
{
if ($pre_pri_x == $pre_x)
{

printf ("%d %.3f %.3f %.3f\n", $ID, $x, $pre_x, $pre_pri_x);
$pre_pri_x = $pre_pre_pri_x;
$pre_x=$x;
}
else
{
printf ("%d %.3f %.3f %.3f\n", $ID, $x, $pre_x, $pre_pri_x);
$pre_pri_x = $pre_pri_x;
$pre_x=$x;
}
}
else
{
$pre_pri_x = $pre_pri_x;
$pre_x = $x;
}
}
}


But the pre_pre_pri_x has give me wrong value.
It give me output

Code
1 0.058 0.000 0.000 
2 0.029 0.058 0.000
5 0.012 0.047 0.000
9 0.083 0.220 0.000



(This post was edited by eminempark on May 30, 2013, 12:39 AM)


Edit Log:
Post edited by eminempark (Novice) on May 30, 2013, 12:39 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives