CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
extract data...

 



AWHF
Novice

Apr 9, 2007, 7:38 PM

Post #1 of 44 (5872 views)
extract data... Can't Post

hey!

i want to extract word from a file.
the file consist of text.
i want to extract the word in a bracket.
for e.g: pin(Vcc)
the pin( ) in blue color is static while the word in red color is dynamic.
how am i going to wirte the script?


i had try using patter matching
s/\w+/;
if (/pin(/../)/)
print FILEWRITE;
but it failed to function.


osmodius
Novice

Apr 14, 2007, 9:52 AM

Post #2 of 44 (5859 views)
Re: [AWHF] extract data... [In reply to] Can't Post

You're heading to your solution, but you've made a few mistakes. Try:


Code
#!/usr/bin/perl 

open(FILE, "file.txt");
open(FILEWRITE, ">filewrite.txt");
while($line = <FILE>){
if ($line =~ /pin\((\w+)\)/){
print FILEWRITE "$1\n";
}
}
close FILE;
close FILEWRITE;



Need some real-time help? Shove admin@ub3r.net on yer MSN.


AWHF
Novice

Apr 18, 2007, 6:16 PM

Post #3 of 44 (5843 views)
Re: [osmodius] extract data... [In reply to] Can't Post

i have try the script, and its work as what i wanted.
if i want to sort it after extracted? how can i sort it?


osmodius
Novice

Apr 19, 2007, 10:57 AM

Post #4 of 44 (5837 views)
Re: [AWHF] extract data... [In reply to] Can't Post


In Reply To
i have try the script, and its work as what i wanted.
if i want to sort it after extracted? how can i sort it?


You can add the matches to an array, like so..


Code
#!/usr/bin/perl  

open(FILE, "file.txt");
open(FILEWRITE, ">filewrite.txt");
while($line = <FILE>){
if ($line =~ /pin\((\w+)\)/){
push(@matches, "$1");
}
}
close FILE;
close FILEWRITE;


The @matches array will then be populated with all the matching strings between the pin() statement. You can then sort these or do whatever you want with them.


Need some real-time help? Shove admin@ub3r.net on yer MSN.


AWHF
Novice

May 28, 2007, 11:16 PM

Post #5 of 44 (5792 views)
Re: [osmodius] extract data... [In reply to] Can't Post

#!/usr/bin/perl
print "enter name: ";
$name = <>;
open(FILE2,$name);
while(<FILE2>)
{
chomp;
@arr = split;
$pin = @arr[0];
open (FILEREAD, "<$pin");
open (FILEWRITE, ">>result");
while ($line = <FILEREAD>)
{
if ($line =~/pin\((\w+)\)/)
{
push (@matches, "$1\n");
@sorted = sort(@matches);

}
print FILEWRITE "@sorted";
}
close FILEWRITE;
close FILEREAD;
}
close FILE2;




i had try out to sort the data by using the following script but the result it came out is only a few data sorted and not all the data.


KevinR
Veteran


May 28, 2007, 11:48 PM

Post #6 of 44 (5789 views)
Re: [AWHF] extract data... [In reply to] Can't Post

The data is sorted. The problem is that you don't understand how the default sort works. See if this helps you understand how to use the sort() function to get the results you need:

http://perldoc.perl.org/functions/sort.html
-------------------------------------------------


AWHF
Novice

Jun 11, 2007, 8:59 PM

Post #7 of 44 (5772 views)
Re: [KevinR] extract data... [In reply to] Can't Post

Let say, in my home directory I have a directory called “document”. In the directory, all the files name end with .doc (e.g: notes1.doc). The question is how can I write a script to extract the info from all the .doc file and print it in a file (let say the file called “result”). the concept i use is:-
1) open the directory "document"
2) search for all the .doc file (pattern matching)
3) create file "result"
4) extract info from all .doc file
5) print to the extracted info into result

this is the 1st to open the directory before i continuew to next step. is this the correct code?



Code
 #!/usr/bin/perl 
