in reply to Always leaving one space in file

From your description it seems that the tellmessage parameter is a textarea - but you use it as if it was a multiple choice scrolling list.

And to answer your question - the my @changes = param('tellmessage'); sets the @changes list to a one element list (if the tellmessage parameter is empty than the list contains one empty string). Thus the foreach loop allways is executed once - and when the parameter is empty the print statement prints the "\n" character.

Replies are listed 'Best First'.
Re: Re: Always leaving one space in file
by Anonymous Monk on Apr 23, 2003 at 15:23 UTC
    I tried this with no success:

    my $list; my @changes = param('tellmessage'); ###################### if (@changes eq " ") { exit } ###################### open(FILE, ">eetnlinks.txt") || die "Can't open file!"; flock(FILE, 2) || die "Can't lock file!"; #truncate(FILE,0); foreach $list (@changes) { chomp ($list); print FILE "$list\n"; } close(FILE);
    Or could I count the length of @changes and compare it:
    if (@changes > 1) { exit; }
    If that would work, I don't know how to count the length of the string... ?
      Try not opening the file unless you have data in the @changes array:
      if (@changes) { # do stuff here }
      I don't know how to count the length of the string...?:
      my $length = length $some_string;
      -- vek --
      Why do you insist on a list? Does the tellmesage parameter contain multiple values? If it was a textarea than it contains just one value and you can retrieve it with:
      my $change = param('tellmessage');
        It is a TEXTAREA not a TEXTBOX

        There is one link perline separated by a pipe "|"

        my site|http://www.whatever.com|blank
        I tried using $change, but it wouldn't work :(
      what I meant was:
      if (@changes eq " ") { @changes eq ""} }