develooper Front page | perl.beginners | Postings from March 2012

How to end a loop

Thread Next
From:
lina
Date:
March 13, 2012 22:38
Subject:
How to end a loop
Message ID:
CAG9cJmnoTkYekp4CZhRZoZAkgN_LbEU0eCY63KBXA=VMstnJ6A@mail.gmail.com
Hi,

here is the on-going script.

#!/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_abbrev_filename = "/home/lina/texmf/bibtex/bib/biophyabbrev.bib";
my $extracted_bib = "basename($infile).bib";
my $cited;
## read all the cited items from .tex file and save it to $cited
open my $fh, '<', $tex_file;
while(<$fh>){
	if(/cite\{(\S+)\}/){
		$cited = sprintf "%s\n",$1;
		$cited =~ tr/\,/\n/;
		print $cited;
	}
}
close($fh);
## read the .bib database and extract the cited out

open my $fh2, '<', $bib_filename;


####### Here I don't know how to end the while loop.
while($cited){
	while(my $line = <$fh2>){
		print $line;
		#if ($line =~ $cited){
		#	print $line;
		#}
	}
	
}

$ more sample.tex
aaa\cite{dehydron,dehydron1},ddd
bbb\cite\cite{inhibitorAromaticDirect}aaa


Thanks for your suggestions,

Best regards,

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About