Ask a Question related to PERL Beginners, Design and Development.
-
Lonewolf #1
Script to parse files
I've been working with this since wolf and jeff and john sent me some stuff,
I think I actually based everything on wolf's code excerpts. I'm sure my
final code is going to not be perfect, but at least I have the piece of mind
of knowing that I can get this thing some better then it was. I'm still not
sure on making it a sub that I can use on anything, but I'll deal with that
issue another day.
Robert
Lonewolf Guest
-
Make this into a script to parse?
I'm back to dealing with the main issue of a badly formatted file being brought down from an archaic system and needing to be cleaned up before... -
Unable to parse and process php files
Hello, Just installed Apache and PHP. Edited the .conf file for the appropariate addtype lines, and Apache itself is working. However, when I... -
How to parse large script faster
I've created a perl script automatically based on an ini file (we want to replace the ini file holding a number of rules by regular expressions in... -
Library to parse mail files
Hi, What would be that best library/module for parsing a mail file. I want to be able to extract the values for header tags as well as the... -
How to use .htaccess to parse only .html files as .php?
***newbie question*** Hi, I am trying to make my server (Apache) parse .html files as .php. I found this line of code: ForceType... -
Wolf Blaum #2
Re: Script to parse files
For Quality purpouses, LoneWolf 's mail on Friday 06 February 2004 16:57 may
have been monitored or recorded as:easy: (notice: thats the same script as priviously but has the parse in a> I've been working with this since wolf and jeff and john sent me some
> stuff, I think I actually based everything on wolf's code excerpts. I'm
> sure my final code is going to not be perfect, but at least I have the
> piece of mind of knowing that I can get this thing some better then it was.
> I'm still not sure on making it a sub that I can use on anything, but I'll
> deal with that issue another day.
sub:)
---snip---
#!/usr/bin/perl
use strict;
use warnings;
my (@fields, $lng);
sub whatever {
if (@_) {
foreach my $infile (@_) {
* my ($i,$rec);
* open INFILE, "$infile" or die "Can't open $infile: $!";
* open OUTFILE, "${infile}.out" or die "Can't open ${infile}.out at home:
$!";
* while (<INFILE>) {
* *$rec++;
* *chomp;
* *@fields = split /\s*\|\s*/, $_;
* *$fields[0] =~ s/^\s+//;
* *#there is probably a way to get rid of the trailing spaces in the first
entry using split,I just couldnt think of any.
* *$lng = @fields unless $lng; #set $lng for first record
* *print "The following record: $i has ", scalar @fields, " fields as compared
to $lng fields in the first record! Skip. : $_\n" and next unless $lng ==
@fields;
#poor quality control of your input data: check if all reords have the same
number of fields or skip and print record otherwise.
* *$i++;
* *print OUTFILE $i;
* *print OUTFILE "|$_" foreach (@fields);
* *print OUTFILE "|$fields[0]\n"; #your trailing ID
* }
* close INFILE;
* close OUTFILE;
* print "Read $rec records from ./sql/$infile and printed $i into ./
${infile}.out\n";
} #end foreach
return 1;
}
else {return undef;}
} #end sub whatever
---snap---
call it with &whatever('path/to/firstfile', 'path/to/secondfile',...)
Enjoy, Wolf
Wolf Blaum Guest
-
Wolf Blaum #3
Re: Script to parse files
For Quality purpouses, wolf blaum 's mail on Friday 06 February 2004 20:15 may
have been monitored or recorded as:
> easy: (notice: thats the same script as priviously but has the parse in a
> sub:)
>
> ---snip---
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> my (@fields, $lng);
.... and that my (@fields, $lng); belings in the sub....
wolf
Wolf Blaum Guest



Reply With Quote

