我在从 Windows 系统获取用户名时遇到问题。我尝试在 perl 中使用 getlogin 函数并打印出我的用户名,但我的问题是如何在模板工具包中访问此用户名。我试过这样
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
use XML::Simple;
use Template;
my $username = getlogin || getpwuid($<) || "veeru";
my $xml = new XML::Simple;
my $data = $xml->XMLin("data.xml", ForceArray=>['dat','employee','experience']);
print $username;
my $template = Template->new();
my $filename = 'output1.tex';
$template->process(\*DATA, $data, $filename)
|| die "Template process failed: ", $template->error(), "\n";
system( "pdflatex $filename" );
__DATA__
\documentclass[a4paper,leqno,twoside]{article}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\begin{document}
Issued by {Name}
\issuedby{ [% username %] }
% Document title. Use \doctitleShort{} to insert a shorter title in the header.
\doctitle{employee information of thie"scr"company}
\doctitleShort{\@doctitle}
[% FOREACH comp IN company %]
[% comp.name %]
[% comp.location%]
employeedata:
[% FOREACH employee IN comp.domain.java.employee %]
[% employee.name %][% employee.number %]
[% FOREACH obj IN data%]
[% FOREACH beha IN obj.employee %]
[% IF beha.number == employee.number && beha.name == employee.name %]
[% beha.address %],
[% LAST %]
[% END %]
[% END %]
[% END %]
[% END %]
[% END %]
[% END %]
\end{document}
但它没有在 pdf 中打印用户名,它在控制台上打印用户名,所以我在模板过程中访问用户名变量时犯了错误。请告诉我如何在模板中使用该用户名变量,如何在 pdf 中打印。
我的第二个问题是
\doctitle{employee information of thie"scr"company}
在上面的行中文档标题是在模板过程中编写的,我需要从 perl 代码访问标题如何执行此操作。任何人都可以帮助我,因为这是我第一次使用模板过程。