simple question on perl
Sean
picasso@madflower.com
Fri, 1 Sep 2000 12:40:02 -0400 (EDT)
Split might even actually be a better command for this.
something like:
@array = split (/e\+/, $string);
$exponent = @array[1] ;
That way it doesnt break if the exponent goes into 2x digits plus you
can keep the first part of the number as a separate variable in case you
need to manipulate it later..
(and also you get so use some regexp)
=)
On Fri, 1 Sep 2000, Alan Garrison wrote:
> >From "Learning Perl":
>
>
> 2.6.3 The chop and chomp Functions
>
> A useful built-in function is chop. This function takes a
> single argument within its parentheses - the name of a scalar
> variable - and removes the last character from the string
> value of that variable. For example:
>
> $x = "hello world";
> chop($x); # $x is now "hello worl"
>
> Note that the value of the argument is altered here, hence
> the requirement for a scalar variable, rather than simply a
> scalar value. It would not make sense, for example, to
> write chop('suey') to change it to 'sue', because there is
> no place in which to save the value. Besides, you could have
> just written 'sue' instead.
>
> The value returned is the discarded character (the letter d
> in world above). This means that the following code is
> probably wrong:
>
> $x = chop($x); # WRONG: replaces $x with its last character
> chop($x); # RIGHT: as above, removes the last character
>
>
>
>
> >>> Jay Pike <jay.pike@voyager.net> 09/01/00 03:00PM >>>
> chop() or chomp() removes the last character, but I don't think you GET
> just that last character.
>
> I like regexs, so I was thinking something like:
>
> $variable =~ s/.*(.)$/$1/;
>
> jp
>
> Adam McDougall wrote:
> > chop or chomp?
> >
> > On Fri, 1 Sep 2000, Daniel R . Kilbourne wrote:
> >
> > > Call me a perl idiot, but how do I remove the last character from a string?
> > >
> > > I will need to pull the last character from a line such as:
> > >
> > > 3.3219333333e+02 (I need to get the 2 in this case)
> > >
> > > the string will always be of constant length.
> > >
> > > Anyone?
> > >
> > > ___
> > > Dan
> > > _______________________________________________
> > > linux-user mailing list
> > > linux-user@egr.msu.edu
> > > http://www.egr.msu.edu/mailman/listinfo/linux-user
> > >
> >
> > _______________________________________________
> > linux-user mailing list
> > linux-user@egr.msu.edu
> > http://www.egr.msu.edu/mailman/listinfo/linux-user
>
> --
> __________________________________________________________________________
> / \
> | James J. Pike Jr. Phone: 888.747.4638 |
> | Network Engineer Direct Phone: 517-324-5890 |
> | Voyager.Net Inc. Http: http://www.voyager.net/ |
> | EMail: jay.pike@voyager.net PGPKey: http://my.voyager.net/jaypike/pgpkey.txt |
> \ /
> --------------------------------------------------------------------------
> _______________________________________________
> linux-user mailing list
> linux-user@egr.msu.edu
> http://www.egr.msu.edu/mailman/listinfo/linux-user
>
> _______________________________________________
> linux-user mailing list
> linux-user@egr.msu.edu
> http://www.egr.msu.edu/mailman/listinfo/linux-user
>