Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi there, Monks!
Is there a way of printing to the browser the CVS Version of a file? I am working with this code here, but it is not working well, the file is under CVS but it can display the file current CVS Version to the screen, any help?

#!/perl/bin/perl print "Content-type: text/html\n\n\n\n"; ### Get the name of the file being requested. #my $Temp = $ENV{'REQUEST_URI'}; my $Temp = "../dcheck.pl"; my $Cvs = $Temp; ### Split the url by "/". my (@Junk) = split(/\//, $Cvs); ### Get the end of the url, which is the filename. my $File = pop @Junk; $Cvs =~ s/[^\/]+$//g; ### Attach the document root directory so we get the complete path t +o the ### file on our computer server. Also, attach the CVS/Entries name s +o that ### we get the CVS information. $Cvs = $ENV{'DOCUMENT_ROOT'} . $Cvs . "CVS/Entries"; ### Open the file, and if we find a match, record it to $Match my $Match = ""; open(FILE,$Cvs); while (my $Line = <FILE>) { if ($Line =~ /$File/) {$Match = $Line; chomp $Line} } close FILE; ### If match is not found, print not found, otherwise get the infor +mation. if ($Match eq "") {print "No CVS information found. '$File'\n";} else { ### Get the information we want and print it out. my ($Junk,$File,$Version,$Date,@Junk) = split(/\//, $Match); print "Version <b>$Version</b> : Date Last Changed <b>$Date</b>\n"; }


Thank you all!

Replies are listed 'Best First'.
Re: CVS Version of a File
by planetscape (Chancellor) on Jul 06, 2006 at 20:13 UTC
Re: CVS Version of a File
by starbolin (Hermit) on Jul 07, 2006 at 07:01 UTC

    You definately need:

    use warnings; use strict;

    If your one line:

    my $Temp = "../dcheck.pl";

    returns undef then without warnings your progam will silently fail yet still produce output.

    s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}