On Tuesday 01 April 2003 20:47, you wrote: Alright...well first of all I hope this is just pseudocode. Because a lot of it won't work at all.
Follow along... | All, | | | | What I need is that if I was parsing some data and there is no value | (spaces) it should print ***** so that the next thing I will print after | it would not be printed out immediately. | | | | Ex. of output I want | | | | VISUALID XXXX | | 123456 1023 | | 123457 1354 | | **** 1789 | | This is what happens if no value is found | | VISUALID XXXX | | 1789 | | | | SCRIPT as follows: | | while ($_=<SUMM>) { ##file is open### This statement is redundant. Saying: while ( <SUMM> ) is sufficient. Each line in <SUMM> will automatically be assigned to $_ as long as $/ isn't changed. | | { | | if (/_visualid_(.*)/) { This regular expression won't work with the data you provided. | | { | | if ($length < 2); { ##what im | doing is that if the string length is less than 2 print ***) You're not assigning $length anywhere. Now, $length is interesting because is seems like what you really want is not to count bytes but you want to count how many words there are on a line. This could be accomplished with a regular expression such as: $numwords = (() = $line =~ /(.*?) /g) + 1; You could also use substr(). <example> perl -e ' $line = "this is a line of words that has hmmm\n"; chomp($line); $numwords = (() = $line =~ /(.*?) /g) + 1; # count starts at 0 print "$line == $numwords words\n"; ' this is a line of words that has hmmm == 9 words </example> | | print "***\t"; | | } | | else { | | print "$1\t";} | Again, I am assuming this is pseudocode but for completeness sake $1 isn't assigned. I guess $1 would be the return from the regex you used above. | }} | | | | if (/_xxxx_(.*)/) { Im not exactly sure why you keep using '_'s in your regexes. | | print "\t$1_"; | | } | | | | | | thanks, | | Nix Here is some code that I would have written to do what you are asking for... [EMAIL PROTECTED] ~]$ cat pb;perl pb open(F,"h") or die(); for ( <F> ) { chomp(); $numwords = (() = $_ =~ /(.*?)\s+/g) + 1; if ( /visualid/i ) { print "$_\t XXXX\n"; next; } if ( $numwords < 2 ) { print "****\t\t $_\n"; } else { print $_,"\n"; } } VISUALID XXXX 123456 1023 123457 1354 **** 1789 -- - Jim -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]