in reply to Using perl interactively with VI

  1. substr $var, 1;

    perldoc -f substr for more info, on Unix

  2. s/\?.*//

    Seearch for: a literal question mark character, followed by any number of any characters; replace all that with: nothing ( i.e., delete it )

Proceessing input files line by line is the best way to do it, unless there are reasons for processing larger chunks. hint: most of the time, when you think you need to process larger chunks, what you really need is to find a different way of thinking about the process.

In the then clause, you chop( $qnum ), removing the last character. Or is this supposed to be the reverse-chop, from part 1? In any case, $qtext continues to end with a newline character.

In the else clause, you chomp( $qspec ). chomp() is like chop(), except it removes only the current $INPUT_RECORD_SEPARATOR, $/, normally "\n". $qspec can't have a newline, since it comes from the middle of a line. But $x ends with a newline.

I would suppose using chomp() right after the while(), to trim newlines from all input.


Update: I forgot the most important part ... You left out "use strict;", and you should localize your variables with my.

--
TTTATCGGTCGTTATATAGATGTTTGCA

Replies are listed 'Best First'.
Re: Re: Using perl interactively with VI
by pbeckingham (Parson) on Mar 11, 2004 at 21:36 UTC
    The regular expression also removes the question mark, which should remain.
    s/\?.*/?/