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
Posted by pauls on February 27, 2008, 6:19 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.

Thanks!

P.

Posted by Jürgen Exner on February 27, 2008, 6:40 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.

No, it doesn't. "\n" denotes a newline when interpolated in a double quoted
string.

>I tried to do this:
>s/n/fred/; to replace the letter n with fred. But, it did not happen.

Works for me

        use strict; use warnings;
        $_ = 'banana';
        s/n/fred/g;
        print;

        C:\tmp>t.pl
        bafredafreda

jue

Posted by John Bokma on February 27, 2008, 7:19 pm
Please log in for more thread options

> bafredafreda

LOL

--
John

Arachnids near Coyolillo - part 1
http://johnbokma.com/mexit/

Posted by pauls on February 28, 2008, 11:48 am
Please log in for more thread options
Jürgen Exner wrote:
>> 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.
>
> No, it doesn't. "\n" denotes a newline when interpolated in a double quoted
> string.
>
>> I tried to do this:
>> s/n/fred/; to replace the letter n with fred. But, it did not happen.
>
> Works for me
>
>         use strict; use warnings;
>         $_ = 'banana';
>         s/n/fred/g;
>         print;
>
>         C:\tmp>t.pl
>         bafredafreda
>
> jue

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


Thanks

P.



Posted by John Bokma on February 28, 2008, 11:59 am
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/;

I doubt it. Please always post a minimal working Perl program that shows
the issue. A lot of problems are solved that way before they have to be
posted to Usenet in the first place. And if it doesn't, at least it
doesn't waste *everbody's* time (including yours) with a game of "guess
the error".

perl -e "my $mv='3.5n'; $mv =~ s/n/e-9/; print $mv"

3.5e-9



--
John

http://johnbokma.com/mexit/2008/

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
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
Loop through a text file line by line January 12, 2005, 7:32 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