Re: how to remove the letter n from a line of text



pauls <pauls@xxxxxxxxxx> wrote:

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
.



Relevant Pages

  • Re: How to construct new variables in a script from other variables and strings.
    ... absolutely NEVER a _GOOD_ reason why strict() should ... I will conceed that a script which is so trivial that it uses no named ... impeed such a trivial script. ...
    (comp.lang.perl.misc)
  • Re: my command (sorry newbe question)
    ... >> commands before declaring a variable. ... > be a good idea if your script calls another script or module in case there ... You ought to be using strict unless you know a good reason not to. ...
    (comp.lang.perl.misc)
  • Re: my command (sorry newbe question)
    ... Chris Lynch wrote: ... strict), then you will need *something*--my, our, global, whatever... ... It should by "my" unless there's a reason for it to be something ... > be a good idea if your script calls another script or module in case there ...
    (comp.lang.perl.misc)
  • Re: havoing trouble with text substitution
    ... pauls wrote: ... and doing a substitution as follows: ... for some reason PERL ...
    (comp.lang.perl.misc)