PDA

View Full Version : Perl Problem (OT)



Foggy3657
2006-05-10, 05:32
Hi,

This request my be OT and if so please remove.

I am a Slimp3 user and I have been trying to read up on Perl so that I could at some point understand how things work, however I really do not find it easy at all.

I have a problem at work, that my reading of Perl tells me could be resolved by using Perl.

I would be happy to pay some one a small fee if they can help me develope the program. I am based in the UK, so if you reside any where else I would need to work out how to transfer the funds.

If you have any interest - please see attached and private mail me. stubbsjuk-at-yahoo-dot-co-dot-uk

Best wishes


James

cepheid
2006-05-10, 16:50
You've got PM.

SteveEast
2006-05-10, 18:25
I was gonna post the code here but then I saw that cepheid's occupation is listed as "starving graduate student"...

Steve.

cepheid
2006-05-10, 19:39
I was gonna post the code here but then I saw that cepheid's occupation is listed as "starving graduate student"...
Well, you may as well, especially given that the task is rather easy to do. I was sort of planning to post it here myself, once I saw that it was so straightforward.

In any case, I haven't heard back from the OP yet anyway (he's probably asleep since he's in the UK), so given that this is no gargantuan task, post away.

I'm a starving graduate student but obviously not in danger of immediate death, so it's no big deal. =) I appreciate the thought, though!

SteveEast
2006-05-10, 19:50
Here it is, edit to taste. I made a bunch of assumptions about the validity of the input data and let the files be in the current directory...


open (O, "<Old_File.txt") or die;
open (N, ">New_File.txt") or die;

while (<O>) {
($A, $B, $C, $D, $E, $F, $G, $H, $I, $J, $extras) = split /,/, $_, 11;
die "whoops, too many fields" if $extras;
print N "$A,$B,$C,$D,$I,$J";
print N "$A,$B,$E,$F,$I,$J";
print N "$A,$B,$G,$H,$I,$J";
}

edit: hey, what happened to my formatting!

Steve.

snarlydwarf
2006-05-10, 20:05
you forgot a chomp and \n's. :)

SteveEast
2006-05-10, 20:08
Nope, the EOLs arrive and depart in $J. I did actually test the code :)

Steve.

snarlydwarf
2006-05-10, 20:12
ah, nm, the eol's are being picked up in $J.

SteveEast
2006-05-10, 21:53
Thinking about it, you're probably right - hiding the EOLs in $J is a bit obscure if the OP is new to perl, so:


open (O, "<Old_File.txt") or die;
open (N, ">New_File.txt") or die;

while (<O>) {
chomp;
($A, $B, $C, $D, $E, $F, $G, $H, $I, $J, $extras) = split /,/, $_, 11;
die "whoops, too many fields" if $extras;
print N "$A,$B,$C,$D,$I,$J\n";
print N "$A,$B,$E,$F,$I,$J\n";
print N "$A,$B,$G,$H,$I,$J\n";
}


Steve.

eq72521
2006-05-11, 08:25
I think the reason that the OP didn't look back here is that I actually responded to his message via email right away yesterday and provided something similar. Sorry, I should have posted something to that effect here.

Foggy3657
2006-05-11, 11:23
Hi All,

Thank you every one that replied.

The issue has now been resolved and I actualy learnt something in the process.

Best wishes.


James.