Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert this shell script to perl?

Status
Not open for further replies.

fz315

Programmer
Oct 29, 2004
6
CA
#!/bin/sh

# time between each screen
refresh_timeout=5

# location of screens
home_dir=screens

# temp runtime file for tracking current screen
cntfile=/var/cnt

# if no cntfile (e.g. when starting) default to #1
if [ -f $cntfile ]; then
cnt=`cat $cntfile`
else
cnt=1
fi

# wrap when we run out
if [ ! -f ../$home_dir/$cnt.jpg ]; then
cnt=1
fi

# html stuff
echo "Content-type: text/html"
echo ""
echo "<HTML>"
echo "<HEAD>"
echo "<TITLE>Slideshow</TITLE>"
echo "<meta http-equiv=\"Refresh\" Content=\"$refresh_timeout; URL=/cgi-bin/display.sh\">"
echo "</HEAD>"
echo "<BODY bgcolor=\"#ffffff\" text=\"#ffffff\">"
echo "<a href=\"/cgi-bin/print.sh\"><img align=\"left\" img border=\"0\" img src=\"/$home_dir/$cnt.jpg\"</a>"
echo "</BODY></HTML>"

# point to next screen
let cnt="$cnt+1"
echo $cnt > $cntfile
 
learning perl might be a start

instead of echo, use print
if ($this="that") {
do_this;
} else {
do_that;
}

HTH
--Paul

Nancy Griffith - songstress extraordinaire,
and composer of the snipers anthem "From a distance ...
 
I recommend to start reading the perl basic structures and syntax:

a) Declaring Variables:

$cntfile="/var/cnt";

b) Checking if it is a directory:

if (-d directory_name) {
do this;{
}else{
do_something_else;
}

Cheers and Good Luck

c) Printing values:

print "What I want to print\n"


c) Checking if it is a files:

if ( -f file_name) {do this;{
}else{
do_something_else;
}






 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top