l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2001 Dec 30 17:05

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] newbie perl question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] newbie perl question

  • Subject: Re: [vox-tech] newbie perl question
  • From: Henry House <hajhouse@houseMAPSag.com>
  • Date: Wed, 30 May 2001 12:08:13 -0700
  • References: Pine.LNX.3.96.1010530120947.29296A-100000@step.mother.com

On Wed, May 30, 2001 at 12:12:14PM -0700, cathair wrote:
> Here's how I DID get output without using the pulldown <snip>:
> my $i;
> for ($i = 0; $i <= $#array_name; $i++){
>       print "$array_name[$i]\n";
> }

Do you know about perl's foreach loop construct? It is tailor-made for the
common case of doing something once for each element of an array. You could
re-write the above as:

foreach my $elem (@array_name) {
        print "$elem\n"

The output is equivalent.

> THAT worked just dandy.
> But when I attempt...<snip>:
> my $j;
> print "<form name="a_form">\n";
> print "<select name="pull_my_finger" size=1>\n";
> for($j = 0; $j <= $#array_name; $j++){
>       print "<option>$array_name[$j]\n";
> }
> print "</select></form>\n";
> </snip>
> ...it fails at me.

The code above looks fine. Are you sure you aren't doing something wrong
earlier in the script that does not become noticeable until this point?

How does the code fail at you?[1]

> Is there a way around this besides embedding the script (and output)
> midpage?

Cannot answer the question because of insufficient data.

[1] When asking for help, it is essential to provide specific information
         about what you were doing and what went wrong. Saying 'it fails at me' is
         a classic un-useful bug report. Better would be to provide the exact
         faulty program output, or the perl debugging messages, if the script died
         in compilation.  Don't feel bad: since you are a newbie, you don't know
         this stuff, but please take note for future reference.

Henry House
OpenPGP key available from http://hajhouse.org/hajhouse.asc

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.