Novice and willing to learn

A

Andries

Hello out there,

Don't spank me.
I'm trying to learn Perl but i'm in a hurry right now and can't find
(yet) how to do this. (You'll notice my novice talents by the
question.)

I have this in large quantities ia a huge text-file:
Geslacht: xxx
Achternaam : xxxx
Voorletters: xxx
Tussenvoegsel(s): xxxx
Adres : xxxxx
Postcode : xxxxx
Woonplaats : xxxx
Telefoonnummer : xxxxx
e-mail (privé) : xxxxxx
Schoollocatie : xxxxxx
Schooladres : xxxxxx
Postcode: xxxxx
Plaats : xxxxx
Telefoonnummer: xxxxx
E-mail school : xxxxxxx


What do i want/need is this:
I want to make a report with only a selection of the data.
Like this f.i

Achternaam : xxxx
Voorletters: xxx
Tussenvoegsel(s): xxxx
Schoollocatie : xxxxxx
Schooladres : xxxxxx

Achternaam : xxxx
Voorletters: xxx
Tussenvoegsel(s): xxxx
Schoollocatie : xxxxxx
Schooladres : xxxxxx

etc.

I want to experiment with this also to learn as quickly as possible so
if anyone is willing to help me please do it the way i can comprehend
what is happening so i can adapt it too.

TIA

Andries Meijer
(e-mail address removed)
 
T

Tad McClellan

Andries said:
Don't spank me.


You'll get spanked if you do something wrong.

Just don't do anything wrong, and you won't have to worry about it.

I'm trying to learn Perl but i'm in a hurry right now and can't find
(yet) how to do this. (You'll notice my novice talents by the ^^^^
question.)


Well yes, you haven't explained what that "this" is, so we
can't help with code that does that "this"...

I have this in large quantities ia a huge text-file:
What do i want/need is this:
I want to make a report with only a selection of the data.


Errr, what criteria is used to select the ones you want?

Only the ones that start with "A" or "V" or "T" or "S"?

Only the 4th, 6th, 7th and 12th?

Achternaam : xxxx
Voorletters: xxx
Tussenvoegsel(s): xxxx
Schoollocatie : xxxxxx
Schooladres : xxxxxx

Achternaam : xxxx
Voorletters: xxx
Tussenvoegsel(s): xxxx
Schoollocatie : xxxxxx
Schooladres : xxxxxx


What is the difference between those two?

They look identical to me...

I want to experiment with this


What "this"?

also to learn as quickly as possible so
if anyone is willing to help me please do it the way i can comprehend
what is happening so i can adapt it too.


Tell us what you want in a way the we can comprehend so we can
adapt it into Perl code.


Have you seen the Posting Guidelines that are posted here frequently?
 
G

gnari

Andries said:
Hello out there,

I have this in large quantities ia a huge text-file:
Geslacht: xxx
Achternaam : xxxx
Voorletters: xxx
Tussenvoegsel(s): xxxx

[snip more fields]
you want a subset of fields in output

I am assuming assuming you are using a
while (<>) {...}
loop.

if the number of output fields is small,
and the list not likely to change,
it may suffice make a print statement for
each one

print of /^Achternaam :/;
print if /^Voorletters:/;
print if /^Tussenvoegsel\(s\):/;
print if /^Schoollocatie :/;
print if /^Schooladres :/;

if the formatting is not regular, and may
contain a irregular number of spaces, you
can do somethiong like:

print if /^Schoollocatie *:/;


if you want to generalise the script, you
could declare the printable field names before
the loop:

my %want= (
'Achternaam' => 1,
'Voorletters' => 1,
'Tussenvoegsel(s)' => 1,
'Schoollocatie' => 1,
'Schooladres' => 1,
);

while (<>) {
my ($name,$value)=split / *: */,$_,2;
print if $want{$_}
}


gnari
 
G

Gunnar Hjalmarsson

Andries said:
I have this in large quantities ia a huge text-file:

What do i want/need is this:
I want to make a report with only a selection of the data. Like
this f.i

Achternaam : xxxx
Voorletters: xxx
Tussenvoegsel(s): xxxx
Schoollocatie : xxxxxx
Schooladres : xxxxxx

You can for instance create a hash whose keys identify the lines you
want to be printed:

my %toBePrinted;
@toBePrinted{ qw/Achternaam Voorletters Tussenvoegsel
Schoollocatie Schooladres/ } = ();

and then, when reading the file line by line, you could do:

my ($key) = /(\w+)/;
print if exists $toBePrinted{$key};
I want to experiment with this also to learn as quickly as possible
Good.

so if anyone is willing to help me please do it the way i can
comprehend what is happening so i can adapt it too.

Nothing is "happening", until you have written the program you need.

Good luck!
 
R

Robin

Andries said:
Hello out there,

Don't spank me.
I'm trying to learn Perl but i'm in a hurry right now and can't find
(yet) how to do this. (You'll notice my novice talents by the
question.)

