[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl-WebCGI] [MacPerl] Referencing a Hash element...



Hello,

Below is a snippet of code from a CGI script I am building. I have been
trying to work out how to create a reference to the hash elements to save
constant repetition of the full Hash element name (i.e.
$Form{"description$tagIndex"} ), but I am having no luck. I have read and
re-read the relevant section in 'Programming Perl', but i am none the wiser
as to the necessary syntax. Any pointers would be much appreciated. Please
feel free to rubbish my bloated code too.


My apologies for the poor formatting, but Outlook Express wasn't built for
displaying code. =P

TIA

Richard

****************************************************************************

        $tagIndex = 1;

        while (exists $Form{"linktext$tagIndex"}) {
            #    Check the data fields for errors
            if (exists $Form{"use$tagIndex"}) {
                    #    Removing any trailing newlines
                    chomp (
                    $Form{"linktext$tagIndex"},
                    $Form{"description$tagIndex"},
                    $Form{"location$tagIndex"},
                    $Form{"order$tagIndex"}
                    );
                    &buildErrorMessage('you have left blank fields') if (
                        $Form{"linktext$tagIndex"} eq '' or
                        $Form{"description$tagIndex"} eq '' or
                        $Form{"location$tagIndex"} eq '' or
                        $Form{"order$tagIndex"} eq '');

                #   Check each entry for illegal characters.
                #   Blocks are enclosed in braces to contain the scope
                #   of the $& variable
                {
                #   Substitute any illegal characters with an asterisk
                $Form{"linktext$tagIndex"} =~ s/[^a-zA-Z ]+/\*/g;
                #   Throw an error if a character was replaced
                &buildErrorMessage(qq| the link text in line
$Form{"order$tagIndex"} contained an illegal character '$&'|) if $&;
                }
                {
                 #  Trim whitespace from each end
                $Form{"linktext$tagIndex"} =~ s/^\s*(.*?)\s*$/$1/;
                }
                {
                #   Substitute any illegal characters with an asterisk
                $Form{"description$tagIndex"} =~ s/[^a-zA-Z()., ]+/\*/g;
                &buildErrorMessage(qq| the description in line
$Form{"order$tagIndex"} contained an illegal character '$&'|) if $&;
                }
                {
                $Form{"description$tagIndex"} =~ s/^\s*(.*?)\s*$/$1/;
                #   Now make sure there is a full stop on the
                #   end of the description.
                #   Add a full stop to the end of the description
                $Form{"description$tagIndex"} .= '.';
                #    If there are two fullstops, replace with one
                $Form{"description$tagIndex"} =~ s/\.+$/\./;
                ucfirst $Form{"description$tagIndex"};
                }
                {
                $Form{"location$tagIndex"} =~ s/[^a-zA-Z_#\/.:]+/\*/g;
                &buildErrorMessage(qq| the location in line
$Form{"order$tagIndex"} contained an illegal character '$&'|) if $&;
                }
            }
            $tagIndex++;
        }

****************************************************************************
-- 

Team Artonomy,
Drawing Business.

team@team-artonomy.com

http://www.team-artonomy.com

Featured on Wow Web Designs,
http://www.wowwebdesigns.com

*************************************



==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org