Well, just in terms of cosmetics, let me suggest that you place the subroutine definition outside the foreach loop -- it just makes more sense that way, and is less confusing.

As for the procedure, you say the input file contains (one or more?) line(s?) like "&name1=value1&name2=value2&...", and if that is true, can you say what this line of coding is doing, and why you're doing this:

($info) = split(/\ /,$i);
I'm not sure (anything containing strings of two or more white-space characters is visually ambiguous), but I think:

As for your stated purpose (to "remove &"), that's not entirely clear either. If you just remove this character from the input, you'll get (one or more?) strings like "name1=value1name2=value2name3=value3...", and I don't think that's what you want.

Maybe you mean "how do I split the line at the "&" characters?" If so, you do it like this:

my %parhash; for my $i (@data) { chomp $i; my @params = split( /\&/, $i ); # and while you're at it, the "nameX=valueX" can be # stored in a hash like this: for ( @params ) { next unless ( /.=./ ); # make sure there's a name and a value my ($k,$v) = split(/=/); $parhash{$k} = $v; } } # print html header stuff, then: print "user supplied data was:<br>\n"; for ( sort keys %parhash ) { print "$_ = $parhash{$_}<br>\n"; } # print html trailer stuff

In reply to Re: Remove & from file by graff
in thread Remove & from file by Jamison

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.