$dirname = "/eng/png/home/awhf/document";
opendir(DIR, "<$dirname")or die "Cannot open directory";
while(<DIR>)
{
.....
.....
.....




KevinR
Veteran


Jun 11, 2007, 10:52 PM

Post #8 of 44 (5768 views)
Re: [AWHF] extract data... [In reply to] Can't Post


In Reply To
Let say, in my home directory I have a directory called “document”. In the directory, all the files name end with .doc (e.g: notes1.doc). The question is how can I write a script to extract the info from all the .doc file and print it in a file (let say the file called “result”). the concept i use is:-
1) open the directory "document"
2) search for all the .doc file (pattern matching)
3) create file "result"
4) extract info from all .doc file
5) print to the extracted info into result

this is the 1st to open the directory before i continuew to next step. is this the correct code?


Code
 #!/usr/bin/perl 
$dirname = "/eng/png/home/awhf/document";
opendir(DIR, "<$dirname")or die "Cannot open directory";
while(<DIR>)
{
.....
.....
.....




Code
#!/usr/bin/perl 
use strict;
use warnings;

my $dirname = "/eng/png/home/awhf/document";
chdir ($dirname) or die "Can't chdir to $dirname: $!";
opendir(DIR, $dirname) or die "Cannot open directory: $!";
my @files = grep {/\.doc$/} DIR;
close DIR;

open (OUT,">>results.txt") or die "Can't open results.txt: $!";
{
local @ARGV = @files;
while (<>) {
print OUT;
}
}
close OUT;

-------------------------------------------------


AWHF
Novice

Jun 11, 2007, 11:57 PM

Post #9 of 44 (5765 views)
Re: [KevinR] extract data... [In reply to] Can't Post

hey!
i had try out your code but there is a error occurs as follow:-

Bareword "DIR" not allowed while "strict subs" in use at script.pl line 8.
Execution of script.pl aborted due to compilation errors.



KevinR
Veteran


Jun 12, 2007, 12:10 AM

Post #10 of 44 (5763 views)
Re: [AWHF] extract data... [In reply to] Can't Post

oops, should be:

my @files = grep {/\.doc$/} readdir DIR;
-------------------------------------------------


AWHF
Novice

Jun 12, 2007, 12:21 AM

Post #11 of 44 (5761 views)
Re: [KevinR] extract data... [In reply to] Can't Post

yeah...!
all the info was print in the result. but the file "result" was alocated in the "document" directory. how if i want to located the file "result" in my home directory?


KevinR
Veteran


Jun 12, 2007, 12:49 AM

Post #12 of 44 (5754 views)
Re: [AWHF] extract data... [In reply to] Can't Post

open (OUT,">>/eng/png/home/awhf/results.txt") or die "Can't open results.txt: $!";
-------------------------------------------------


AWHF
Novice

Jun 12, 2007, 1:30 AM

Post #13 of 44 (5750 views)
Re: [KevinR] extract data... [In reply to] Can't Post

ok! it's work!
this mean the code is to print all the info in the .doc files into the "result". How if i want to print a specific info like what we discuss in the start print and stop print subject where i need to use indicator to indicate when is it "::START" it will start printing and when "::END" it will stop printing. where should i write the code at? is that at "some where here"


Code
 #!/usr/bin/perl  
use strict;
use warnings;
my $dirname = "/eng/png/home/awhf/document";
chdir ($dirname) or die "Can't chdir to $dirname: $!";
opendir(DIR, $dirname) or die "Cannot open directory: $!";
my @files = grep {/\.doc$/}readdir DIR;
close DIR;
open (OUT,">>/eng/png/home/awhf/results.txt") or die "Can't open results.txt: $!";
{
local @ARGV = @files;
while (<>) {
some where here
print OUT;
}
}
close OUT;





KevinR
Veteran


Jun 12, 2007, 10:47 AM

Post #14 of 44 (5742 views)
Re: [AWHF] extract data... [In reply to] Can't Post

maybe:


Code
#!/usr/bin/perl  
use strict;
use warnings;

my $dirname = "c:/";
chdir ($dirname) or die "Can't chdir to $dirname: $!";
opendir(DIR, $dirname) or die "Cannot open directory: $!";
my @files = grep {/\.txx$/} readdir DIR;
close DIR;
print "@files\n";
open (OUT,">results444.txt") or die "Can't open results.txt: $!";
{
local @ARGV = @files;
local $/ = undef;
while (<>) {
if ( /::START(.*?)::END/s ) {
print OUT $1;
}
}
}
close OUT;

-------------------------------------------------


AWHF
Novice

Jun 12, 2007, 11:16 PM

Post #15 of 44 (5728 views)
Re: [KevinR] extract data... [In reply to] Can't Post

i had try out but it can't function as what i want. actually i need to extract specific info fro example:

::Start
Ali
Baba
Zarul
Bahrul
Alec
Foong
Caster
Lee
::End

this is the code that i had try out





Code
  

#!/usr/bin/perl
use strict;
use warnings;
my $dirname = "/eng/png/home/awhf/document";
chdir ($dirname) or die "Can't chdir to $dirname: $!";
opendir(DIR, $dirname) or die "Cannot open directory: $!";
my @files = grep {/\.cas$/} readdir DIR;
close DIR;
print "@files\n";
open (OUT,">>/eng/png/home/awhf/results") or die "Can't open results: $!";
{
local @ARGV = @files;
local $/ = undef;
while (<>)

{
s/\s*(\w+).*/$1/;

if ( /::START(.*?)::END/s )

{

print OUT $1;

}

}

}

close OUT;



KevinR
Veteran


Jun 12, 2007, 11:28 PM

Post #16 of 44 (5721 views)
Re: [AWHF] extract data... [In reply to] Can't Post


Quote
actually i need to extract specific info fro example:


What info are you wanting to extract from the data you posted?
-------------------------------------------------


AWHF
Novice

Jun 12, 2007, 11:37 PM

Post #17 of 44 (5720 views)
Re: [KevinR] extract data... [In reply to] Can't Post

ops...sorry!

::Start
Ali Baba
Zarul
Bahrul
Alec
Foong
Caster
Lee
::End


actually i want to extract the data blue in color


KevinR
Veteran


Jun 13, 2007, 12:05 AM

Post #18 of 44 (5716 views)
Re: [AWHF] extract data... [In reply to] Can't Post

See if this works:


Code
#!/usr/bin/perl     
use strict;
use warnings;
my $dirname = "/eng/png/home/awhf/document";
chdir ($dirname) or die "Can't chdir to $dirname: $!";
opendir(DIR, $dirname) or die "Cannot open directory: $!";
my @files = grep {/\.cas$/} readdir DIR;
close DIR;
print "@files\n";
open (OUT,">>/eng/png/home/awhf/results") or die "Can't open results: $!";
{
local @ARGV = @files;
local $/ = undef;
while(<>) {
if ( /::START(.*?)::END/is ) {
my $match = $1;
$match =~ s/^\s*(\w+).*$/$1/gm;
print OUT $match;
}
}
}
close OUT;

-------------------------------------------------


AWHF
Novice

Jun 13, 2007, 12:46 AM

Post #19 of 44 (5714 views)
Re: [KevinR] extract data... [In reply to] Can't Post

no, it still can't function properly. it print out numbers and not the info which is blue in color


KevinR
Veteran


Jun 13, 2007, 9:33 AM

Post #20 of 44 (5694 views)
Re: [AWHF] extract data... [In reply to] Can't Post

instead of saying: "still can't function properly" describe what the script does do. Does it match some lines? Does it match no lines? Does it give an error?

Try this:


Code
#!/usr/bin/perl      
use strict;
use warnings;
my $dirname = "/eng/png/home/awhf/document";
chdir ($dirname) or die "Can't chdir to $dirname: $!";
opendir(DIR, '.') or die "Cannot open directory: $!";
my @files = grep {/\.cas$/} readdir DIR;
close DIR;
print "@files\n";
open (OUT,">>/eng/png/home/awhf/results") or die "Can't open results: $!";
{
local @ARGV = @files;
local $/ = undef;
while(<>) {
while ( /::START(.*?)::END/isg ) {
my $match = $1;
$match =~ s/^\s*(\w+).*$/$1/gm;
print OUT $match;
}
}
}
close OUT;

-------------------------------------------------


AWHF
Novice

Jun 13, 2007, 8:15 PM

Post #21 of 44 (5684 views)
Re: [KevinR] extract data... [In reply to] Can't Post

As what i had try the code, it still can't function. There is an error. The info in the "result" is full with numbers instead a the info that is in the .doc files.


Code
 #!/usr/bin/perl       
use strict;
use warnings;
my $dirname = "/eng/png/home/awhf/document";
chdir ($dirname) or die "Can't chdir to $dirname: $!";
opendir(DIR, '.') or die "Cannot open directory: $!";
my @files = grep {/\.cas$/} readdir DIR;
close DIR;

open (OUT,">>/eng/png/home/awhf/results") or die "Can't open results: $!";
{
local @ARGV = @files;
local $/ = undef;
while(<>) {
while ( /::START(.*?)::END/isg ) {
my $match = $1;
$match =~ s/^\s*(\w+).*$/$1/gm;
print OUT $match;
}
}
}
close OUT;



the info in the "result" is as follow:
123543678432435476452454769875735
123543579879067563427346582134490
432135468424130978967581341341657

instead of:
Ali
Zarul

Alec

Caster




KevinR
Veteran


Jun 13, 2007, 11:42 PM

Post #22 of 44 (5678 views)
Re: [AWHF] extract data... [In reply to] Can't Post

without seeing the files you are working with I dont know what the problem is.
-------------------------------------------------


AWHF
Novice

Jun 18, 2007, 12:16 AM

Post #23 of 44 (5647 views)
Re: [KevinR] extract data... [In reply to] Can't Post

The example files i work on are as follow:

File1.doc

::Start
Ali Baba
Zarul
Bahrul
Alec
Foong
Caster
Lee
::End

File2.doc

::Start
Calvin Lee
Ester Foong
Alex Wong

Lee Kim
::End

File3.doc

::Start
Jocob Lim
Irene Chai
::End



(This post was edited by AWHF on Jun 18, 2007, 12:22 AM)


AWHF
Novice

Jun 25, 2007, 1:32 AM

Post #24 of 44 (5579 views)
Re: [KevinR] extract data... [In reply to] Can't Post

hey!

this is my code

Code
 #!/usr/bin/perl 
print "enter name: ";
$name = <>;
open(FILE,$name);
while(<FILE>)
{
chomp;
@arr = split;
$file = @arr[0];
open (FILEREAD, "<$file");
open (FILEWRITE, ">>result2");
while (<FILEREAD>)
{
s/\s*(\w+).*/$1/;
if (/^::pin/../^::delay/)
{
print FILEWRITE "$1\n";
} }
close FILEWRITE;
close FILEREAD;
}
close FILE;



instead of using the highlight code how can i automatically open the file without asking the user to keyin?

can i use this code below? how can i combine with my script?

my $dirname = "/engpng/home/awhf/document";
chdir ($dirname) || die "can't chdir to $dirname: $!";
opendir(DIR, $dirname) || die "can't open directory: $!";






KevinR
Veteran


Jun 25, 2007, 9:16 AM

Post #25 of 44 (5575 views)
Re: [AWHF] extract data... [In reply to] Can't Post

opendir() is for opening a directory, not a file. But you could change the path to a file and then use open():


Code
#!/usr/bin/perl 
my $file = 'path/to/some/file.txt';
open(FILE,$file) or die "$!";
while(<FILE>)
{

-------------------------------------------------


AWHF
Novice

Jun 25, 2007, 6:34 PM

Post #26 of 44 (3249 views)
Re: [KevinR] extract data... [In reply to] Can't Post

sorry!
what i'm trying to mean that is i want to open all the files in a directory which the name ended by .doc.
let's say the file called "file1.doc", "file2.doc", "file3.doc", .... and the directory called "document". i had try out this script but it could not function. there is nothing in the "result"

Code
  #!/usr/bin/perl   
my $dirname = "/eng/png/home/awhf/document";
chdir ($dirname) || die "can't chdir to $dirname: $!";
opendir(DIR, $dirname) || die "can't open directory: $!";
my @files = grep {/\.doc$/} readdir DIR;
close DIR;
open(OUT, ">>/eng/png/home/awhf/result") || die "can't open: $!";
while (<@files>)
{
s/\s*(\w+).*/$1/;
if (/^::start/../^end/)
{
print OUT;
}
}
close OUT



(This post was edited by AWHF on Jun 25, 2007, 6:40 PM)


KevinR
Veteran


Jun 25, 2007, 8:18 PM

Post #27 of 44 (3241 views)
Re: [AWHF] extract data... [In reply to] Can't Post

I thought I already showed you how to do this earlier in the thread. If you want to read the file directly from the @files array you have to explicitly open them:


Code
#!/usr/bin/perl    
my $dirname = "/eng/png/home/awhf/document";
chdir ($dirname) || die "can't chdir to $dirname: $!";
opendir(DIR, $dirname) || die "can't open directory: $!";
my @files = grep {/\.doc$/} readdir DIR;
close DIR;
open(OUT, ">>/eng/png/home/awhf/result") || die "can't open: $!";
foreach my $file (@files) {
open (my $FH, $file) or die "$!";
while (<$FH>)

{
s/\s*(\w+).*/$1/;
if (/^::start/../^end/)
{
print OUT;
}
}
}


I don't know if thats going to print anything to OUT but thats the way to cycle through and read the files in @files.
-------------------------------------------------


AWHF
Novice

Jun 29, 2007, 12:27 AM

Post #28 of 44 (3230 views)
Re: [KevinR] extract data... [In reply to] Can't Post


As what i had try the code, it still can't function. There is an error. The info in the "result" is full with numbers instead a the info that is in the .doc files.


Code
  #!/usr/bin/perl        
use strict;
use warnings;
my $dirname = "/eng/png/home/awhf/document";
chdir ($dirname) or die "Can't chdir to $dirname: $!";
opendir(DIR, '.') or die "Cannot open directory: $!";
my @files = grep {/\.cas$/} readdir DIR;
close DIR;

open (OUT,">>/eng/png/home/awhf/results") or die "Can't open results: $!";
{
local @ARGV = @files;
local $/ = undef;
while(<>) {
if(/::START(.*?)::END/is) {
my $match = $1;
$match =~ s/(\w+)/$1/gm;

print OUT $match;
}
}
}
close OUT;



the info in the "result" is as follow:
123543678432435476452454769875735
123543579879067563427346582134490
432135468424130978967581341341657

instead of:
Ali
Zarul

Alec

Caster








As what we discuss previously, the are error at the output. As i notice that the coding in the red color have some error. How am i gonna correct it?

The example files i work on are as follow:

File1.doc

::Start
Ali Baba
Zarul
Bahrul
Alec
Foong
Caster
Lee
::End

File2.doc

::Start
Calvin Lee
Ester Foong
Alex Wong

Lee Kim
::End

File3.doc

::Start
Jocob Lim
Irene Chai
::End



KevinR
Veteran


Jun 29, 2007, 12:56 AM

Post #29 of 44 (3224 views)
Re: [AWHF] extract data... [In reply to] Can't Post


Quote
The info in the "result" is full with numbers instead a the info that is in the .doc files.


I don't know why you are getting those numbers. when I run the code with the sample data I get the correct results.
-------------------------------------------------


AWHF
Novice

Jun 29, 2007, 1:12 AM

Post #30 of 44 (3223 views)
Re: [KevinR] extract data... [In reply to] Can't Post

is there another code the replace the code in red color?


KevinR
Veteran


Jun 29, 2007, 10:36 AM

Post #31 of 44 (3213 views)
Re: [AWHF] extract data... [In reply to] Can't Post

There are probably a few ways to do what you are trying.
-------------------------------------------------


AWHF
Novice

Jul 1, 2007, 5:11 PM

Post #32 of 44 (3200 views)
Post deleted by AWHF [In reply to]

 


KevinR
Veteran


Jul 1, 2007, 8:31 PM

Post #33 of 44 (3197 views)
Re: [AWHF] extract data... [In reply to] Can't Post

I might help you, but I will not do it for you.
-------------------------------------------------


AWHF
Novice

Jul 2, 2007, 1:42 AM

Post #34 of 44 (3193 views)
Re: [KevinR] extract data... [In reply to] Can't Post

Actually after the previous discussion, i need to do an assignment. My assignment are as follow:- I have 2 directories, "DIR_A" & "DIR_B".
In the "DIR_A" i have many file which the name end by ".doc1" (e.g: file1.doc1, file2.doc1, ...).
all the content in the files as follow(example):



file1.doc1
::Start
ali Baba
zarul Bahrul
alec Foong
caster Lee
::End

file2.doc1
::Start
Calvin Lee
Ester Foong
Alex Wong
Lee Kim
::End

file3.doc1
::Start
jocob Lim
irene Chai
::End


where else in "DIR_B" i have many files as well which the name end by "_fast.txt" and "_slow.txt" all the content in the files as follow(example):

file1_fast.txt
this is the 1st line
this is the 2nd line
name(ali)
this is the 3rd line
name(zarul)
this is the 4th line
name(alec)
this is the 5th line
this is the 6th line

file2_fast.txt
this is the 1st line
this is the 2nd line
name(calvin)
this is the 3rd line
name(alex)
this is the 4rd line

file3_fast.txt

this is the 1st line
this is the 2nd line
name(jacob)
this is the 3rd line
this is the 4th line
name(irene)
this is the 5th line
this is the 6th line


file1_slow.txt
this is 1st sentence
name(ali)
this is 2st sentence
name(zarul)
this is 3st sentence
name(alec)
this is 4st sentence


file2_slow.txt
this is 1st sentence
this is 2st sentence
name(calvin)
this is 3st sentence
name(alex)
this is 4st sentence



file3_slow.txt

this is 1st sentence
name(jacob)
this is 2st sentence
name(irene)
this is 3st sentence

where there are the same name between "_fast.txt" and "_slow.txt"
as u can see above "file1_fast.txt" = "file1_slow.txt"
"file2_fast.txt" = "file2_slow.txt"
"file3_fast.txt" = "file3_slow.txt"
the content between the "_fast.txt" and "_slow.txt" are not the same but the info that need to extract is same.









All the info are in blue color. This is my home directory (/eng/home/assignment) where the "DIR_A" and " DIR_B" are located.
I need to compare the info in all the files between "DIR_A" and "DIR_B". The comparison need to make by the same file name (e.g: file1.doc with file1_fast.txt with file1_slow.txt)

the output of the comparison will look like this:
file1
caster

file2
ester
lee

file3
none

It only show the different of the comparison




so what is the concept, methodology or how the flow chart will looks like?


KevinR
Veteran


Jul 2, 2007, 9:08 AM

Post #35 of 44 (3186 views)
Re: [AWHF] extract data... [In reply to] Can't Post

hint: use a hash
-------------------------------------------------


AWHF
Novice

Jul 2, 2007, 5:11 PM

Post #36 of 44 (3181 views)
Re: [KevinR] extract data... [In reply to] Can't Post

DIR_A
1) Go in to DIR_A
2) Sort files to make all the files between ".doc", "_fast.txt" and "_slow.txt" the same. (e.g: file1.doc = file1_fast.txt = file1_slow.txt)
3) Open the files one by one
4) Extract info
5) Sort the info
6) compare
7) Print out the result (different & same)

