You need to post some code and sample data; otherwise it's going to be very hard for anyone to help you. | [reply] |
PC025
A
A
TELCO LEFT HAND SIDE
J0007
RJ45 EARLESS
N/A
N/A
N/A
N/A
50 WAY MOUNT CONNECTOR FEMALE BT009
PC026
A
A
TELCO RIGHT HAND SIDE
J0007
RJ45 EARLESS
N/A
N/A
N/A
N/A
50 WAY MOUNT CONNECTOR FEMALE BT009
PC029
A
A
TELCO LEFT HAND SIDE
J0007
RJ45 EARLESS
N/A
N/A
N/A
N/A
50 WAY MOUNT CONNECTOR MALE BT010
And this is what I have come up with in the form of code...please don't laugh...hehe!!!:
open (DATFILE, "prod.dat") or die "I couldn't get at log.txt";
for $line (<DATFILE>) {
print "$line <br>";
}
close DATFILE;
I know it don't look much but the books I have referenced don't seem to help, and there is noone else I know with any perl knowledge.
Hope this makes things a bit clearer
Thanks
2001-11-06 Edit by Corion : Changed formatting to use opening and closing CODE tags | [reply] [d/l] [select] |
So you are already halfway. You just need to plough in a few online docs. Try (at the commandline) 'perldoc perlop', and perlre for searching/replacing, and 'perldoc perlrun' for nifty commandline switches -- be sure to look up -i and -p. Oh yeah, don't forget to read all about ARGV in perlvar.
| [reply] |
Well, you're reading in the data file, and spitting out some HTML; that's a good start. I agree with jeroenes that you need to read some documentation. You definitely need to look at the basics though: perldata, perlsyn,
perlfunc,
and perlop. You might also try the books, Learning Perl (beginner-oriented) and Programming Perl (much steeper learning curve, but good if you've programmed before). This will all seem overwhelming and give you a headache at first, but once you've been over it a few times, you'll be much better equipped to solve problems in perl.
Now then, your .DAT file's format, with no distinction between record separator and field separator (i.e. each field is on a separate line) doesn't mix very well with line-oriented data processing, which is what most of those perl tutorials are going to talk about. If I were you, I would try to convert the .DAT file into a tab-delimited fields format (it doesn't look like your data will have any tabs in it, so this should be safe). If you can't do that to the external file, you can still convert it for use internally by your perl program:
#!/usr/bin/perl -w
use strict ;
my $filename = 'sample.dat' ;
open (DATAFILE, "<$filename")
or die "$0: cannot open file \"$filename\" for reading: $!\n" ;
my (@record, @records) ;
while (<DATAFILE>) {
tr/\r\n//d ;
push @record, $_ ;
if (@record == 11) {
push @records, join ("\t", @record) ;
@record = () ;
}
}
close (DATAFILE) ;
die "$0: incomplete record (line count = ", scalar @record, ") at end
+of file \"$filename.\"\n"
unless @record == 0 ;
This code snippet will read each group of 11 lines into an array (@record), then convert it to a single tab-delimited line and add it to the array @records. At the end, @records will contain your entire file in tab-delimited format. Now that the program has an internal copy of your file in a sensible format, it's easy to do fun things with it, like print it all out (print map {"$_\n"} @records) or search through it looking for keywords (print map {"$_\n"} grep /\Q$keyword\E/, @records). To understand all of this, look up grep and map in perlfunc, and read some of that other material people have posted for you.
Anyway, I hope this is enough to get you started. If you have any more specific questions, be sure to post them, or create an account and ask in the Chatterbox. | [reply] [d/l] [select] |
can I have your job?
But seriously, have you checked into the substr function? | [reply] |
Errr, I agree with the other in that you need some sample code; but I feel you are trying too hard in the first place. Do you have access to a database or will you have to write these to disk? You can use the integral search functions on a record, then :). | [reply] |
Wow BlackMateria, you are a star, it works a treat and I have read up on all the bits and understand now how it works!! Thankyou so much.
Now I have another query...if you can help me out on this one I would be forever in your debt!
I now need to run a HTML search which asks for a keyword which will then open up my new perl script and display the results in HTML. At the moment I put a peice of data in $keyword and it finds all the records when I run the script, but how do I get the HTML to overwrite that keyword so it can change everytime the need a different search?
Hope that makes sense!!
So in essense with everything put together, a person gets a HTML page which asks what the would like to search for, they put in a keyword, the result is then shown on a html for that particular file.
Cheers
Jason | [reply] |
Check out
CGI.pm and
friends on CPAN. Documentation for CGI.pm can be found here, among other places. Hope this helps!
| [reply] |