I have this in large quantities ia a huge text-file:
Geslacht: xxx
Achternaam : xxxx
Voorletters: xxx
Tussenvoegsel(s): xxxx
Adres : xxxxx
Postcode : xxxxx
Woonplaats : xxxx
Telefoonnummer : xxxxx
e-mail (privé) : xxxxxx
Schoollocatie : xxxxxx
Schooladres : xxxxxx
Postcode: xxxxx
Plaats : xxxxx
Telefoonnummer: xxxxx
E-mail school : xxxxxxx


What do i want/need is this:
I want to make a report with only a selection of the data.
Like this f.i

Achternaam : xxxx
Voorletters: xxx
Tussenvoegsel(s): xxxx
Schoollocatie : xxxxxx
Schooladres : xxxxxx

Achternaam : xxxx
Voorletters: xxx
Tussenvoegsel(s): xxxx
Schoollocatie : xxxxxx
Schooladres : xxxxxx

etc.

I want to experiment with this also to learn as quickly as possible so
if anyone is willing to help me please do it the way i can comprehend
what is happening so i can adapt it too.

TIA

Andries Meijer
(e-mail address removed)

do you have code?
 
A

Andries

First of all my apologies! Truly meant.
No, i don't have code. How could I
I just started and i'm not further yet than "Hello world"
I use the sybex book called Perl, CGI and Javascript Complete.

I didn't want to insult any of you.
I always learn a lot from questions i ask and things i really need and
can use. I'm not a very theoretical man. I have trouble reading
learning books on computers. I really learn a lot from the problems i
stumble on and the question for help. When i comprehend a bit of the
language of Perl i'm on my way to make things myself because i can
look it up. When starting from scratch (as i am) is difficult.
I looked in this newsgroup an read a few things but most is mystical
to me.
I never made any program because when i was a youngster there weren't
any computers. And now at the age of 50 i want to learn Perl because i
read and heard it can do a lot with large quantaties of text.

I understand yout point and have to try first and make some code.
Point taken.
Anyway really thanks for pointing this out to me.
I guess i was a bit naive.

Andries Meijer
(e-mail address removed)
 
R

Robin

And now at the age of 50 i want to learn Perl because i
read and heard it can do a lot with large quantaties of text.

Yeah, just from the name you can infer it - Perl = Practical Extraction and
Report Language.
-Robin
 
G

gnari

Andries said:
I just started and i'm not further yet than "Hello world"
I use the sybex book called Perl, CGI and Javascript Complete.

You should familarize yourself with the docs
that come with perl.

actually the problem you selected is a good one for a beginner,
but you should at least show is what you have tried yourself
before asking for help. as an exercise, I suggest you start by
making a program that reads the input lines and prints then all
out. when that is solved, add things to it, like just printing
a line matching a specific condition. there are many ways to
test your lines, like using substr(), index() or regular expressions
look these up in the docs:
perldoc -f substr
perldoc -f index
perldoc perlre

take a look at http://learn.perl.org/

good luck

gnari
 
J

Jim Cochrane

First of all my apologies! Truly meant.
No, i don't have code. How could I
I just started and i'm not further yet than "Hello world"
I use the sybex book called Perl, CGI and Javascript Complete.

I didn't want to insult any of you.
I always learn a lot from questions i ask and things i really need and
can use. I'm not a very theoretical man. I have trouble reading
learning books on computers. I really learn a lot from the problems i
stumble on and the question for help. When i comprehend a bit of the
language of Perl i'm on my way to make things myself because i can
look it up. When starting from scratch (as i am) is difficult.
I looked in this newsgroup an read a few things but most is mystical
to me.
I never made any program because when i was a youngster there weren't
any computers. And now at the age of 50 i want to learn Perl because i
read and heard it can do a lot with large quantaties of text.

I understand yout point and have to try first and make some code.
Point taken.
Anyway really thanks for pointing this out to me.
I guess i was a bit naive.

The first step in solving a problem is to define, as precisely as
possible, what the problem is. Sometimes this is the hardest part
of developing a program or application; and sometimes it requires an
iterative process - e.g., start with an initial problem specification,
experiment with implementations, realize that it would really be better
if you changed the spec. to be more general, comprehensive, specific,
or etc.

However, after some experience with this process you'll probably get
better at coming up with a good, well-thought-out initial problem
specification, essentially going through a good part of the process of
refining the specification in your mind (and/or on paper) before you
even write a line of code, usually saving much time in the process.

The better you get at producing a good, complete spec., the better
results you're likely to get if you post to this group needing help
with the implementation. (Though I'd wager that if you word your
request well you're likely to even get good help in coming up with a
good specification, as well as help with the implementation.)

Good luck - 50 is definitely not too old to learn good development and
programming skills if you have the interest and commitment.
 
A

Andries

The first step in solving a problem is to define, as precisely as
possible, what the problem is. Sometimes this is the hardest part
of developing a program or application; and sometimes it requires an
iterative process - e.g., start with an initial problem specification,
experiment with implementations, realize that it would really be better
if you changed the spec. to be more general, comprehensive, specific,
or etc.

