Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Subject
- Posted on
- regexp question
- 11-16-2004
posted on
November 16, 2004, 10:09 pm
November 16, 2004, 10:09 pm
I'm have the following problem: I have pair of numbers like 111.1234 and
111.1235. But I want to display that than as 111.1234|5 (to save space on
the screen).
Other examples:
111.98 and 114.0 -> 111.98|4.0
1.2345 and 1.2945 -> 1.2345|945
I have sort of a solution but it's quiet ugly, maybe someone has an idea for
an elegant solution.
Thanks,
Sam
Re: regexp question
> I'm have the following problem: I have pair of numbers like 111.1234 and
> 111.1235. But I want to display that than as 111.1234|5 (to save space
> on the screen).
> Other examples:
>
> 111.98 and 114.0 -> 111.98|4.0
> 1.2345 and 1.2945 -> 1.2345|945
If you're only dealing with two numbers at a time, you should store the
difference between the numbers instead; I refuse to believe that your
screen is _that_ small. :-)
--
"Leadership is doing what is right when no one is watching." (George
Van Valkenburg)
Re: regexp question
"Tore Aursand" wrote
> On Tue, 16 Nov 2004 16:09:54 +0000, Sam wrote:
> > I'm have the following problem: I have pair of numbers like 111.1234 and
> > 111.1235. But I want to display that than as 111.1234|5 (to save space
> > on the screen).
> > Other examples:
> >
> > 111.98 and 114.0 -> 111.98|4.0
> > 1.2345 and 1.2945 -> 1.2345|945
>
> If you're only dealing with two numbers at a time, you should store the
> difference between the numbers instead
but with the difference he has still to deal with other problems:
e.g 111.98 and 114.0
would be 111.98|2.02 and not 111.98|4.0
But I agree that you can not easily solve that with a regular expression.
Patty
Re: regexp question
On Tue, 16 Nov 2004 18:56:05 +0000, Patty Reynolds wrote:
>>> I'm have the following problem: I have pair of numbers like 111.1234
>>> and 111.1235. But I want to display that than as 111.1234|5 (to save
>>> space on the screen).
>>> Other examples:
>>>
>>> 111.98 and 114.0 -> 111.98|4.0
>>> 1.2345 and 1.2945 -> 1.2345|945
>> If you're only dealing with two numbers at a time, you should store the
>> difference between the numbers instead
> but with the difference he has still to deal with other problems: e.g
> 111.98 and 114.0
> would be 111.98|2.02 and not 111.98|4.0
I know that - I just wanted to give him another solution to his "space
problem".
As long as one knows the difference between two numbers, and knowing one
of the numbers, you can always calculate the other number. The same can
be done with more than two numbers, ie.:
111.98|2.02|-3.2 ... etc ...
First, calculate the sum of the two first numbers, then proceed one to the
next "sequence" and so on. No need for a regular expression, and it is
easier to maintain (especially if you some day _need_ to handle more than
two numbers).
--
"It's not so much what you have to learn if you accept weird theories,
it's what you have to unlearn." (Isaac Asimov)
>>> I'm have the following problem: I have pair of numbers like 111.1234
>>> and 111.1235. But I want to display that than as 111.1234|5 (to save
>>> space on the screen).
>>> Other examples:
>>>
>>> 111.98 and 114.0 -> 111.98|4.0
>>> 1.2345 and 1.2945 -> 1.2345|945
>> If you're only dealing with two numbers at a time, you should store the
>> difference between the numbers instead
> but with the difference he has still to deal with other problems: e.g
> 111.98 and 114.0
> would be 111.98|2.02 and not 111.98|4.0
I know that - I just wanted to give him another solution to his "space
problem".
As long as one knows the difference between two numbers, and knowing one
of the numbers, you can always calculate the other number. The same can
be done with more than two numbers, ie.:
111.98|2.02|-3.2 ... etc ...
First, calculate the sum of the two first numbers, then proceed one to the
next "sequence" and so on. No need for a regular expression, and it is
easier to maintain (especially if you some day _need_ to handle more than
two numbers).
--
"It's not so much what you have to learn if you accept weird theories,
it's what you have to unlearn." (Isaac Asimov)
Re: regexp question
> >>> I'm have the following problem: I have pair of numbers like 111.1234
> >>> and 111.1235. But I want to display that than as 111.1234|5 (to save
> >>> space on the screen).
> >>> Other examples:
> >>>
> >>> 111.98 and 114.0 -> 111.98|4.0
> >>> 1.2345 and 1.2945 -> 1.2345|945
>
> >> If you're only dealing with two numbers at a time, you should store the
> >> difference between the numbers instead
>
> > but with the difference he has still to deal with other problems: e.g
> > 111.98 and 114.0
> > would be 111.98|2.02 and not 111.98|4.0
>
> I know that - I just wanted to give him another solution to his "space
> problem".
>
> As long as one knows the difference between two numbers, and knowing one
> of the numbers, you can always calculate the other number. The same can
> be done with more than two numbers, ie.:
>
> 111.98|2.02|-3.2 ... etc ...
>
> First, calculate the sum of the two first numbers, then proceed one to the
> next "sequence" and so on. No need for a regular expression, and it is
> easier to maintain (especially if you some day _need_ to handle more than
> two numbers).
sorry for not being clear enough - I want to save these values in a column
(therefor the space limitations) and I would like to have it a format like
xx.xxx|yy so that you can see the values and not only the difference
Re: regexp question
> Hello,
>
> I'm have the following problem: I have pair of numbers like 111.1234 and
> 111.1235. But I want to display that than as 111.1234|5 (to save space on
> the screen).
> Other examples:
>
> 111.98 and 114.0 -> 111.98|4.0
> 1.2345 and 1.2945 -> 1.2345|945
how can this work ?
given 1.2345|945 , how do you differentiate between the pairs:
1.2345 and 1.234945 -> 1.2345|945
1.2345 and 1.23945 -> 1.2345|945
1.2345 and 1.2945 -> 1.2345|945
1.2345 and 1.945 -> 1.2345|945
1.2345 and 1945 -> 1.2345|945
1.2345 and 945 -> 1.2345|945
?
gnari
>
> I'm have the following problem: I have pair of numbers like 111.1234 and
> 111.1235. But I want to display that than as 111.1234|5 (to save space on
> the screen).
> Other examples:
>
> 111.98 and 114.0 -> 111.98|4.0
> 1.2345 and 1.2945 -> 1.2345|945
how can this work ?
given 1.2345|945 , how do you differentiate between the pairs:
1.2345 and 1.234945 -> 1.2345|945
1.2345 and 1.23945 -> 1.2345|945
1.2345 and 1.2945 -> 1.2345|945
1.2345 and 1.945 -> 1.2345|945
1.2345 and 1945 -> 1.2345|945
1.2345 and 945 -> 1.2345|945
?
gnari
Re: regexp question
> Hello,
>
> I'm have the following problem: I have pair of numbers like 111.1234 and
> 111.1235. But I want to display that than as 111.1234|5 (to save space on
> the screen).
> Other examples:
>
> 111.98 and 114.0 -> 111.98|4.0
> 1.2345 and 1.2945 -> 1.2345|945
>
I came up with a solution that works for the examples you posted plus
a few that I could think of.
$second = join("\t", $first, $second);
$second =~ s/^([\d.]+)[\d.]*?\t([\d.]*?)$/$2/;
print "$first|$second\n";
-jaa
>
> I'm have the following problem: I have pair of numbers like 111.1234 and
> 111.1235. But I want to display that than as 111.1234|5 (to save space on
> the screen).
> Other examples:
>
> 111.98 and 114.0 -> 111.98|4.0
> 1.2345 and 1.2945 -> 1.2345|945
>
I came up with a solution that works for the examples you posted plus
a few that I could think of.
$second = join("\t", $first, $second);
$second =~ s/^([\d.]+)[\d.]*?\t([\d.]*?)$/$2/;
print "$first|$second\n";
-jaa
Site Timeline
- » FAQ 1.3 Which version of Perl should I use?
- — Next thread in » PERL Discussions
- » NCBI ASN1 File in Perl
- — Previous thread in » PERL Discussions
- » s suffix question
- — Newest thread in » PERL Discussions
- » SSD partition alignment revisited
- — The site's Newest Thread. Posted in » Computer Hardware