in reply to Strange @ appearance

There's a small problem with the format. The line@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $subject should be 2 lines...
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $subject
The only reason I can see for having '@' chars in the output is that perhaps you have '@' chars in the input. Add in a print STDOUT "[$date] [$subject] [$article]\n" line to find out what's in the variables. Maybe your split() is getting data you hadn't intended.

Also, it's not hurting anything, but the extra parens around split() aren't needed.

Update: Null characters sometimes look like '^@' in an editor. Perhaps the input file contains nulls ? Try doing a hex dump ( od -hc filename ) and see.

Replies are listed 'Best First'.
Re: Re: Strange @ appearance
by Anonymous Monk on Jul 29, 2001 at 18:03 UTC
    Thanks 4 responding. Yes, I notice I put that $subject on the wrong line - it isnt in my actual code, just a typo. As for having '@' chars in the input, I don't know. The input is actually POSTed from a web page. I have decoded it like so:
    # Get POSTED info and stick it in $post_info. read (STDIN, $post_info, $ENV {'CONTENT_LENGTH'} ); # split off fields and put them in @InfoArray @InfoArray = split(/&/, $post_info); # Remove variable= part and translate data into real chars for ($n = 0; @InfoArray[$n]; $n++) { chomp; # remove newline ($dummy, $temp) = split (/=/, @InfoArray[$n]); $temp =~ tr/+/ /; $temp =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; @InfoArray [$n] = $temp; }
    Does anyone see something dodgy with that little lot? Also, yes, it may be a null character, but I have chomped and choped the last line of text, and even done a 'get rid of crap' command  $article =~ s/\ 0//g;, all to no avail. Sheesh, It's gonna take me a while to get used to PERL. It's very powerful and, if you know it, quick, but it's so untidy! Im a Java man you see...
      Yikes, don't try and implement CGI.pm yourself. See here for more info.

      Your loop is a little "dodgy", using array slices and such. Also, the chomp() is chomping $_, which means nothing in the context you gave it, since $_ is being set to the array index.

      If you end up not using CGI.pm (ack), rewrite the loop so that chomp actually does something.

      # iterate over the split # placing each element in $_ along the way my @InfoArray; for (split(/&/, $post_info)) { chomp; # remove newline ($dummy, $temp) = split (/=/, $_); $temp =~ tr/+/ /; # ack, urldecoding in a regex ? $temp =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; push(@InfoArray,$temp); }
      But do please try Cgi.pm...it's well equipped to pull out the form values, do the (un)encoding of urls, etc.