1829320 Members
1802 Online
109989 Solutions
New Discussion

Re: Perl assistance

 
SOLVED
Go to solution
Luke Morgan
Frequent Advisor

Perl assistance

Hi,
I have a perl script I was given.
It works like a charm except for one thing I have just discovered. It doesn't appear to use decimals.
The script takes a file with two columns. One being a column number, and one a value.
e.g.
1|2
2|2
3|42

It returns a file with the values in the appropriate columns.
e.g.
2|2|42

The problem is, if a value in the original file is say 0.442, then the output will be 0

Can anyone help me make this script notice decimals please?

for a in `ls $path/data/indexeditems`
do
perl -nle'/(\d+)\D+?(-?\d+)/&&$1 and$x[$1-1]=$2}END{$,="|";print@x' $path/data/indexeditems/$a > $path/data/lines/$a
done



Thanks for your time

Luke
6 REPLIES 6
Ollie R
Respected Contributor
Solution

Re: Perl assistance

Hi Luke,

In Perl-speak, "TAMTOATDI". Here's one:

replace:
/(\d+)\D+?(-?\d+)/
with:
/(\d+)\D+?(-?\S+)/

This presumes that the first entry on each line consists of only digits.

Ollie.
To err is human but to not award points is unforgivable
Luke Morgan
Frequent Advisor

Re: Perl assistance

Excellent!

Thanks Ollie.

Any chance of telling me what "TAMTOATDI" means?
:)

Luke
John Poff
Honored Contributor

Re: Perl assistance

Hi Luke,

I'm not quite sure how Ollie's acronym for TAMTOATDI works out, but I've seen it spelled TMTOWTDI, which is pronounced 'tim-toady' and stands for 'There's More Than One Way To Do It'. It's an expression familiar to Perl users because there are always many possible solutions to a problem using Perl.

JP
Stuart Browne
Honored Contributor

Re: Perl assistance

I'm picking "theres ALWAYS more than ..."
One long-haired git at your service...
Ollie R
Respected Contributor

Re: Perl assistance

Hi,

I'm picking the fact that I made a typo!!! 8O)

Glad the script worked,

Ollie.
To err is human but to not award points is unforgivable
Stuart Browne
Honored Contributor

Re: Perl assistance

Well, I was having trouble trying to figure out what the 2nd A stood for :P
One long-haired git at your service...