|
Prev: s///x
Next: Perl - Get Two Decimals
From: Rita on 21 Nov 2005 16:48 Hi I have data $seq = ABCHDJJKOLEUOEJLDXJFXLJLCXJFLDFJDFUPD ASJKDJIUEOFJLDFJOFUEOF DNBKASCDFHIEFYHKHCAKDFHDGTAAAACAC TATCAACAAACATTTTCAT This is one sequence and I Want to remove Enter Space from in it I am using Regular Expraision ($seq =~ s/\n\s /sg); But its reading just first line. I donot know why? Can somebody help me? Thanks
From: Rita on 21 Nov 2005 16:56 > ($seq =~ s/\n\s /sg); Sorry I write wrong by mistake i am using ($seq =~ s/\s//sg); Is It I am doing something wrong?
From: Brian Wakem on 21 Nov 2005 17:00 Rita wrote: > Hi > I have data > $seq = ABCHDJJKOLEUOEJLDXJFXLJLCXJFLDFJDFUPD > ASJKDJIUEOFJLDFJOFUEOF > DNBKASCDFHIEFYHKHCAKDFHDGTAAAACAC > TATCAACAAACATTTTCAT Bareword "ABCHDJ......." not allowed while "strict subs" in use at -e line 1. Not a good start. > This is one sequence and I Want to remove Enter Space from in it > I am using Regular Expraision > ($seq =~ s/\n\s /sg); A) The pattern does not occur anywhere in the string. B) The second half of your substituion is missing. > But its reading just first line. Maybe, but what you've posted is barely even perl, so how can we determine why? Please post *real* code. -- Brian Wakem Email: http://homepage.ntlworld.com/b.wakem/myemail.png
From: Brian Wakem on 21 Nov 2005 17:04 Rita wrote: > >> ($seq =~ s/\n\s /sg); > > Sorry I write wrong by mistake > i am using > ($seq =~ s/\s//sg); > Is It I am doing something wrong? Works fine for me. #!/usr/bin/perl use strict; my $seq = <<SEQ; ABCHDJJKOLEUOEJLDXJFXLJLCXJFLDFJDFUPD ASJKDJIUEOFJLDFJOFUEOF DNBKASCDFHIEFYHKHCAKDFHDGTAAAACAC TATCAACAAACATTTTCAT SEQ $seq =~ s/\s//sg; print "$seq\n"; ____________________________ $ perl scripts/tmp/tmp64.pl ABCHDJJKOLEUOEJLDXJFXLJLCXJFLDFJDFUPDASJKDJIUEOFJLDFJOFUEOFDNBKASCDFHIEFYHKHCAKDFHDGTAAAACACTATCAACAAACATTTTCAT -- Brian Wakem Email: http://homepage.ntlworld.com/b.wakem/myemail.png
From: Big and Blue on 21 Nov 2005 17:11
Rita wrote: > I have data > $seq = ABCHDJJKOLEUOEJLDXJFXLJLCXJFLDFJDFUPD > ASJKDJIUEOFJLDFJOFUEOF > DNBKASCDFHIEFYHKHCAKDFHDGTAAAACAC > TATCAACAAACATTTTCAT I presume that you mean you have a string that contains several newlines in it (it's only a "sequence" in biological terms). > This is one sequence and I Want to remove Enter Space from in it I presume by Enter you mean newline. > I am using Regular Expraision > ($seq =~ s/\n\s /sg); > But its reading just first line. (I think that final / should be //). You haven't actually given us any code to work with, so we'll have to guess. The code isn't "reading" any line, but it may only be changing the first line (as you see it). That regex appears to be forcing \n to be followed by \s then by a space before any substitution is done. If you've only got a \n then nothing will happen. Assuming you want to get rid of all newlines and spaces why not ask for that? $seq =~ s/\s+//g; Alternatively, don't get them in the string in the first place. If you are reading this from a file then chomp() as you go. -- Just because I've written it doesn't mean that either you or I have to believe it. |