However, after some experience with this process you'll probably get
better at coming up with a good, well-thought-out initial problem
specification, essentially going through a good part of the process of
refining the specification in your mind (and/or on paper) before you
even write a line of code, usually saving much time in the process.

The better you get at producing a good, complete spec., the better
results you're likely to get if you post to this group needing help
with the implementation. (Though I'd wager that if you word your
request well you're likely to even get good help in coming up with a
good specification, as well as help with the implementation.)

Good luck - 50 is definitely not too old to learn good development and
programming skills if you have the interest and commitment.

Let me try to explain my question.
I use a program (Whisper) to generate passwords.
I have to fill in the (real-name), the username, the pwd and a
memo-field with data of the "customer"
I have hundreds of these accounts.

I can export all this data to a csv - file

So I have a text-file. What i want is to sort some of the data f.i.
name an pwd out and put them in a new text-file
The example I used before is just an example and I made xxxxx to
disclose the identities.

Andries
 
J

Jim Cochrane

Let me try to explain my question.
I use a program (Whisper) to generate passwords.
I have to fill in the (real-name), the username, the pwd and a
memo-field with data of the "customer"
I have hundreds of these accounts.

I can export all this data to a csv - file

So I have a text-file. What i want is to sort some of the data f.i.
name an pwd out and put them in a new text-file
The example I used before is just an example and I made xxxxx to
disclose the identities.

This is a good start. If I understand right, it sounds like you need at
least two requirements wrt processing the text file*:

- Select a subset of the records in the file according to some criteria
("sort some of the data").
- For each record, print out just the name and password field.
(This is easy if the data is, as you imply, structured.)

[I guess sorting is another requirement, but it can be dealt with later.]

The question then arises: What criteria do you want to use to select a
subset of the records? A general description of the different criteria
and/or some examples would be very helpful.

* This may be my ignorance of a standard convention, but I don't know what
"f.i." stands for. If it has a bearing on the requirements, let me know.
 
A

Andries

Let me try to explain my question.
I use a program (Whisper) to generate passwords.
I have to fill in the (real-name), the username, the pwd and a
memo-field with data of the "customer"
I have hundreds of these accounts.

I can export all this data to a csv - file

So I have a text-file. What i want is to sort some of the data f.i.
name an pwd out and put them in a new text-file
The example I used before is just an example and I made xxxxx to
disclose the identities.

This is a good start. If I understand right, it sounds like you need at
least two requirements wrt processing the text file*:

- Select a subset of the records in the file according to some criteria
("sort some of the data").
- For each record, print out just the name and password field.
(This is easy if the data is, as you imply, structured.)

[I guess sorting is another requirement, but it can be dealt with later.]

The question then arises: What criteria do you want to use to select a
subset of the records? A general description of the different criteria
and/or some examples would be very helpful.

* This may be my ignorance of a standard convention, but I don't know what
"f.i." stands for. If it has a bearing on the requirements, let me know.

I have the next (few hundreds of)
sex: male
Surname : Great
Voorletters: A
Tussenvoegsel(s): the
Adres : xxxxx
Postcode : xxxxx
Woonplaats : xxxx
Telefoonnummer : xxxxx
e-mail (privé) : xxxxxx
Schoollocatie : Humbold
Schooladres : xxxxxx
Postcode: xxxxx
Plaats : xxxxx
Telefoonnummer: xxxxx
E-mail school : xxxxxxx

It's all in a long, long text-file all different names, adresses etc.

I want to pick a few items of the data out like the name and the
school and put them in a new textfile like a list with:
name: Great
School: Humbold
[new line]
name: Johnson
School: Harvard
[new line]
etc

I think it should be like this (in laymans terms)
->Read the oldfile
->Look for name:
->Remember name: and whats behind the:
->Look for school: and what's behind the :
->Make a new (empy) line
->Look for name:
->Remember name: and whats behind the:
->Look for school: and what's behind the :
->Make a new (empy) line
and so on
-> write to newfile


perl myprog.pl < oldfile newfile >

Andries
 
J

Jürgen Exner

Robin said:
Yeah, just from the name you can infer it - Perl = Practical
Extraction and Report Language.

Please don't contribute to the proliferation of urban legends.
See "perldoc perl": "What's the difference between "perl" and "Perl"?"
last sentence.

jue
 
R

Robin

Jürgen Exner said:
Please don't contribute to the proliferation of urban legends.
See "perldoc perl": "What's the difference between "perl" and "Perl"?"
last sentence.

point taken, I suppose.
-Robin
 
J

Jürgen Exner

Sherm said:
I think you mean "perldoc perlfaq1".

No, I did mean the last sentence in the answer to "What's the difference
between "perl" and "Perl"?" which is one of the many answers you get when
querying for "perl".
Of course, the same answer will pop up as part of perlfaq1, too.
According to the (nearly) last sentence in "perldoc perl", it stands
for "Pathologically Eclectic Rubbish Lister". For some reason I doubt
that's what you were referring to... ;-)

Nice one. Fine with me, too. But why is it listed under "bugs"?

jue
 

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top