Using a for() statement to create a variable??

Discussion in 'Perl Misc' started by dayton@gecko.org, Mar 26, 2005.

  1. Guest

    I have a form that is dynamiclly generated from a database. Using the
    CGI module, I'm trying to parse the parameters returned, but since the
    number of paramaters changes I can't get the variables assigned...

    What I'm trying:
    --------------
    $count='1';
    while (my(@data)=$table_data4->fetchrow_array) {
    print qq|
    <tr><td><input name=rs$count type=text
    maxlength=7 size=7 value=$data[0]><td>$data[1]
    |;
    $count++;
    }
    --------------------

    which correctly populates the table but then when I try to parse the
    parms..

    (like : if (param()){ $buh = param('buh') || '';}

    I run into my problem. I've tried:

    ----------------------
    for ($i=1;$i<=$number;$i++)
    $R$i="rs$i";
    }
    ----------------------

    and the error I get is:

    Scalar found where operator expected at ./test line 5, near "$RS$i"
    (Missing operator before $i?)
    syntax error at ./test line 5, near "$RS$i"
    Execution of ./test aborted due to compilation errors.


    How can I auto-generate the variables based on the # of params created
    by the form?
     
    , Mar 26, 2005
    #1
    1. Advertising

  2. wrote:
    > I have a form that is dynamiclly generated from a database. Using the
    > CGI module, I'm trying to parse the parameters returned, but since the
    > number of paramaters changes I can't get the variables assigned...

    [...]
    > for ($i=1;$i<=$number;$i++)
    > $R$i="rs$i";

    [...]
    > How can I auto-generate the variables based on the # of params created
    > by the form?


    You don't. Symbolic references are evil, please see the FAQ and google. This
    has been discussed to death many, many times over.
    Instead us a more suitable data structure like a hash. Again, the FAQ
    explains how ("How can I use a variable as a variable name?").

    jue
     
    Jürgen Exner, Mar 26, 2005
    #2
    1. Advertising

  3. Guest

    Dynamically generate the code block, then use "eval" on it?
     
    , Mar 26, 2005
    #3
  4. "" <> wrote in
    news::

    > Dynamically generate the code block, then use "eval" on it?


    To do what?

    Sinan
     
    A. Sinan Unur, Mar 26, 2005
    #4
  5. Guest

    "To do what?"

    Weren't you the guy insulting me on another post....
     
    , Mar 26, 2005
    #5
  6. [Full-quote]
    wrote:
    > "To do what?"
    >
    > Weren't you the guy insulting me on another post....


    Who is "you"? Whom are you talking to?
    Usenet is a 1-to-many communications form. Do you mean every single reader
    of this newsgroup?

    jue
     
    Jürgen Exner, Mar 26, 2005
    #6
  7. Guest

    ""Who is "you"? Whom are you talking to?""

    JH #2 - Please speak english in clear, readable and understandable
    expressions.
    What are "you" talking about?
     
    , Mar 26, 2005
    #7
  8. wrote:
    > ""Who is "you"? Whom are you talking to?""


    I suppose this is a quote from an article I posted. It is common courtesy to
    mark quoted text as such and to provide an attribution.

    > JH #2 - Please speak english in clear, readable and understandable
    > expressions.
    > What are "you" talking about?


    I strongly suggest that you read up on basic Nettiquette ASAP. You are on
    the brink of being granted membership in many killfiles.

    jue
     
    Jürgen Exner, Mar 26, 2005
    #8
  9. <> wrote:

    > JH #2 - Please speak english in clear, readable and understandable
    > expressions.



    We will do that when you do that.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Mar 26, 2005
    #9
  10. Guest

    "I suppose this is a quote from an article I posted. It is common
    courtesy to
    mark quoted text as such and to provide an attribution.


    > JH #2 - Please speak english in clear, readable and understandable
    > expressions.
    > What are "you" talking about?



    I strongly suggest that you read up on basic Nettiquette ASAP. You are
    on
    the brink of being granted membership in many killfiles.
    "

    I suggest you not mention "kill" as an attribute within your reply.
    Should you feel the need
    to kill someone, I suggest you consult proffessional help immediatly.
    In America, we do not
    take kindly to threats from individuals from foreign countries. Your
    time may well be better
    spent mastering english and gaining insite on American culture.
     
    , Mar 27, 2005
    #10
  11. "" <> wrote in
    news::

    > "I suppose this is a quote from an article I posted. It is common
    > courtesy to mark quoted text as such and to provide an attribution.


    And you have failed again to show common courtesy.

    >> JH #2 - Please speak english in clear, readable and understandable
    >> expressions.
    >> What are "you" talking about?

    >
    > I strongly suggest that you read up on basic Nettiquette ASAP. You are
    > on the brink of being granted membership in many killfiles. "


    Ditto.

    > I suggest you not mention "kill" as an attribute within your reply.


    Your ignorance is amusing.

    http://www.google.com/search?q=define: killfile

    > Should you feel the need to kill someone,


    No one said anything about killing anyone.

    > I suggest you consult proffessional help immediatly.


    Spell check: 'professional' and 'immediately'

    > In America, we do not take kindly to threats from individuals from
    > foreign countries.


    Just FYI: UseNet is not America.

    > Your time may well be better spent mastering english and gaining


    Spell check: 'English'.

    > insite on American culture.


    Spell check: 'insight'.

    Grammer check: 'insight into American culture'.

    I know, I know, I am feeding the troll.

    I am going to shut up now.

    Sinan.
     
    A. Sinan Unur, Mar 27, 2005
    #11
  12. wrote:
    > "I suppose this is a quote from an article I posted. It is common
    > courtesy to
    > mark quoted text as such and to provide an attribution.


    Would you please start providing proper credits when quoting text that you
    didn't write? Or do you want to be accused of plagiarism?

    >> JH #2 - Please speak english in clear, readable and understandable
    >> expressions.
    >> What are "you" talking about?

    >
    > I strongly suggest that you read up on basic Nettiquette ASAP. You are
    > on
    > the brink of being granted membership in many killfiles.


    Again, I never granted you the right to copy my text and to claim it as your
    own.

    > I suggest you not mention "kill" as an attribute within your reply.
    > Should you feel the need
    > to kill someone, I suggest you consult proffessional help immediatly.


    Your ignorance is surely broad. But really stunning is your resistance to
    learning.

    > In America, we do not
    > take kindly to threats from individuals from foreign countries.


    Yeah, true. It happens so easily that a certain person from Texas believes
    you have weapons of mass destruction in your backyard....

    BTW: Last time I checked America was a double continent. Which country
    within (or outside of) this continent are you considering to be "foreign"?

    > Your
    > time may well be better
    > spent mastering english and gaining insite on American culture.


    Try "English" and "insight into".
    Oh, and is there such a thing as _the_ American culture? I always found
    Carribean, Canadian, and Argentinian culture to be quite different.

    Proud to be an old European (although living in the USA).

    jue
     
    Jürgen Exner, Mar 27, 2005
    #12
  13. Joe Smith Guest

    wrote:
    > Dynamically generate the code block, then use "eval" on it?


    No! That is as bad, if not worse, than symbolic references.

    The message you are following up to (which you neglected to
    include any part of in your message) has the correct answer.

    It is quite clear that you are inexperienced in the ways of
    USENET. USENET is not the same as a web forum.

    When you post a follow-up message here, you are expected to
    include the name of the previous poster and a selected
    portion of the previous message.
     
    Joe Smith, Mar 27, 2005
    #13
  14. Jürgen Exner wrote:

    > wrote:
    >
    >>How can I auto-generate the variables based on the # of params created
    >>by the form?

    >
    > You don't. Symbolic references are evil, please see the FAQ and google.


    See also message <>

    http://groups.google.co.uk/groups?selm=

    > This
    > has been discussed to death many, many times over.
    > Instead us a more suitable data structure like a hash.


    In the OP's example an array is probably the more natural structure.
     
    Brian McCauley, Mar 27, 2005
    #14
  15. in a typical display of rudeness gives no context when
    he says:

    [ Of using symrefs in a loop to create several variables with numeric
    suffixes ]

    > Dynamically generate the code block, then use "eval" on it?


    It is, of course, a general rule that any inappropriate use of symrefs
    can be made even worse by using eval instead of symrefs.

    Symrefs and eval(STRING) are powerfull but dangerous tools. Use them
    only when the beniefits outweigh the costs. Symrefs are the lesser of
    the two (in both power and danger).
     
    Brian McCauley, Mar 27, 2005
    #15
  16. <> wrote:

    > You are
    > on
    > the brink of being granted membership in many killfiles.



    > I suggest you not mention "kill" as an attribute within your reply.
    > Should you feel the need
    > to kill someone,



    Pardon me but your ignorance is showing yet again.

    Nobody (apart from you) has said anything about killing anyone.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Mar 27, 2005
    #16
  17. wrote:
    > I suggest you not mention "kill" as an attribute within your reply.
    > Should you feel the need
    > to kill someone, I suggest you consult proffessional help immediatly.
    > In America, we do not
    > take kindly to threats from individuals from foreign countries. Your
    > time may well be better
    > spent mastering english and gaining insite on American culture.


    Listen, you dirty little traitor. A lot of good Americans in my father's
    generation gave their lives to put an end to vermin like you, and the
    last thing we need is to have an infestation back home. So you can just
    pack up your semiliterate, un-American shit and haul ass to North Korea,
    where you'll be right at home.

    --
    John W. Kennedy
    "But now is a new thing which is very old--
    that the rich make themselves richer and not poorer,
    which is the true Gospel, for the poor's sake."
    -- Charles Williams. "Judgement at Chelmsford"
     
    John W. Kennedy, Mar 27, 2005
    #17
  18. Guest

    On Sun, 27 Mar 2005 16:42:49 -0500, "John W. Kennedy"
    <> wrote:

    > wrote:
    >> I suggest you not mention "kill" as an attribute within your reply.
    >> Should you feel the need
    >> to kill someone, I suggest you consult proffessional help immediatly.
    >> In America, we do not
    >> take kindly to threats from individuals from foreign countries. Your
    >> time may well be better
    >> spent mastering english and gaining insite on American culture.

    >
    >Listen, you dirty little traitor. A lot of good Americans in my father's
    >generation gave their lives to put an end to vermin like you, and the
    >last thing we need is to have an infestation back home. So you can just
    >pack up your semiliterate, un-American shit and haul ass to North Korea,
    >where you'll be right at home.


    No problem. I'm in Los Angeles, California name a time and place so
    i can meet you and your fatther
     
    , Mar 29, 2005
    #18
  19. Guest

    On Wed, 30 Mar 2005 08:03:25 +0100, Henry Law
    <> wrote:

    >On 26 Mar 2005 16:04:11 -0800, "" <>
    >wrote:
    >
    >>I suggest you not mention "kill" as an attribute within your reply.
    >>Should you feel the need
    >>to kill someone, I suggest you consult proffessional help immediatly.
    >>In America, we do not
    >>take kindly to threats from individuals from foreign countries. Your
    >>time may well be better
    >>spent mastering english and gaining insite on American culture.

    >
    >Hey, Robic0, I have to thank you for providing me with several minutes
    >of fun, catching up with the newsgroup this morning. Far from
    >killfiling you (I guess you know what that means now) I've actually
    >been searching the group for your posts. The technical ones aren't
    >very interesting: they're rather obscure and from the reactions of the
    >Perl mavens here I suspect they're not very accurate; but the
    >non-technical ones like this are a hoot.
    >
    >The way you assume that Google is the same as USENET, and that the
    >group is a "site", and that the whole thing is in some way "owned" by
    >the USA and that everyone with a European or Asian name is therefore a
    >"foreigner" and to be deprecated in some way ... you provide more and
    >more fun with each thread. And the myopic pomposity you manage to get
    >into every post just cracks me up. Thanks.



    HHHHHHEEEEEEEYYYYYYYYYYYYYY
    HEEEEEEEEEEEEEEENNNNNNNRRRRRRRRYYYYYYYYY !!!!!!!!!!!!!

    How the **** are ya man ?????????
     
    , Apr 1, 2005
    #19
  20. Guest

    >Just FYI: UseNet is not America.
    >Sinan.


    Al Gore -> *****U S A***** --->>>>> ArpaNnet --> UseNet --> <you,
    the foreigner who taketh away American jobs>
     
    , Apr 1, 2005
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    823
  2. Jay McGavren
    Replies:
    11
    Views:
    1,169
    Alan Krueger
    Jan 16, 2006
  3. Replies:
    6
    Views:
    7,097
    mbstevens
    Aug 11, 2005
  4. tedsuzman
    Replies:
    2
    Views:
    7,147
    Michel Claveau, résurectionné d'outre-bombe inform
    Jul 21, 2004
  5. Froefel
    Replies:
    1
    Views:
    798
    Mark Rae [MVP]
    Jul 4, 2007
Loading...

Share This Page