DIR_A -> open DIR_A -> sort files -> open the same name file -> extract info -> sort info -> compare -> print result

DIR_B
1) Go in to DIR_B
2) choose the same type of file (e.g: _fast.txt and _slow.txt)
3) Sort files to make all the files between ".doc", "_fast.txt" and "_slow.txt" the same. (e.g: file1.doc = file1_fast.txt = file1_slow.txt)
3) Open the files one by one
4) Extract info
5) Sort the info
6) compare
7) Print out the result (different & same)

DIR_B -> open DIR_B -> choose type of file -> sort files -> open the same name file -> extract info -> sort info -> compare -> print result



Is my concept of the whole script correct?


(This post was edited by AWHF on Jul 2, 2007, 7:27 PM)


KevinR
Veteran


Jul 2, 2007, 8:35 PM

Post #37 of 44 (3176 views)
Re: [AWHF] extract data... [In reply to] Can't Post

sounds good
-------------------------------------------------


AWHF
Novice

Jul 2, 2007, 8:55 PM

Post #38 of 44 (3175 views)
Re: [KevinR] extract data... [In reply to] Can't Post

so, this is layout of my script:



open DIR_A
sort files
{
open the same name file
{
extract info
{
sort info
}
}
}
Output A


open DIR_B
{
choose type of file (e.g: whether is _fast.txt or _slow.txt)
{
sort files
{
open the same name file
{
extract info
{
sort info
}
}
}
}
}
Output B
Compare Output A with Output B
{
print result
}





