Home > Archive > PERL Programming > December 2005 > Help with a simple script to change data format
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Help with a simple script to change data format
|
|
| Tolga Uzuner 2005-12-04, 6:56 pm |
| Hi There,
Havent used Perl in almost two decades. So rusty, its not funny.
Lo and behold, I need to do something very simple: I have a large file
with data in a grid format:
Date ¦ Item 1 ¦ Item 2 ¦ Item 3 <newspace>
The date format is yyyy_mm_dd . As above, column separators are "¦" and
row separators are cariage returns.
I need to convert all the dates into the following format so I can read
the data into a database: "dd/mm/yyyy"
Could someone please give me a hand with this so I can de-rust and get
back into Perl...
Thanks, Tolga
| |
| Matt Garrish 2005-12-04, 6:56 pm |
|
"Tolga Uzuner" <tolga@coubros.com> wrote in message
news:dmvbth$sgd$1@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
> Hi There,
>
> Havent used Perl in almost two decades. So rusty, its not funny.
>
So are you saying you invented Perl? BS detector on high alert...
> Lo and behold, I need to do something very simple: I have a large file
> with data in a grid format:
>
Hmm, the calling card of someone looking for someone else to do their
homework.
> Date ¦ Item 1 ¦ Item 2 ¦ Item 3 <newspace>
>
> The date format is yyyy_mm_dd . As above, column separators are "¦" and
> row separators are cariage returns.
>
> I need to convert all the dates into the following format so I can read
> the data into a database: "dd/mm/yyyy"
>
> Could someone please give me a hand with this so I can de-rust and get
> back into Perl...
>
So if you're really looking to get back into the language, why haven't you
done any of the work yourelf? Usenet is not a forum for asking for scripts.
You're welcome to come back if you have a specific problem...
Matt
| |
| Tolga Uzuner 2005-12-04, 6:56 pm |
| This was entirely uncalled for. I made no claims about having invented
Perl. I asked for help. Noone has a right to decide what usenet is for.
I can post whatever message I like. You could just have ignored the
message. Why bother even writing the reply below ? Do you have nothing
else to do ? Loser.
Matt Garrish wrote:
> "Tolga Uzuner" <tolga@coubros.com> wrote in message
> news:dmvbth$sgd$1@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
>
>
>
> So are you saying you invented Perl? BS detector on high alert...
>
>
>
>
> Hmm, the calling card of someone looking for someone else to do their
> homework.
>
>
>
>
> So if you're really looking to get back into the language, why haven't you
> done any of the work yourelf? Usenet is not a forum for asking for scripts.
> You're welcome to come back if you have a specific problem...
>
> Matt
>
>
| |
| Matt Garrish 2005-12-04, 9:55 pm |
|
"Tolga Uzuner" <tolga@coubros.com> wrote in message
news:dmvqmh$jto$1@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
[TOFU corrected]
>
>
> Matt Garrish wrote:
> This was entirely uncalled for. I made no claims about having invented
> Perl. I asked for help. Noone has a right to decide what usenet is for. I
> can post whatever message I like. You could just have ignored the message.
> Why bother even writing the reply below ? Do you have nothing else to do ?
> Loser.
You made a ridiculous claim about having not used the language since before
it even existed. If you want to write bs please do it somewhere else. If you
want someone to write a script for you, go to a jobs group and pay someone.
If you have a question about perl, ask away.
Matt
| |
| Paul Lalli 2005-12-05, 9:56 pm |
| Tolga Uzuner wrote:
> Havent used Perl in almost two decades.
Hmmm....
perldoc perlhist
Pump- Release Date Notes
king
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Larry 0 Classified. Don't ask.
Larry 1.000 1987-Dec-18
Perl didn't even exist two decades ago. When exactly did you use it?
> So rusty, its not funny.
Well, I agree with the "not funny" part, anyway...
> Lo and behold, I need to do something very simple:
So what's stopping you?
> I have a large file with data in a grid format:
>
> Date =A6 Item 1 =A6 Item 2 =A6 Item 3 <newspace>
>
> The date format is yyyy_mm_dd . As above, column separators are "=A6" and
> row separators are cariage returns.
>
> I need to convert all the dates into the following format so I can read
> the data into a database: "dd/mm/yyyy"
What have you tried so far? How did it not work? What errors did you
receive?
> Could someone please give me a hand with this so I can de-rust and get
> back into Perl...
Sure.
First, visit http://learn.perl.org
Second, download Perl. If you're on a Unix machine, chances are you
already have it available. If you're on Windows, visit
http://www.activestate.com for one of the most popular Windows ports.
Third, start reading some documentation. All installed Perl
distributions come with this documentation available via the "perldoc"
command. Open up a command window, and execute the following commands:
perldoc perlintro
perldoc perl
perldoc perlsyn
perldoc -f open
perldoc -f readline
perldoc -f split
perldoc -f print
That should be enough to get you started. Once you've read that
documentation, make an attempt to solve your problem. Then if it
doesn't work correctly, feel free to post what you have an request
assistance in fixing it.
Good day,
Paul Lalli
| |
| Tolga Uzuner 2005-12-05, 9:56 pm |
|
You sat down, figured out in your tiny brain that Perl came out less
than two decades ago, and decided to deride someone whom you have never
met in your life, who was only asking for help from a community where
helping others is entirely voluntary.
You are a pathetic excuse for a human being. A self-styled cop of usenet
"etiquette". Because there is probably absolutely nothing else to do in
your life. This message exchange is probably the most interesting that
has happened to you all year. Oxygen is wasted on people like you.
You waste useful peoples oxygen. Get lost,
Scouring usenet groups so you can bother people with your self-styled
Matt Garrish wrote:
> "Tolga Uzuner" <tolga@coubros.com> wrote in message
> news:dmvqmh$jto$1@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
>
> [TOFU corrected]
>
>
>
>
> You made a ridiculous claim about having not used the language since before
> it even existed. If you want to write bs please do it somewhere else. If you
> want someone to write a script for you, go to a jobs group and pay someone.
> If you have a question about perl, ask away.
>
> Matt
>
>
| |
| Tolga Uzuner 2005-12-05, 9:56 pm |
| Thank you very much, sincerely appreciate it.
"Two decades" was of course, just a manner of speaking. I last used Perl
in 1993.
Regards,
Tolga
Paul Lalli wrote:
> Tolga Uzuner wrote:
>
>
>
> Hmmm....
> perldoc perlhist
> Pump- Release Date Notes
> king
> ===================================
>
> Larry 0 Classified. Don't ask.
>
> Larry 1.000 1987-Dec-18
>
> Perl didn't even exist two decades ago. When exactly did you use it?
>
>
>
>
> Well, I agree with the "not funny" part, anyway...
>
>
>
>
> So what's stopping you?
>
>
>
>
> What have you tried so far? How did it not work? What errors did you
> receive?
>
>
>
>
> Sure.
>
> First, visit http://learn.perl.org
> Second, download Perl. If you're on a Unix machine, chances are you
> already have it available. If you're on Windows, visit
> http://www.activestate.com for one of the most popular Windows ports.
> Third, start reading some documentation. All installed Perl
> distributions come with this documentation available via the "perldoc"
> command. Open up a command window, and execute the following commands:
>
> perldoc perlintro
> perldoc perl
> perldoc perlsyn
> perldoc -f open
> perldoc -f readline
> perldoc -f split
> perldoc -f print
>
> That should be enough to get you started. Once you've read that
> documentation, make an attempt to solve your problem. Then if it
> doesn't work correctly, feel free to post what you have an request
> assistance in fixing it.
>
> Good day,
> Paul Lalli
>
| |
| Tolga Uzuner 2005-12-05, 9:56 pm |
| As a matter of fact, I did get some help from someone in this group who
was much more constructive.
Presumably, in your tiny world, you are a little deity who knows exactly
when Perl came out, super proud that you do not go around asking people
for help. Good for you.
In the meanwhile though, in the interest of mortals like us who do
occasionally need to ask for help, would you mind crawling into your
little hole and continue not to care about us. Thank you little prince.
Matt Garrish wrote:
> "Tolga Uzuner" <tolga@coubros.com> wrote in message
> news:dn2d0k$ah0$1@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
>
>
> {Once again unable to understand proper posting]
>
>
>
>
> And you're still full of bs. I know when Perl was created because I've been
> using it for years. I know when people make absurd claims like yours - the
> self-styled coder who just happens to have forgotten a little perl and wants
> someone to write their code - that they've never touched the language
> before.
>
> I also don't run around to other groups when I have to write a script
> begging for handouts, and don't care for people who do. If you don't like
> it, it's your problem. As you note but utterly fail to understand, help is
> voluntary. Make no effort and you get not help, which is what you got.
>
>
>
>
> Wow, that hurt me so much I think I'll go take a cry now. Oh the humanity!
>
>
>
>
> Hmm, guess I finally used up your oxygen. If you spent more time writing
> code than begging you might have gotten somewhere a long time ago.
>
> Matt
>
>
| |
| Justin C 2005-12-05, 9:56 pm |
| Organization: I prefer chaos
Reply-To: justin.news@purestblue.com
User-Agent: slrn/0.9.8.1pl1 (Debian)
Message-ID: <1344.4394beda.49de5@stigmata>
Date: Mon, 05 Dec 2005 22:27:38 -0000
X-Complaints-To: abuse@clara.net (please include full headers)
X-Trace: 641d7a04961f61007d1600027102684c53007118
f0850a00356008194394c1c0
NNTP-Posting-Date: Mon, 05 Dec 2005 22:40:00 +0000
Lines: 24
Xref: number1.nntp.dca.giganews.com alt.perl:37433
On 2005-12-05, Tolga Uzuner <tolga@coubros.com> wrote:
>
> You sat down, figured out in your tiny brain that Perl came out less
> than two decades ago, and decided to deride someone whom you have never
> met in your life, who was only asking for help from a community where
> helping others is entirely voluntary.
Oh, get a grip. It's obvious you aren't going to get the answer you want
because you're not putting any effort into it. The only thing you're
expending effort on is antagonising the people most likely to help *if*
you were to show some attempt at helping yourself.
I'm an absolute dunce when it comes to perl and even *I* can see half a
dozen quick and dirty solutions to your problem (all of which will be
pulled apart and, probably, improved to a command line one-liner by the
best of 'em here), but I won't post because nothing good came out of no
effort.
And for your persistence I'm entering you into an exclusive club:
*PLONK*
--
Justin C, by the sea.
| |
| Tolga Uzuner 2005-12-05, 9:56 pm |
| Yes, well this was probably well deserved, and my apologies to anyone I
have antagonised, but it could have been pointed out much more
constructively as per Paul Lalli's message. There was no need to use the
derogatory language in the initial response to my query.
Justin C wrote:
> On 2005-12-05, Tolga Uzuner <tolga@coubros.com> wrote:
>
>
>
> Oh, get a grip. It's obvious you aren't going to get the answer you want
> because you're not putting any effort into it. The only thing you're
> expending effort on is antagonising the people most likely to help *if*
> you were to show some attempt at helping yourself.
>
> I'm an absolute dunce when it comes to perl and even *I* can see half a
> dozen quick and dirty solutions to your problem (all of which will be
> pulled apart and, probably, improved to a command line one-liner by the
> best of 'em here), but I won't post because nothing good came out of no
> effort.
>
> And for your persistence I'm entering you into an exclusive club:
>
> *PLONK*
>
| |
| Sherm Pendley 2005-12-05, 9:56 pm |
| Tolga Uzuner <tolga@coubros.com> writes:
> You sat down, figured out in your tiny brain that Perl came out less
> than two decades ago, and decided to deride someone whom you have
> never met in your life, who was only asking for help from a community
> where helping others is entirely voluntary.
I hate to break it to you, but I doubt anyone is going to volunteer to
write your code for you now, after that little tantrum.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
| |
| Matt Garrish 2005-12-05, 9:56 pm |
|
"Tolga Uzuner" <tolga@coubros.com> wrote in message
news:dn2fcc$go0$1@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
[Which now begs the question: are you an idiot or are you so pretentious you
think people should quote the way your want?]
> Matt Garrish wrote:
> As a matter of fact, I did get some help from someone in this group who
> was much more constructive.
>
And who also said you were full of bs.
Matt
| |
| Tolga Uzuner 2005-12-05, 9:56 pm |
| My apologies again to others in this community that may have been
offended. I clearly went overboard.
In any case, I do not expect anyone to write my code. I asked for a
hand, not a handout. Paul Lalli's response was all it took. And I didn't
mind that he noted my exaggeration of matters when I said two decades,
as clearly it was in jest.
Regards,
Tolga
Sherm Pendley wrote:
> Tolga Uzuner <tolga@coubros.com> writes:
>
>
>
>
> I hate to break it to you, but I doubt anyone is going to volunteer to
> write your code for you now, after that little tantrum.
>
> sherm--
>
| |
| Paul Lalli 2005-12-05, 9:56 pm |
| Tolga Uzuner wrote:
> Thank you very much, sincerely appreciate it.
I sincerely wish I had waited a little while longer before replying at
all. Lest you think my helpful response in any way condones your
behavior in this thread, rest assured I will not be assisting you at
any point in the future.
> "Two decades" was of course, just a manner of speaking. I last used Perl
> in 1993.
There is no "of course" about that statement. It was flat out
dishonest, whether it was a joke in your mind or not.
Paul Lalli
| |
| Purl Gurl 2005-12-05, 9:56 pm |
| Tolga Uzuner wrote:
> Date ¦ Item 1 ¦ Item 2 ¦ Item 3 <newspace>
> The date format is yyyy_mm_dd . As above, column separators are "¦" and
> row separators are cariage returns.
record separator is \n newline based on your "<newspace>" comment.
If not, your record separator is \r\n return \ newline. This might make a
difference in later manipulation of data. You may want to remove \r from
your data, if present.
Purl Gurl
#!perl
while (<DATA> )
{
$date_stamp = substr($_, 0, 10);
($year, $month, $day) = split (/_/, $date_stamp);
substr ($_, 0, 10, "$day/$month/$year");
print $_;
}
__DATA__
2005_12_05 ¦ Item 1 ¦ Item 2 ¦ Item 3
2038_04_01 ¦ Item 1 ¦ Item 2 ¦ Item 3
1970_01_01 ¦ Item 1 ¦ Item 2 ¦ Item 3
RESULTS:
05/12/2005 ª Item 1 ª Item 2 ª Item 3
01/04/2038 ª Item 1 ª Item 2 ª Item 3
01/01/1970 ª Item 1 ª Item 2 ª Item 3
|
|
|
|
|