Text Formattingcan`t write some programming code

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
bci24sg22
Posts: 4
Joined: Sun Mar 22, 2009 4:42 am

can`t write some programming code

Post by bci24sg22 »

I have some problem writing some perl text code in latex. The original text is this:

Code: Select all



#!/usr/bin/perl -w
use Time::Local;
my $AMANDA='amandabackup';
$AMANDA_HOME = (getpwnam($AMANDA) )[7] || die "Cannot find $AMANDA home directory\n" ;
$AM_PASS = "$AMANDA_HOME/.am_passphrase";
$ENV{'PATH'} = '/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin';
$ENV{'GNUPGHOME'} = "$AMANDA_HOME/.gnupg";
sub encrypt() {
   system "gpg --batch --disable-mdc --symmetric --cipher-algo AES256 --passphrase-fd 3  3<$AM_PASS";}
sub decrypt() {
    system "gpg --batch --quiet --no-mdc-warning --decrypt --passphrase-fd 3  3<$AM_PASS";
}
if ( $#ARGV > 0 ) {
    die "Usage: $0 [-d]\n";
}
if ( $#ARGV==0 && $ARGV[0] eq "-d" ) {
   decrypt();
}
else {
   encrypt();
}
and i have write it like this:

Code: Select all

\begin{flushleft}
\texttt{\#!/usr/bin/perl -w} \\
\texttt{use Time::Local;} \\
\texttt{my \$AMANDA='amandabackup';} \\
\texttt{\$AMANDA\_HOME = (getpwnam(\$AMANDA) )[7] || die "Cannot find \$AMANDA home directory\backslash n" ;} \\
\texttt{\$AM\_PASS = "\$AMANDA\_HOME/.am\_passphrase";} \\
\texttt{\$ENV{'PATH'} = '/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin';} \\
\texttt{\$ENV{'GNUPGHOME'} = "\$AMANDA\_HOME/.gnupg";} \\
\texttt{sub encrypt() \{ } \\
\texttt{   system "gpg $--$batch $--$disable-mdc $--$symmetric $--$cipher-algo AES256 $--$passphrase-fd 3  3<\$AM\_PASS";} } \\
\texttt{sub decrypt() \{ } \\
\texttt{    system "gpg $--$batch $--$quiet $--$no-mdc-warning $--$decrypt $--$passphrase-fd 3  3<\$AM\_PASS"; } \\
\texttt{\} } \\
\texttt{if ( \$\#ARGV > 0 ) \{ } \\
\texttt{    die "Usage: \$0 [-d]\backslash n";} \\
\texttt{\} } \\
\texttt{if ( \$\#ARGV==0 && \$ARGV[0] eq "-d" ) \{ } \\
\texttt{   decrypt();} \\
\texttt{\}}
\texttt{else \{ } \\
\texttt{   encrypt();} \\
\texttt{ \} } 
\end{flushleft}
Please tell me what i am wrong here....i have got some errors. And another thing....how can insert these spaces?

Code: Select all

class temp 
{
     \\this kind of space
}
Last edited by bci24sg22 on Tue Apr 07, 2009 4:13 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

can`t write some programming code

Post by gmedina »

Hi,

you can use the listings package. Refer to the package documentation for further information.

A little example, using your code:

Code: Select all

\documentclass{article}
\usepackage{listings}

\lstset{language=Perl,breaklines=true}

\begin{document}

\begin{lstlisting}
#!/usr/bin/perl -w
use Time::Local;
my $AMANDA='amandabackup';
$AMANDA_HOME = (getpwnam($AMANDA) )[7] || die "Cannot find $AMANDA home directory\n" ;
$AM_PASS = "$AMANDA_HOME/.am_passphrase";
$ENV{'PATH'} = '/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin';
$ENV{'GNUPGHOME'} = "$AMANDA_HOME/.gnupg";
sub encrypt() {
   system "gpg --batch --disable-mdc --symmetric --cipher-algo AES256 --passphrase-fd 3  3<$AM_PASS";}
sub decrypt() {
    system "gpg --batch --quiet --no-mdc-warning --decrypt --passphrase-fd 3  3<$AM_PASS";
}
if ( $#ARGV > 0 ) {
    die "Usage: $0 [-d]\n";
}
if ( $#ARGV==0 && $ARGV[0] eq "-d" ) {
   decrypt();
}
else {
   encrypt();
}
\end{lstlisting}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
bci24sg22
Posts: 4
Joined: Sun Mar 22, 2009 4:42 am

Re: can`t write some programming code

Post by bci24sg22 »

thanx a lot man! ;)
Post Reply