what do u think?
was it loop correctly?



(This post was edited by AWHF on Jul 2, 2007, 10:21 PM)


KevinR
Veteran


Jul 2, 2007, 9:32 PM

Post #39 of 44 (3173 views)
Re: [AWHF] extract data... [In reply to] Can't Post

Start writing real code and test as you go. You will get quick feedback about your programming logic that way. Wink
-------------------------------------------------


AWHF
Novice

Jul 3, 2007, 2:18 AM

Post #40 of 44 (3167 views)
Re: [KevinR] extract data... [In reply to] Can't Post


Code
#!/usr/bin/perl 
my $dir_A = "/eng/home/assignment/dir_A";
chdir($dir_A) || die "Can't chdir to $dirname: $!";
opendir(DIRA, $dir_A) || die "Can't open directory: $1";
my @docfiles = grep{/\.doc$/} readdir DIRA;
close DIRA;
@sortdoc = (sort @docfiles);open(FILE, $sortdoc);
while (<FILE>)
{
s/(\w+)/$1/;
if (/^::start/../^::end/)
{
push (@array, $1);
}
@sortdoc = (sort, @array);
}
my $dir_B = "/eng/home/assignment/dir_B";
chdir($dir_B) || die "Can't chdir to $dirname: $!";
opendir(DIRB, $dir_B) || die "Can't open directory: $1";
my @txtfilesfast = grep{/\_fast.txt$/} readdir DIRB;
my @txtfilesslow = grep{/\_slow.txt$/} readdir DIRB;
close DIRB;
@sortfiletxtfast = (sort @txtfilesfast);

