$ perl extract_v2.pl try.tex
Useless use of a constant (<) in void context at extract_v2.pl line 25.
Useless use of private variable in void context at extract_v2.pl line 25.
metabolism
toxic2
toxic4
#!/usr/bin/env perl
use strict;
use warnings;
use File::Spec;
use File::Basename;
my $INPUTFILE = $ARGV[0];
my $tex_filename = $INPUTFILE;
my $bib_filename = "/home/lina/texmf/bibtex/bib/biophymd.bib";
my $bib_abbrev_filename = "/home/lina/texmf/bibtex/bib/biophyabbrev.bib";
# divide the input file name into its path and name,
# ignore its extension
my ($name, $path) = fileparse($tex_filename, qr/\.[^\.]+$/);
# create a new name with .bib extension
my $output_bib_filename = File::Spec->catfile($path,"$name.bib");
# Read bib_abbrevation file
open my $bib_output, '<', $bib_abbrev_filename;
(^^^^^^^^^^^^^^ here I wish to read the bib-abbrevation first into
bib_out, namely try.bib and then search the bib_filename (database)
for the enerties showed in the try.tex.)
open $bib_output, '>', $output_bib_filename
or die "Could not write $output_bib_filename:$!\n";
open my $texfile, '<', $tex_filename or die "Can't open ${tex_filename}:$!";
while (my $line = <$texfile>) {
if( $line =~ m/cite\{(\S+)\}/g) {
my $match_entry = $1 ;
print $match_entry,"\n";
}
}
$ more try.tex
bbbbb
aaaa \cite{metabolism}
ccc \cite{toxic2}
EEE \cite{toxic4}
ddd cite not
Thanks with best regards,
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/