Hi lina,

On Sun, 4 Mar 2012 00:37:58 +0800
lina <lina.lastn...@gmail.com> wrote:

> Hi,
> 
> I want to output the result into the file shared the same basename but
> different extensions,
> 
> Below is what I have come up so far:
> 
> perl try.tex
> 
> #!/usr/bin/env perl
> 
> use strict;
> use warnings;
> use File::Basename;
> 

That's good so far.

> 
> my $bib_filename = "/home/lina/texmf/bibtex/bib/biophymd.bib";
> my $bib_abbrev_filename ="/home/lina/texmf/bibtex/bib/biophyabbrev.bib"
> 

You're missing a trailing semicolon (";") here. 

> open my $bib_abbrev, '<', $bib_abbrev_filename
> 

And here.

> my $bib_output, '>', "basename($ARGV[0]).bib"
> 

Perl won't interpolate function calls inside double-quotes. You can do:

open my $bib_output, '>', basename($filename) . ".bib"
        or die "Foo bar. $!";

You can also do "@{[basename($filename)]}.bib" (using the "Turtle operator"
mentioned here - http://www.catonmat.net/blog/secret-perl-operators/ - but this
is clunky. 

You've also missed the open and the trailing ";" again.

> ### here the ARGV[0] is try.tex, so the output filename is try.bib.
> 
> my %dict;
> 
> 
> my $tex_filename = $ARGV[0] ;
> 

You're mentioning $ARGV[0] twice in this script. You should assign it to a
variable once and use it instead. Also see:

http://perl-begin.org/tutorials/bad-elements/#subroutine-arguments

> open my $file, '<', $tex_filename or die "Can't open $tex_filename:$!";
> 

It is possible that here ":" will be considered as part of the variable name,
because Perl uses "::" as a namespace separator. So you should write
${tex_filename} instead to delimit it.

I also dislike calling variables "file" because it can refer to a file handle,
a file name, the file contents or whatever.

> while (my $line = <$file>) {
>       if($line =~ m/cite\{(\S+)\}/g) {
>       print $1,"\n";

Here it is better to do if (my ($match_substring) =~ m/cite\{(\S+)\}/)) because
$1 can easily be clobbered (see Perl Best Practices about it). Why are you
using /g here?

Regards,

        Shlomi Fish


-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Best Introductory Programming Language - http://shlom.in/intro-lang

Beliefs are what divide people. Doubt unites them.
    — http://en.wikiquote.org/wiki/Peter_Ustinov

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to