Generallstlisting package and Perl code

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
jannetta
Posts: 46
Joined: Mon Dec 22, 2008 12:59 pm

lstlisting package and Perl code

Post by jannetta »

Hi All

I have a slight problem. I am trying to include a Perl listing in my dissertation, but the $ in front of the variables seem to cause a problem. This is what I have in my LaTeX document:

Code: Select all

\lstset{language=Perl}
\lstset{commentstyle=\textit}
\lstset{frame=shadowbox, rulesepcolor=\color{gray}}
\begin{lstlisting}[numbers=left]

my $url = 
	'http://192.168.0.7:8080/POG/getINDI.jsp?zarefno=a1.';
use LWP::Simple;
my $content = get $url;
die "Couldn't get $url" unless defined $content;
print $content;
print "\n";
print "Length " + length($content)

\end{lstlisting}
Everything seems to compile okay, but ight at the end I get warning message:

Code: Select all

###  Warning: END group without type while waiting to end lstlisting.  ###
I managed to get rid of the problem by including an extra $ character just before the \end{lstlisting} line. However, I'm sure this is not the right way to do it and I now have an extra $ displayed in my code.

Thanks in advance to any helpers
Jannetta

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

lstlisting package and Perl code

Post by daleif »

I dont get any problems what so ever, but would you please post FULL minimal examples instead of sniplets. This works fine for me

Code: Select all

\documentclass{memoir}
\usepackage{listings,color}
\definecolor{gray}{gray}{0.8}
\lstset{language=Perl}
\lstset{commentstyle=\textit}
\lstset{frame=shadowbox, rulesepcolor=\color{gray}}
\begin{document}
\begin{lstlisting}[numbers=left]
  my $url =
       'http://192.168.0.7:8080/POG/getINDI.jsp?zarefno=a1.';
  use LWP::Simple;
  my $content = get $url;
  die "Couldn't get $url" unless defined $content;
  print $content;
  print "\n";
  print "Length " + length($content)

\end{lstlisting}
\end{document}
Using the following versions

Code: Select all

 *File List*
  memoir.cls    2009/02/06 v1.6180339e configurable book, report, article docum
ent class
   ifpdf.sty    2007/12/12 v1.6 Provides the ifpdf switch (HO)
 ifxetex.sty    2009/01/23 v0.5 Provides ifxetex conditional
ifluatex.sty    2007/12/12 v1.0 Provides the ifluatex switch (HO)
   mem10.clo    2008/01/30 v0.3 memoir class 10pt size option
mempatch.sty    2008/07/23 v6.0 Patches for memoir class v1.6180339
listings.sty    2007/02/22 1.4 (Carsten Heinz)
  keyval.sty    1999/03/16 v1.13 key=value parser (DPC)
 lstmisc.sty    2007/02/22 1.4 (Carsten Heinz)
listings.cfg    2007/02/22 1.4 listings configuration
   color.sty    2005/11/14 v1.0j Standard LaTeX Color (DPC)
   color.cfg    2007/01/18 v1.5 color configuration of teTeX/TeXLive
  pdftex.def    2008/09/08 v0.04l Graphics/color for pdfTeX
lstlang1.sty    2004/09/05 1.3 listings language file
supp-pdf.tex
  omscmr.fd    1999/05/25 v2.5h Standard LaTeX font definitions
jannetta
Posts: 46
Joined: Mon Dec 22, 2008 12:59 pm

lstlisting package and Perl code

Post by jannetta »

Here is my MWE. I have left the packages that I use for my dissertation in the pre-amble. I don't know if there might be clashes or whether there might be a specific order in which the packages should be loaded:

Code: Select all

\documentclass[a4paper,12pt]{report}
\usepackage[paper=a4paper,left=30mm,width=150mm,top=25mm,bottom=25mm]{geometry} 
\usepackage[cleanlook, english]{isodate} % for formatting the date of \today
\usepackage[round, authoryear]{natbib} % Use the natbib bibliography and citation package
\usepackage{bibtopic}
\usepackage{xcolor} % Driver-independent color extensions for LaTeX and pdfLaTeX.
\usepackage{hyperref} % For creating hyperlinks in the toc and references
\usepackage{verbatim}
\usepackage{listings} % This for inserting code listings
\usepackage{graphicx} % This is used to load images
\usepackage{pdfpages} % for inserting pages from other pdf documents
\usepackage{appendix} % For creating the appendices
\usepackage{makeidx} % For creating the glossary and index
\makeindex
\usepackage[style=altlist,toc]{glossaries}
\newglossaryentry{soc}{name={SOC},description={Service Oriented Computing, also known as SOA or Service Oriented Architecture, focuses on the development and integration of systems to provide business processes. The systems are packaged as interoperable services}}
\newglossaryentry{WWW}{name={WWW}, description={World Wide Web}}
\newglossaryentry{W3C}{name={W3C}, description={World Wide Web Consortium}}
\newglossaryentry{API}{name={API}, description={Application Programmer's Interface}}
\newglossaryentry{UnintendedConsequence}{name={Unintended consequence}, description={an outcome that was not inteneded in a particular situation.}}
\makeglossaries

\lstset{language=Perl}
\lstset{commentstyle=\textit}
\lstset{frame=shadowbox, rulesepcolor=\color{gray}}
\begin{document}
\bibliographystyle{plainnat}

\begin{titlepage}
\centering
\vspace*{11\baselineskip}
\large 
\bfseries
AMUSEMENTS IN MATHEMATICS\\
\normalfont
\small
Sub Title\\
\vfill
HENRY ERNEST DUDENEY\\
(student number)\\[2\baselineskip]
\textbf{\today}\\[2\baselineskip]
Word Count: {\color{red}\input{wordcount2.tex}}\\
\end{titlepage}

\begin{lstlisting}[numbers=left]

my $url =
   'http://192.168.0.7:8080/POG/getINDI.jsp?zarefno=a1.';
use LWP::Simple;
my $content = get $url;
die "Couldn't get $url" unless defined $content;
print $content;
print "\n";
print "Length " + length($content)

\end{lstlisting}
\end{document}
I downloaded and installed the latest listsings package and listing.sty. The problem still persists. If I take the $ out just before \end{lstlisting} I get warning messages. At this point you can't see the warning messages on screen or in the log file, but they are printed on the title page where the word count (in red) is suppose to go. I'll attached a copy of the produced document to show this.
Attachments
MWE.pdf
(39.03 KiB) Downloaded 488 times
daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Re: lstlisting package and Perl code

Post by daleif »

this is NOT a minimal example! Remove all packages that are not needed, remove all irrelevant text, and create an example that the rest of us can compile for our self, you input a file that we do not have. How is that wordcount file created? Where dis that come from?
jannetta
Posts: 46
Joined: Mon Dec 22, 2008 12:59 pm

Re: lstlisting package and Perl code

Post by jannetta »

I think I found the source of the problem. Thanks for you help though.
daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Re: lstlisting package and Perl code

Post by daleif »

then for the sake of the archives, could you tell us what the problem was?
Velocity
Posts: 1
Joined: Thu Apr 22, 2010 11:49 am

lstlisting package and Perl code

Post by Velocity »

I found this page on google since I was trying to find the answer to this question too, but thought since I found the solution I would post it since jannetta didn't bother.

You need to specify where you are describing comments within your code. e.g.

Code: Select all

escapeinside={\#*}{*)} % if you want to add a comment within your code
Post Reply