each character in a string

mk76_at_buffalo.edu
Date: 10/29/04


To: beginners@perl.org
Date: Fri, 29 Oct 2004 14:32:39 -0400

Hi All,
I have to write a code wherein I have to access each character in a
string and compare it with '-'

$_ = $seq1[0];
while(/./g) {
 if($1 eq '-') {
    $res1[0] .= '-';
 }
 else {
    $res1[0] = "A";
 }
}

I have initialised $_ with the string in which I have to search. Now I
know that the while loop will read each and every character in the
string. I just need to get that character read to make the comparison. I
know $1 doesnt work because it is not :) Where is the value returned or
how can I assign a variable the value of the condition in the while loop ?

Thanks,
Manas.



Relevant Pages

  • Re: Optimization question
    ... PROCEDURE ForOptimize*(s: ARRAY OF CHAR); ... Calling this with a 75-character string yielded "31" for both loops. ... the sentinel null character. ... With C's "for," you define how you continue the loop, which can be (and ...
    (comp.lang.oberon)
  • Re: searching for the highest index within a directory
    ... (I used to write code in the Ada programming language... ... Because "testFile_34" is a string, ... there is no way to compare them as numbers. ... means we look at the first character in each string. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Can not find older posting: Reading files (fast)
    ... |> "Sucks up an entire file from PATH into a freshly-allocated string, ... (loop for bytes-read = (read-sequence buffer file-stream) ... CHARACTER; or a type specifier for a finite recognizable subtype of INTEGER; or one of the symbols SIGNED-BYTE, UNSIGNED-BYTE, or ... (loop for line = (read-line s nil nil) ...
    (comp.lang.lisp)
  • Re: Cant Figure Out How to Access a List Item
    ... With the alpha character in front you first have to strip it off to get at ... Personally, if the message ID was an alphanumeric string, I'd first try to ... loop through each subject item and send a new email with each subject ... retrieving the object you want with the MessageID, ...
    (comp.lang.basic.visual.misc)
  • Re: Should function argument be changed in function body?
    ... > have to read for the loop is right there at the loop. ... string, the position of the null character happens to be the same with C ... function which modifies its parameters should be short and 'obviously' ...
    (comp.lang.c)