Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to parse out specific data in text files and plugs into thespreadsheet

Reply
Thread Tools

How to parse out specific data in text files and plugs into thespreadsheet

 
 
cyrusgreats@gmail.com
Guest
Posts: n/a
 
      12-06-2007
I need help writing a script in perl that takes text files and parses
out specific data and plugs the data back into the spreadsheet. Can
anyone help me on that..Thanks in advance..
 
Reply With Quote
 
 
 
 
J. Gleixner
Guest
Posts: n/a
 
      12-06-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I need help writing a script in perl that takes text files and parses
> out specific data and plugs the data back into the spreadsheet. Can
> anyone help me on that..Thanks in advance..


The documentation can help, along with thousands of Web sites, and
many, many books.

perldoc perlopentut
perldoc -f split

Books:

http://books.perl.org/
 
Reply With Quote
 
 
 
 
cyrusgreats@gmail.com
Guest
Posts: n/a
 
      12-07-2007
On Dec 6, 5:38 pm, Tad McClellan <(E-Mail Removed)> wrote:
> (E-Mail Removed) <(E-Mail Removed)> wrote:
> > I need help writing a script in perl that takes text files and parses
> > out specific

>
> You have left the specifics unspecified...
>
> > data and plugs the data back into the spreadsheet.

>
> Errr, what flavor of spreadsheet would that be?
>
> Many of them have there own, uncompatible, data formats.
>
> > Can
> > anyone help me on that..

>
> Yes.
>
> > Thanks in advance..

>
> You're welcome in advance.
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


Well what meant by specifics, each person in this exmaple have an id
as follows:

Capitan id : 123456
Time arrival : 10:00:56
Time left : 12:11:23

Capitan id : 88456
Time arrival : 1100:56
Time left : 12:17:0

As for spreadsheet, excel file would work!
 
Reply With Quote
 
J. Gleixner
Guest
Posts: n/a
 
      12-07-2007
(E-Mail Removed) wrote:

>>> I need help writing a script in perl that takes text files and parses
>>> out specific

[...]
> Well what meant by specifics, each person in this exmaple have an id
> as follows:
>
> Capitan id : 123456
> Time arrival : 10:00:56
> Time left : 12:11:23
>
> Capitan id : 88456
> Time arrival : 1100:56
> Time left : 12:17:0
>
> As for spreadsheet, excel file would work!


You will need to put SOME work into this. You'll have to
parse it into the various fields and you could use
Spreadsheet::WriteExcel to create an Excel file.

http://search.cpan.org/~jmcnamara/Sp.../WriteExcel.pm
 
Reply With Quote
 
cyrusgreats@gmail.com
Guest
Posts: n/a
 
      12-07-2007
On Dec 7, 8:42 am, "J. Gleixner" <(E-Mail Removed)>
wrote:
> (E-Mail Removed) wrote:
> >>> I need help writing a script in perl that takes text files and parses
> >>> out specific

> [...]
> > Well what meant by specifics, each person in this exmaple have an id
> > as follows:

>
> > Capitan id : 123456
> > Time arrival : 10:00:56
> > Time left : 12:11:23

>
> > Capitan id : 88456
> > Time arrival : 1100:56
> > Time left : 12:17:0

>
> > As for spreadsheet, excel file would work!

>
> You will need to put SOME work into this. You'll have to
> parse it into the various fields and you could use
> Spreadsheet::WriteExcel to create an Excel file.
>
> http://search.cpan.org/~jmcnamara/Sp...20/lib/Spr...- Hide quoted text -
>
> - Show quoted text


I've already wrote the code for Spreadsheet what is left parsing the
data and put them possibly into the has with their value.


 
Reply With Quote
 
J. Gleixner
Guest
Posts: n/a
 
      12-07-2007
(E-Mail Removed) wrote:
> On Dec 7, 8:42 am, "J. Gleixner" <(E-Mail Removed)>
> wrote:
>> (E-Mail Removed) wrote:
>>>>> I need help writing a script in perl that takes text files and parses
>>>>> out specific

>> [...]
>>> Well what meant by specifics, each person in this exmaple have an id
>>> as follows:
>>> Capitan id : 123456
>>> Time arrival : 10:00:56
>>> Time left : 12:11:23
>>> Capitan id : 88456
>>> Time arrival : 1100:56
>>> Time left : 12:17:0
>>> As for spreadsheet, excel file would work!

>> You will need to put SOME work into this. You'll have to
>> parse it into the various fields and you could use
>> Spreadsheet::WriteExcel to create an Excel file.
>>
>> http://search.cpan.org/~jmcnamara/Sp...l-2.20/lib/Spr...


> I've already wrote the code for Spreadsheet what is left parsing the
> data and put them possibly into the has with their value.


You could use split or a regular expression.

perldoc -f split
perldoc perlretut

Why not give it a try, post it, and explain what steps are
causing problems. You're not paying us enough to write your
code for you.
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      12-07-2007
[please don't quote Google's -hide quoted text- rubbish]

Quoth (E-Mail Removed):
> On Dec 7, 8:42 am, "J. Gleixner" <(E-Mail Removed)>
> wrote:
> > (E-Mail Removed) wrote:
> > >>> I need help writing a script in perl that takes text files and parses
> > >>> out specific

> > [...]
> > > Well what meant by specifics, each person in this exmaple have an id
> > > as follows:

> >
> > > Capitan id : 123456
> > > Time arrival : 10:00:56
> > > Time left : 12:11:23

