Hi Lina, On Wed, Mar 14, 2012 at 10:15 AM, lina <lina.lastn...@gmail.com> wrote:
> Thanks all, here comes the update one: > > #!/usr/bin/env perl > > use strict; > use warnings; > use Carp qw(croak); > use autodie qw(open close); > use File::Basename; > > croak "Usage: ./bibextract.pl tex_file.tex" unless defined $ARGV[0]; > > my $infile = $ARGV[0]; > > my $tex_file = $infile; > #my $bib_filename = "/home/lina/texmf/bibtex/bib/biophymd.bib"; > my $bib_filename = "try.bib"; > my $bib_abbrev_filename = "/home/lina/texmf/bibtex/bib/biophyabbrev.bib"; > my $extracted_bib = "basename($infile).bib"; > my $cited; > my @citeditems; > my $item; > > > ## read all the cited items from .tex file and save it to $cited > open my $fh, '<', $tex_file; > while(<$fh>){ > if(/cite\{(\S+)\}/){ > use: if(/cite\{(.+?)\}/){ > #$cited = sprintf "%s\n",$1; > #$cited =~ tr/\,/\n/; ########### the problem is > here. it > failed to split this to different element in the array @citeditems. > #push(@citeditems,$cited); > use: push @citeditems,split/,/,$1; > } > } > close($fh); > > > ## read the .bib database and extract the cited out > open my $fh2, '<', $bib_filename; > > foreach $item (@citeditems){ > print $item; > #match($item); > #print "a\n"; > } > > sub match{ > my $reg = @_; > LINE: while(my $line = <$fh2>){ > > if ($line =~ m/$reg\,/ .. $line =~ /^\}$/){ ######## > thanks Tim and > David's suggestion in another thread. I rechecked it worked. > print $line; > #last; > } > > > } > } > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > > -- Tim