in reply to concatenating multiple lines without using . operator

No. That's why Perl has the concatenation operator.

Maybe you can explain to us the situation you have, then we can come up with interesting or applicable solutions to achieve your intended goal.

For example a combination of join and s/\r\n//g could work.

Replies are listed 'Best First'.
Re^2: concatenating multiple lines without using . operator
by anonym (Acolyte) on Jun 13, 2012 at 13:31 UTC

    Thanks.Yep, I tried $_ =~ s/\r\n//g; $seq{$chr} = join ("", $_); already but it does nt concatenate as expected .Below is my code:

    while (<IN>) { chomp; if (/^>chr(\S*)$/) { $chr = $1; #print STDERR "[$chr]\n"; } else { chomp $_; $_ =~ s/\s\r\n\t//g; $seq{$chr} = join ("",$_); #$seq{$chr} = `perl -pe 'chomp; END {print "\n" }' $file`; #$seq{$chr} .= $_; print "$seq{$chr}\n"; } #print OUT "$seq{$chr}\n"; }

    Thanks

      Why didn't you show this code when you asked your initial question?

      Please also explain what this regular expression in your code is supposed to do:

      $_ =~ s/\s\r\n\t//g;

      See perlre and YAPE::Regex::Explain.

      Q:\>perl -MYAPE::Regex::Explain -we "print for YAPE::Regex::Explain->n +ew(shift)->explain;" "\s\r\n\t" The regular expression: (?-imsx:\s\r\n\t) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- \s whitespace (\n, \r, \t, \f, and " ") ---------------------------------------------------------------------- \r '\r' (carriage return) ---------------------------------------------------------------------- \n '\n' (newline) ---------------------------------------------------------------------- \t '\t' (tab) ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
      $seq{$chr} = join ("",$_);

      The join Perl built-in joins a list of strings. In the statement above, the list consists in the single string contained in the  $_ scalar, so the output of  join will be exactly the same as the input.

      It seems that what you are looking for is the "s" modifier for regex. Try:
      $_ =~ s/[\s\r\n\t]//sg;
      Also note - since the \s \r .. etc are alternative characters, and NOT a sequence, I have placed them in [brackets].

      From the docs:

      s     Treat string as single line. That is, change "." to match any character whatsoever, even a newline, which normally it would not match.
      Update: Ignore the suggestion to use the "s" modifier. It is not necessary. See jwkrahn note below.

                   I hope life isn't a big joke, because I don't get it.
                         -SNL

        what you are looking for is the "s" modifier
        ...
        change "." to match any character

        The pattern used does not contain the "." character class so why would the "s" modifier be needed?

        Thanks for the reply.I tried this but it is still printing in the same format. I am not sure where I am going wrong.