This way works: ## read the .bib database and extract the cited out
foreach $item (@citeditems){ match($item); } sub match{ open my $fh2, '<', $bib_filename; LINE: while(my $line = <$fh2>){ if ($line =~ m/@_\,/ .. $line =~ /^\}$/){ print $line; #last; } } close($fh2); } but when I used the sub match{ my $reg = @_; if ($line =~ m/$reg\,/ .. $line =~ /^\}$/){ not works. do you know why? Thanks, On Wed, Mar 14, 2012 at 6:10 PM, lina <lina.lastn...@gmail.com> wrote: > ## read the .bib database and extract the cited out > open my $fh2, '<', $bib_filename; > > foreach $item (@citeditems){ > match($item); > } > > sub match{ > my $reg = @_; > LINE: while(my $line = <$fh2>){ > > if ($line =~ m/$reg\,/ .. $line =~ /^\}$/){ > print $line; > #last; > } > > > } > } > > > **** OUTPUT ******* > $ ./bibextract.pl sample.tex > @Article{ dehydron1, > title = "", > author = "G. E. and A. Wedemann", > journal = PEPT, > pages = "128-127", > volume = "2", > number = "9", > month = "Jul", > year = "2001" > } > > > It supposed to be > > **************************** > @Article{ dehydron, > author = "L. F. Benoit and A. B. C", > title = "", > year = "2011", > journal = JPCHEMB, > volume = "15", > number = "2", > pages = "247-156", > doi = "10.1/jp65985" > } > > @Article{ dehydron1, > title = "", > author = "G. E. and A. Wedemann", > journal = PEPT, > pages = "128-127", > volume = "2", > number = "9", > month = "Jul", > year = "2001" > } > > @Article{ inhibitorAromaticDirect, > title = "", > author = "J. Hardy and D. J. Selkoe", > journal = SCIEN, > pages = "35-56", > volume = "29", > number = "580", > month = "Jul", > year = "2030" > } > > > ****************************** > > not only the middle one, > > do you think I should re-open the file every time in match, > > Thanks again with best regards, -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/