On Wednesday 30 Jun 2010 13:52:19 Chaitanya Yanamadala wrote:
> try this..
> 
> now to get the $variable,
> read each line of the file by just opening it..
> in this one only thing u need to do is value of $j....
> 

Let me comment on your code.

1. Please show us all your code, not just part of it.

2. Add "use strict;" and "use warnings;" to the beginning and fix all the 
problems it reports..

> $variable = "name1##Thu Oct 18 14:33:23 2007    ##2007-10-18
> 14:33:23.000000000-0400";
> my @vv = split('-',$variable);
> my @vale = split('##',$variable);

Why are you splitting on strings instead of on regexes? << split(/##/, 
$variable); >>

> print "First=>".$vale[1]."\n";
> print "Second=>".$vale[2]."\n";
> 

Maybe I don't understand you but arrays in Perl start at 0 - not at 1.

> 
> $var =$vale[1];

You have two many variable names starting with "v" and they all very much 
alike. Please give more meaningful names. I wonder how you can follow it.

> my @values = split(' ', $var);
> #print "1 values=>". $values[0]."\n";
> if($values[1] eq "Oct"){
> $j=10;
> }

Why not use a date-parsing module such as the ones in:

* http://perl-begin.org/topics/date-and-time/

> $search = $values[4]."-".$j."-".$values[2]."
> ".$values[3].".000000000-".$vv[3];

This is better done using interpolation. Also add my there (see "use 
strict;").

> print "Related Item =>".$values[4]."-".$j."-".$values[2]."
> ".$values[3].".000000000-".$vv[3]."\n";

Again, use interpolating here instead of excessive ".".

> 
> $found = grep /$search/,@vale;

1. Maybe you want grep /\Q$search\E/ here.

2. grep returns a list. Either you want List::MoreUtils::any or you want 
$found to be an array.

> print "Found value=> ".$found."\n";
> if($found eq '1')
> {
> print "Value is there in line\n";
> }
> else{
> print "Value is not there in line\n";
> }
> 

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
My Aphorisms - http://www.shlomifish.org/humour.html

God considered inflicting XSLT as the tenth plague of Egypt, but then
decided against it because he thought it would be too evil.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to