Dummy perl programming question

L

lonelyplanet999

Hi,

I'm a newbie to perl and is now studying about perl programming, I
read some perl programming tutorials online (enter 'Perl tutorial' at
google.com) and also find some sample perl scripts for study.

For below statements I couldn't understand what is the function of
'$in'. I tried to search through the perl script tutorial pages since
this morning (now it's afternoon) but still couldn't find the
explanation. Could anyone help what's the meaning or where to find url
with explanation of such syntax ?

1. $index=$in{ind} if($in{ind});
2. $startfile=$in{startfile};

I couldn't ask the script author as he stated in the script the script
will not be supported.

Tks!

#!/usr/local/bin/perl
##################################################################################
# WEBSITE KEYWORD SEARCH
# (c) Global Data Industries
# www.gd-ind.com
#
# This script is freeware and may be freely distributed but must not
be sold.
# e-mail support for the script is unfortunately not available,
although please
# e-mail bug fixes/enhancements to myself at (e-mail address removed) :)
#
# sitesearch.pl allows a web site to be searched against keywords or
"" enclosed
# phrases. A + in front of the word/phrase means that this word/phrase
is
# required, a - means that this word/phrase must not appear in any of
the returned
# links.
# The script requires a filename as the 1st search file, it will then
recursively
# follow all the HTML hyperlinks on the page, allowing "whole site or
this section
# only" searching to be performed.
# Returned links are sorted for confidence.
#
# Your form needs to pass 2 things: a Text Box called "keywords", e.g.
# <INPUT TYPE="TEXT" NAME="keywords"> and a input field, (can be a
hidden, radio
# or textbox) with the file name to start the search from, called
"startfile"
# e.g. <INPUT TYPE=HIDDEN NAME="startfile" VALUE="index.html">
#
# You'll need to go through the script, changing a few things to make
it work
# on your setup!
#
# V1 15/1/99 Phil Anderson.
# (created)
#
##################################################################################


require 'cgi-lib.pl';

# change this to the root HTML directory of your site as seen by
# HTTP, e.g. if your URL is www.mydomain.com/mysite the root
# would be $htmlroot="/mysite". Leave it empty if you're using
# the server root

$htmlroot="";

# change this to the absolute path to the HTML directory on your
# web server. If you are using something like WSFTP, log on to
# your server, change to the html directory- the full path to
# it will be given in the listbox on the top!

chdir("server/users/me/public_html");


# change this to the path to your CGI directory

$cgidir="/cgi-bin";



##################################################################################
# if you've got everything above right, this script should run. the
only stuff that
# needs changing below here is the HTML that is used to format the
script's search
# returns.



# change this to however many links you want returned on each search

$maxlinks=10;






##################################################################################
# start the program
&ReadParse;
undef $/;
$index=1;
$index=$in{ind} if($in{ind});

# array @ignorefiles contains the list of filenames we're not
# to bother following if found as links
@ignorefiles=split(/,/,$in{ignore});


# startfile is the top-level file we're to look at.
$startfile=$in{startfile};

.... other content trimmed as they are not related to my question.
 
N

nobull

I'm a newbie to perl and is now studying about perl programming,

In that case you should start learning to program in Perl5. There is
no point lerning to program for Perl4.
I
read some perl programming tutorials online (enter 'Perl tutorial' at
google.com) and also find some sample perl scripts for study.

The example script you enclose was clearly written in the style of a
Perl4 script. I can't say for sure that it was actually written to
run on Perl4 but it uses many Perl4 techniques that are now considered
very poor Perl5 programming style. So if it wasn't written for Perl4
it was written by someone who learned how to program for Perl4 and
never bothered to learn how to program for Perl5.

Throw it away. To not attempt to learn from it.

As a quick rule of thumb do not attempt to learn from any script
(other than a one-liner) that doesn't start 'use strict' as this is
usually a sign of a program (orgininally) written for Perl4 (or by
someone who learned how to program for Perl4 and never bothered to
learn how to program for Perl5).
For below statements I couldn't understand what is the function of
'$in'.
1. $index=$in{ind} if($in{ind});
2. $startfile=$in{startfile};

'in' is the name of a hash (string-keyed array) variable called %in.
$in{ind} refers to the element of %in with the key 'ind'.
Could anyone help what's the meaning or where to find url
with explanation of such syntax ?

http://www.perldoc.com/perl5.8.0/pod/perldata.html

Note: this is the same 'perldata' document as you'll find on your own
local disk in the manuals that were installed as part of Perl.

There's a lot of reference (and some tutorial) documentation included
with Perl. I suggest you take a look at the table of contents
(perltoc).

This newsgroup does not exist (see FAQ). Please do not start threads
here.
 
L

lonelyplanet999

In that case you should start learning to program in Perl5. There is
no point lerning to program for Perl4.


The example script you enclose was clearly written in the style of a
Perl4 script. I can't say for sure that it was actually written to
run on Perl4 but it uses many Perl4 techniques that are now considered
very poor Perl5 programming style. So if it wasn't written for Perl4
it was written by someone who learned how to program for Perl4 and
never bothered to learn how to program for Perl5.

Throw it away. To not attempt to learn from it.
I read this script not just because it is perl but it presents a
program that describes the logic of a simple search engine. If I don't
know about meaning of that mentioned statements, I have no way to know
the program logic behind at all.
As a quick rule of thumb do not attempt to learn from any script
(other than a one-liner) that doesn't start 'use strict' as this is
usually a sign of a program (orgininally) written for Perl4 (or by
someone who learned how to program for Perl4 and never bothered to
learn how to program for Perl5).



'in' is the name of a hash (string-keyed array) variable called %in.
$in{ind} refers to the element of %in with the key 'ind'.
Is 'in' standard Perl keywords just line STDIN, etc ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top