Hello,
There are a few problems in the program you included. First is the use
of split outside the loop which is not what you want. Second is using
the /.?/ expression to test the length of the field where you should've
used the "length" function.
I guess what you needed was a way to add the document_number(s)
sequentially until your list of document_number(s) is exhausted or your
input is depleted. So, let's try to see how your program can be fixed:
use strict;
use Text::Wrap;
my @doc_num= qw (000030004 000030067 000030068 000030079 000030148
000030294 000030319 000030454 000031100 000031125 000031131 000031140
000031410);
$doc_num_ref = \@doc_num; ### do you really need this anywhere?
###my($author,$title,$publisher,$notes,$abstract)=split /\|/,$_;
### die, don't warn
open (IN,"<l:/intext.txt") or die "Cannot find specified file: $!\n";
open (OUT,">c:/outtxt.txt") or die "Cannot create specified file: $!\n";
my @fields = qw/TI PU NT ABST/;
select (OUT);
while (<IN>){
print "*** DOCUMENT BOUNDARY ***\n";
#&doc_num;
### I guess you want your doc_num here
print shift(@doc_num) . "\n"; ### consult perldoc -f shift
my ($auth,@bib) = split /\|/; ### this bib item contains
### title,publisher,notes,abstract
### $auth is the first item in the list
my @authors = split /;\s*/, $auth;
### split on semicolon folowed by any number of spaces.
for(@authors){
print "..AU:\n",wrap(" ","",$_),"\n";
}
for my $i (0..3){
print "..$fields[$i]:\n", wrap(" ","",$bib[$i]), "\n";
}
## if ($title =~ (/.$/)){
## print "..TI:\n",wrap(" ","","$title"),"\n"; }
## if ($publisher =~ (/.$/)){
## print "..PU:\n",wrap(" ","","$publisher"),"\n"; }
## if ($notes =~ (/.$/)){
## print "..NT:\n",wrap(" ","","$notes"),"\n"; }
## if ($abstract =~ (/.$/)){
## print "..ABST:\n",wrap(" ","","$abstract"); }
}
close (IN);
close (OUT);
##sub multi_authors{
## $author =~ s/;\s+/;/mg;
## @authors = split /;/,$author;
## foreach $author(@authors){
## print "..AU:\n",wrap(" ","","$author"),"\n";
## }
##
##}
I hope this helps,,,
Aziz,,,
In article <[EMAIL PROTECTED]>, "Rashid Faraby"
<[EMAIL PROTECTED]> wrote:
> Hi Folks,
>
> I've been struggling with this for a couple of hours this morning and it
> seems like I'll need some help from the pros. I have a long file
> consisting of document numbers. I would like to insert sequentially a
> number into records saved in another file I am data munging through a
> while loop. The problem I am faced with is how to instruct the code to
> insert a single array element and remember where it left off. For
> instance,
> during the first run, it'll get no 000030004 and insert it in record A,
> then no 000030067 for record B, etc. I believe I have to use splice
> (splice @array (0,1)), or do ?
>
> I am including a simplified version of my code here for your review.
> The defective code is commented. Your help is very much appreciated.
>
>
>
> use strict;
> use Text::Wrap;
>
> my @doc_num= qw (000030004 000030067 000030068 000030079 000030148
> 000030294 000030319 000030454 000031100 000031125 000031131 000031140
> 000031410);
> $doc_num_ref = \@doc_num;
>
> my($author,$title,$publisher,$notes,$abstract)=split /\|/,$_;
>
> open (IN,"<l:/intext.txt") or warn "Cannot find specified file: $!\n";
> open (OUT,">c:/outtxt.txt") or warn "Cannot create specified file:
> $!\n";
>
> select (OUT);
> while (<IN>){
>
> print "*** DOCUMENT BOUNDARY ***\n";
> #&doc_num;
> if ($author =~ (/.$/)){
> &multi_authors;
> }
> if ($title =~ (/.$/)){
> print "..TI:\n",wrap(" ","","$title"),"\n"; }
> if ($publisher =~ (/.$/)){
> print "..PU:\n",wrap(" ","","$publisher"),"\n"; }
> if ($notes =~ (/.$/)){
> print "..NT:\n",wrap(" ","","$notes"),"\n"; }
> if ($abstract =~ (/.$/)){
> print "..ABST:\n",wrap(" ","","$abstract"); }
> }
> close (IN);
> close (OUT);
>
> sub multi_authors{
> $author =~ s/;\s+/;/mg;
> @authors = split /;/,$author;
> foreach $author(@authors){
> print "..AU:\n",wrap(" ","","$author"),"\n";
> }
>
> }
>
>
>
>
> #sub doc_num{
>
> #foreach $doc_num (@$doc_num) {
> # print "..Document-Number: $doc_num\n"; #}
> #}
>
>
> __END__;
> _______________________________________________________ The American
> Occupational Therapy Foundation (AOTF) Creating Opportunities through
> Research and Education http://www.aotf.org
> 301.652.2682
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]