> >
> > > Capitan id : 88456
> > > Time arrival : 1100:56
> > > Time left : 12:17:0

> >
> > > As for spreadsheet, excel file would work!

> >
> > You will need to put SOME work into this. You'll have to
> > parse it into the various fields and you could use
> > Spreadsheet::WriteExcel to create an Excel file.
> >
> >

> http://search.cpan.org/~jmcnamara/Sp...20/lib/Spr...-
>
> I've already wrote the code for Spreadsheet what is left parsing the
> data and put them possibly into the has with their value.


You mean like

my @records;

{
open my $FILE, '<', 'file.txt'
or die "can't open file.txt: $!";

local $/ = '';

while (my $rec = <$FILE>) {
my @fields = split /\n/, $rec;
my %rec;

for (@fields) {
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "invalid field: '$_'";
$rec{$k} = $v;
}

push @records, \%rec;
}
}

? Was that really so difficult?

Ben

 
Reply With Quote
 
cyrusgreats@gmail.com
Guest
Posts: n/a
 
      12-07-2007
On Dec 7, 9:49 am, Ben Morrow <(E-Mail Removed)> wrote:
> [please don't quote Google's -hide quoted text- rubbish]
>
> Quoth (E-Mail Removed):
>
>
>
>
>
> > On Dec 7, 8:42 am, "J. Gleixner" <(E-Mail Removed)>
> > wrote:
> > > (E-Mail Removed) wrote:
> > > >>> I need help writing a script in perl that takes text files and parses
> > > >>> out specific
> > > [...]
> > > > Well what meant by specifics, each person in this exmaple have an id
> > > > as follows:

>
> > > > Capitan id : 123456
> > > > Time arrival : 10:00:56
> > > > Time left : 12:11:23

>
> > > > Capitan id : 88456
> > > > Time arrival : 1100:56
> > > > Time left : 12:17:0

>
> > > > As for spreadsheet, excel file would work!

>
> > > You will need to put SOME work into this. You'll have to
> > > parse it into the various fields and you could use
> > > Spreadsheet::WriteExcel to create an Excel file.

>
> >http://search.cpan.org/~jmcnamara/Sp...l-2.20/lib/Spr...

>
> > I've already wrote the code for Spreadsheet what is left parsing the
> > data and put them possibly into the has with their value.

>
> You mean like
>
> my @records;
>
> {
> open my $FILE, '<', 'file.txt'
> or die "can't open file.txt: $!";
>
> local $/ = '';
>
> while (my $rec = <$FILE>) {
> my @fields = split /\n/, $rec;
> my %rec;
>
> for (@fields) {
> my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
> or die "invalid field: '$_'";
> $rec{$k} = $v;
> }
>
> push @records, \%rec;
> }
> }
>
> ? Was that really so difficult?
>
> Ben- Hide quoted text -
>
> - Show quoted text -


Thanks but I'm getting error: invalid field in this line:
my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
or die "invalid field: '$_'";
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      12-08-2007

Quoth (E-Mail Removed):
> On Dec 7, 9:49 am, Ben Morrow <(E-Mail Removed)> wrote:
> >
> > [please don't quote Google's -hide quoted text- rubbish]

<snip>
> > Ben- Hide quoted text -


Which part of the above did you fail to understand?

<snip>
> > local $/ = '';
> >
> > while (my $rec = <$FILE>) {
> > my @fields = split /\n/, $rec;
> > my %rec;
> >
> > for (@fields) {
> > my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
> > or die "invalid field: '$_'";
> > $rec{$k} = $v;
> > }

<snip>
> Thanks but I'm getting error: invalid field in this line:
> my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
> or die "invalid field: '$_'";


So... you have a line which doesn't match the pattern. The error message
told you what the line looks like, and which paragraph of the file it was
in. Now change the pattern so it matches what you want it to match.

Ben

 
Reply With Quote
 
cyrusgreats@gmail.com
Guest
Posts: n/a
 
      12-08-2007
On Dec 7, 4:33 pm, Ben Morrow <(E-Mail Removed)> wrote:
> Quoth (E-Mail Removed):
>
> > On Dec 7, 9:49 am, Ben Morrow <(E-Mail Removed)> wrote:

>
> > > [please don't quote Google's -hide quoted text- rubbish]

> <snip>
> > > Ben- Hide quoted text -

>
> Which part of the above did you fail to understand?
>
> <snip>
>
> > > local $/ = '';

>
> > > while (my $rec = <$FILE>) {
> > > my @fields = split /\n/, $rec;
> > > my %rec;

>
> > > for (@fields) {
> > > my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
> > > or die "invalid field: '$_'";
> > > $rec{$k} = $v;
> > > }

> <snip>
> > Thanks but I'm getting error: invalid field in this line:
> > my ($k, $v) = /([^:]*) \s* : \s* (.*)/x
> > or die "invalid field: '$_'";

>
> So... you have a line which doesn't match the pattern. The error message
> told you what the line looks like, and which paragraph of the file it was
> in. Now change the pattern so it matches what you want it to match.
>
> Ben


thanks I figured that out...
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Two RCA plugs into One [OT] Alan NZ Computing 20 02-07-2008 09:01 AM
Optimal configurating for switch port that router plugs into troute_kilgore@yahoo.com Cisco 1 12-19-2004 11:14 PM
switching speaker plugs at sound card rr Computer Support 8 12-17-2003 12:25 AM



Advertisments