open (FILE1, $txtfilesfast);
while ($line1 =<FILE1>)
{
if($line1 =~/name\((\w+\)/)
{
push (@array1, $line1);
}
@sorttxtfast = (sort, @array1);
}open (FILE2, $txtfilesslow);
while ($line2 =<FILE2>)
{
if($line2 =~/name\((\w+\)/)
{
push (@array2, $line2);
}
@sorttxtslow = (sort, @array2);
}


this is part of my script, but i haven't test because i don't know how to continue my script to do the comparison. can u help me? btw...is my script correct?


KevinR
Veteran


Jul 3, 2007, 10:19 AM

Post #41 of 44 (3158 views)
Re: [AWHF] extract data... [In reply to] Can't Post

How come you are not asking your teacher/professor/tutor these questions?
-------------------------------------------------


AWHF
Novice

Jul 3, 2007, 4:34 PM

Post #42 of 44 (3156 views)
Re: [KevinR] extract data... [In reply to] Can't Post

Actually i learn this PERL by my self. Non of my friends know PERL. I feel that PERL is very usefull espeacially for extraction process. So, i hope this forum will help me. And i hope u will guide me thru my learning process.Smile


KevinR
Veteran


Jul 3, 2007, 4:53 PM

Post #43 of 44 (3154 views)
Re: [AWHF] extract data... [In reply to] Can't Post

OK, well, I'm really not a very good teacher. I am a self taught perl coder myself and my education has some large gaps in it but I'll try and assist you.
-------------------------------------------------


AWHF
Novice

Jul 3, 2007, 4:57 PM

Post #44 of 44 (3153 views)
Re: [KevinR] extract data... [In reply to] Can't Post

Ok!Wink
So, i'm looking forward for your help for me to complete my 1st script.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives