[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
Re: Will someone make sense of this Perl segment for an idiot?
****** message to minivend-users from Ryan Hertz <rhertz@gyb.baits.com> ******
At 08:06 PM 4/8/99 , mediamob wrote:
>****** message to minivend-users from mediamob <mediamob@dnaco.net>
******
>
>
>I thought I was pretty smart, and then I started trying to use minivend...
:-)
>
>Anyway, I think that understanding this bit of code from browse1 as
>supplied with sample might unlock some keys for me. I have no perl
>experience, but I do have a book ("learning perl") and a desperate
>persistance. I will list the lines here and a statement as to why it makes
>no sense to me based upon what I can garner from the perl book. I would be
>most appreciateive if anyone can offer a clue.
>
>Here goes:
>[perl arg=scratch]
> $start = tag_data('session', 'arg') || 1;
>
>It looks like this means something like "assign to the variable $start the
>value of a logical OR operation between the return value of the routine
>tag_data (with arguments 'session' and 'arg') and the numeric value 1."
>
>If Perl considers 1 to be true and 0 to be false, doesn't this always
>return a true? What good does it do?
I believe you could consider the double pipe as 'or', so if the 'arg'
passed from the session doesn't contain anything (undef) we'll start with
numero uno.
>Secondly, what does tag_data() do? I found some exaple uses in the mailist
It is most likely a function defined elsewhere.
>arcives, and some other reqests for help regarding it, but no definition.
>A search of the docs turns up 4 references, but likewise no definition.
>
> $chunk = 1;
>
>Ok, I think I get this one.
>
> if($start =~ /(\d+):(\d*)/) {
>
>I get as far as this: " If the value of $start matches" and then I can't
>recognise what is an operator and what is a variable. What does the : do?
>does the \ indicate a literal d rather than a reserved word d?
It's called a regular expression or regexp. I believe that 'd' is a
numeric digit. Look at the syntax for calling [browse] from the minivend
HTML pages and it will make sense... we're making sure that browse is
getting two numbers seperated by a colon.
>
> $start = $1;
>
>Now the value of $start is set = the value of $1. Where did $1 come from ,
>and how do we know it's value?
I believe that $1 had become the first number from the regexp above.
>
> $chunk = $2 || 1;
> }
>Likewise $2
$2 would be the second number from the regexp above.
>
> $prev = $start - $chunk;
> if($prev < 1) {
> $prev = 0;
> }
>
>I think I get this.
>
> $Safe{'scratch'}{'start'} = $start;
> $Safe{'scratch'}{'chunk'} = $chunk;
> $Safe{'scratch'}{'next'} = $start + $chunk;
> $Safe{'scratch'}{'prev'} = $prev;
> $Safe{'scratch'}{'not_shown'} = 1;
>
>No clue as to what the left side does. Looks like some kind of array
>handling, but I don't find a reference.
It is making sure that scratch's start variable is Safe. (no funny stuff).
>
> return '';
>[/perl]
>
>Ok ,these I think I have.
>
>
>TIA-
>
>MediaMob
>
Ryan Hertz tel 520-645-3812
Webmaster tel 800-645-BAIT
Advertising Director fax 520-645-2588
Gary Yamamoto Custom Baits, Inc. http://www.yamamoto.baits.com
-
To unsubscribe from the list, DO NOT REPLY to this message. Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list