Re: Big problem with @array and Chomp ... I think :o

From: Kevin Shay (kevin_shay_at_yahoo.com)
Date: 11/05/03


Date: 4 Nov 2003 19:48:29 -0800


"Robert TV" <ducott_99@yahoo.com> wrote in message
news:<j0Tpb.290847$6C4.168943@pd7tw1no>...
> @recipients = CGI::param('csvdata');
>
> open (FILE,">>$activeuser/csvdump.txt");
> close(FILE);
>
> open (ADDRESSES, ">$activeuser/csvdump.txt") or die "Can't open file: $!";
> print ADDRESSES @recipients;
> close(ADDRESSES);
>
> open (ADDRESSES, "<$activeuser/csvdump.txt") or die "Can't open file: $!";
> @recipients = <ADDRESSES>;
> close(ADDRESSES);
>
> unlink <$activeuser/csvdump.txt>;
>
> <-- End Code Example -->
>
> Ok, right about now your wondering why did I take the form contents, write
> it to a temp file, then open and get the data back from the temp file. For
> some reason I cannot get the code to work any other way.

The problem may lie in the first line of code above:

@recipients = CGI::param('csvdata');

It sounds like you have a single HTML form field called csvdata, into
which the user enters multiple lines of text. If that's the case, the
CGI module will not automatically turn this into a list. It's a single
value. So the entire set of data is being placed into the first
element of @recipients.

When you print that one-element array to a file, it simply prints that
one element; the element happens to have multiple lines, so the
resulting file will have multiple lines. Then, when you re-open the
file and do this:

@recipients = <ADDRESSES>;

Perl reads the lines of the file into the array, one line per element,
which is what you wanted in the first place. So you could probably
just do this to avoid the whole temp file workaround:

@recipients = split(/\n/, CGI::param('csvdata'));

As for the actual chomp problem, it may have something to do with the
way different operating systems encode newlines differently (\n on
Unix, \r\n on DOS/Windows, \r on Mac). Depending on which platform the
user's browser is running on, you may not be getting just \n
characters separating the lines. So you might want to normalize
everything to \n newlines:

my $csvdata = CGI::param('csvdata');
$csvdata =~ s/\r\n?/\n/g;
@recipients = split(/\n/, $csvdata);

Kevin

--
perl -MLWP::UserAgent -e '$u=new LWP::UserAgent;$u->agent("japh");
print join(" ",(split(/\s+/,(split/\n/,$u->request(HTTP::Request->
new(GET=>join("",split(/\n/,"http://groups.google.com/groups?selm=
4365%40omepd.UUCP&output=gplain"))))->content)[60]))[0..3]),",\n"'


Relevant Pages

  • Re: too many recipients
    ... What he gets is a single message from the System ... Administrator with multiple lines like this.. ... > And, are the recipients in your own Exchange organization, or are they ...
    (microsoft.public.exchange.admin)
  • Re: Multiple emails received
    ... If you are, then crank up protocol logging, look through message ... >>>We don't have this problem with our other external recipients. ... >>>multiple emails and I did not see any multiple instances of the same email ...
    (microsoft.public.exchange.admin)
  • Re: How can I create a distribution list using Outlook categories
    ... The categories technique works well for NEW messages to be sent to multiple ... recipients in a particular interest group. ... method is darn clumsy when I want to FORWARD a message that I have received ... "Russ Valentine" wrote: ...
    (microsoft.public.outlook.contacts)
  • Re: Problem forwarding message to multiple recipients
    ... If you are using Outlook Express, do not open the address book. ... > When trying to forward a received message to multiple ... > recipients, whenever I attempt to do this by bringing up ... > the first name disappears. ...
    (microsoft.public.internet.mail)
  • Sending emails to multiple recipients
    ... Is it possible/anyone know how to send a document (.pdf) to multiple ... recipients using POP where the email is not just a matter of throwing 1000 ...
    (microsoft.public.dotnet.languages.vb)

Loading