Here's a brief analysis:

$mech->submit_form( # invoke the submit_form() object method. $form_string => $d, # Anything to the left of a # => is treated as like it's 'single quoted' # That means variables are not interpolated. # This is a possible bug in your script, # but not the one you're asking about. # *** Next comes the bug you're asking about. fields => { # The curly bracket begins an # anonymous hash. $param_string # This is a single scalar value } # You've completed the creation of the anonymous hash, but # you created it with one key (the contents of $param_string) # and no associated value. So you get an error message. );

If you want $param_string to represent a bunch of key/value pairs, you should first split it on its delimiter. After reading the comment in your code I assume you mean that the string is key/value delimited with =>, and each pair delimited with something else like maybe comma (,). If that's correct, this ought to do what you want:

$mech->submit_form( $form_string, $d, fields => { split( /=>\s+|,\s+/, $param_string ) } );

Of course you'll get into trouble quickly if it turns out that you have embedded commas within quoted text, and that sort of thing. If that's the case, you'll probably want to parse $param_string with a more robust tool.


Dave


In reply to Re: passing a variable as a string by davido
in thread passing a variable as a string by coldfingertips

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.