Re: regex help please
- From: "Jerry" <jpreston@xxxxxxxxxxxxxxxxx>
- Date: Thu, 28 Dec 2006 15:05:34 -0600
OK!
#!/perl
use strict;
local( *FI, *FO );
my $DEBUG = 10;
my $DEBUG1 = 0;
my $work_path = "C:\\Documents and Settings\\Jerry\\My Documents";
my @Form_files = ();
my %Form_data = ();
my $screen_cnt = 0;
## read dir where files exist and get only the file we are interested in
opendir( DIR, $work_path );
@Form_files = grep( /^PAS/,/DFM/, readdir( DIR ));
print "$#Form_files\n" if $DEBUG1;
print "@Form_files\n" if $DEBUG1;
## sort filies
print "@Form_files\n" if $DEBUG1;
@Form_files = sort { $a cmp $b } @Form_files;
print "\n\n@Form_files\n\n" if $DEBUG;
## start of breaking down of form files
foreach my $form_file ( @Form_files ) {
open ( FI, "$work_path\\$form_file" ) or die "Couldn't open
$work_path\\$form_file";
my @text = <FI>;
close FI;
$form_file =~ s/DFM/FDT/; # swap out file ext DFM to FDT -> Form Data
# print "opf - $form_file\n";
## find GENERALto find screen title
my $cnt = -1;
foreach ( @text ) {
## break out be screen #, exp: '(Screen 2)'
print $screen_cnt++ if $_ =~ /\(Screen /i;
print "$screen_cnt screen $_!!" if $_ =~ /\(Screen /i;
$cnt++;
print "cnt $cnt - $form_file - $_";
next if $_ !~ /GENERAL/i;
last;
}
# open ( FO, ">+$work_path\\$form_file" ) or die "Couldn't create
$work_path\\$form_file";
# print FO "$_";
print "\n\n$cnt - $text[ $cnt ] - $_\n\n";
print "\n\njp $cnt+1 - $text[ $cnt+1 ] - $_\n\n";
## get form title and print it
$cnt++;
print "\n\n$cnt - $text[ $cnt ] - $_\n\n";
$cnt++;
# Emp# EmpStatus MStatus BeganEmp EndedEmp
foreach ( $cnt...$#text ) {
$_ = $text[ $_ ];
/(\w+)\s+/g;
print "parm: *1 $1*2 $2*3 $3*4 $4*6 $6*7 $7*8
$8*$9*$10*$11*$12*$_*<br>\n";
print "$form_file - $_";
print $_+'\n';
# exit;
}
# close( FO );
exit;
close( FI );
}
Jerry
"Paul Lalli" <mritty@xxxxxxxxx> wrote in message
news:1167339165.614399.257270@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Jerry wrote:
It has been a while that I have done any regex. What I am trying to do
is
break down a string like the following:
my $_ = " Emp# EmpStatus MStatus BeganEmp
EndedEmp";
$_ cannot be lexicalized. Please post real code. Have you read the
posting guidelines that are posted here twice a week? They contain
invaluable information on how to create a good posting that is likely
to be answered.
I do not know many words will be in $_ or if there will be spaces at the
front of $_ or not.
Along the getting the words, I need to get all the spaces as a word
between
the words and at the end as well.
I don't have a clue what this means. What does "all the spaces as a
word between the words" mean? Please post desired output along with
your sample input. This is another thing that's in those guidelines.
I have started with:
/\s+(\w+)\s+/g;
print "parm: *1 $1*2 $2*3 $3*4 $4*6 $6*7 $7*8
$8*$9*$10*$11*$12*$_*<br>\n" ;
And how does the result of this do or not do what you want? Please
post actual output along with desired output and sample input. Again,
this is in the posting guidelines.
As a hunch, I'd say you want to use the split function, splitting on
whitespace, and capturing the delimiter with parentheses, so that the
delimiters are also returned. See
perldoc -f split
And then create a short-but-complete script that demonstrates your best
attempt, along with sample input and output that demonstrates what you
want, what you got, and how they differ.
Paul Lalli
.
- Follow-Ups:
- Re: regex help please
- From: Uri Guttman
- Re: regex help please
- References:
- regex help please
- From: Jerry
- Re: regex help please
- From: Paul Lalli
- regex help please
- Prev by Date: Re: regex help please
- Next by Date: Re: FAQ 5.2 How do I change, delete, or insert a line in a file, or append to the beginning of a file?
- Previous by thread: Re: regex help please
- Next by thread: Re: regex help please
- Index(es):
Relevant Pages
|