Click here to get back home

how to remove the letter n from a line of text

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
how to remove the letter n from a line of text pauls 02-27-2008
Get Chitika Premium
Posted by Jürgen Exner on February 28, 2008, 1:27 pm
Please log in for more thread options

>Let me be more clear and correct myself:
>What I was actually trying was this:
>
>$my_variable =~ s/n/e-9/;
>
>where the variable $my_variable has this in it: 3.5n
>
>
>and I was hoping to change it to:
>
>3.5e-9
>
>
>when I read-in the data and do the following (below) on $_
>
>s/n/e-9/;
>
>it works!
>
>But if I do it like this:
>
>$my_variable =~ s/n/e-9/;
>
>The n is removed but not replaced by the e-9

Again, I cannot reproduce your problem based on your verbal description:

        C:\tmp>type t.pl
        use warnings; use strict;
        my $my_variable = '3.5n';
        $my_variable =~ s/n/e-9/;
        print $my_variable;

        C:\tmp>t.pl
        3.5e-9
        
Is there a specific reason why you don't post a minimal self-contained
script that produces your problem as recommended in the posting guidelines?

jue

Posted by Tad J McClellan on February 28, 2008, 7:33 pm
Please log in for more thread options
> Jürgen Exner wrote:

>> Works for me
>>
>>         use strict; use warnings;
>>         $_ = 'banana';
>>         s/n/fred/g;
>>         print;
>>
>>         C:\tmp>t.pl
>>         bafredafreda


> Let me be more clear and correct myself:


You do that by posting a short and complete program that we can run.

Like Jürgen did.


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher0cmdat/"

Posted by Jim Gibson on February 27, 2008, 7:00 pm
Please log in for more thread options

> I want to replace all occurances of the letter n in a line of text.
> The confusion I am having is due to the fact that n denotes a new line
> in reg expressions.
>
> I tried to do this:
>
> s/n/fred/; to replace the letter n with fred. But, it did not happen.
>
> This is an area of PERL for which I have not seemed to get it straight.
> That is, when you want to replace a letter that is used by PERL in reg
> expression operations.

'n' only denotes a newline if it is preceded by a backslash character
in double-quotish mode: "\n".

Examples:

perl -e '$x="alno";$x=~s/n/fred/;print"$x\n";'
alfredo

perl -e '$x="al\no";$x=~s/n/fred/;print"$x\n";'
al
o

perl -e '$x=q(al\no);$x=~s/n/fred/;print"$x\n";'
al\fredo

If this doesn't work for you, please post some code showing what you
get and how it differs from what you expect.

(FYI: you can type Perl as a name, not an acronym)

--
Jim Gibson

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Similar ThreadsPosted
Parsing a text file line-by-line: skipping badly-formed lines? May 14, 2007, 11:10 am
How to Remove Space in text file November 21, 2005, 1:48 pm
remove html to leave text May 3, 2007, 4:51 pm
Remove blank lines from text file September 10, 2005, 11:23 am
Loop through a text file line by line January 12, 2005, 7:32 pm
how to remove parentheses from a line in a file - need help! September 15, 2007, 1:50 pm
how to remove duplicate header line in CGI September 17, 2007, 4:25 pm
remove specific line from al ltext fiels in dir? June 23, 2005, 10:37 am
Getting Text Value , in Single line July 27, 2004, 11:58 am
Tk::Checkbutton - text does not line up ... September 10, 2006, 4:25 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap