Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

RE: Re: script adding spaces into a file for no reason...

by Anonymous Monk
on May 20, 2000 at 00:59 UTC ( [id://13492]=note: print w/replies, xml ) Need Help??


in reply to Re: script adding spaces into a file for no reason...
in thread script adding spaces into a file for no reason...

<textarea>@{join("",@text)}</textarea> the proposed solution still returns an array; It needs to be taken out of array context. Instead of print <<END , try: print "<textarea>" . join ( "", @text ) ."</textarea>\n" ; This is presuming, of course, that the "\n" is already on the end of each element of @text. if not, you might want to join them with "\n". Also, be aware that some browsers may take it upon themselves to make each line ending a "\n\r" - especially if you cut and paste into the textarea. I make it a habit to: $input =~ s/\r//g ; On all submitted form values to clean it up.
  • Comment on RE: Re: script adding spaces into a file for no reason...

Replies are listed 'Best First'.
RE: RE: Re: script adding spaces into a file for no reason...
by httptech (Chaplain) on May 20, 2000 at 04:35 UTC
    My solution, @{[join("",@text)]} does not return an array in this case. (Look at pg.239-241 of Effective Perl Programming for more examples of using this construct). It does use the anonymous array construct and the array dereferencing construct, but the net result is to interpret the code inside the brackets in whatever context it would have occured elsewhere outside of the constuct and the here-doc. So, because "join" returns a scalar, so does my code. It's just a quick and dirty way to interpolate a piece of code inside a larger print statement.

    Of course, there are many other ways you could accomplish the same thing, I just happen to like this because it keeps the amount of variable assignment to a minimum.

      Thanks to everyone for their help. It's working now. Here's the core file saving code for your reference. It removes unncessary line returns, etc.

      if (defined $query->param('Submit')) { open NEWNEWS, "> cgi/news.txt" || die "Cannot open file: $!"; $result = $query->param('content'); $result =~ s/\r//g; print NEWNEWS $result; close(NEWNEWS); print '<p>Saved your changes.</p>'; $query->delete('Submit'); }


      JoeG
RE: RE: Re: script adding spaces into a file for no reason...
by Anonymous Monk on May 20, 2000 at 01:06 UTC
    ack! (look at the html source to decipher previous reply)
RE: RE: Re: script adding spaces into a file for no reason...
by JoeG (Initiate) on May 20, 2000 at 01:24 UTC
    I tried reading the source .. and used that code-- it runs w/o errors, but unfortunately didn't fix..
    I used:
    print "<textarea>" . join ( "", @text ) ."</textarea>\n" ;
    hmm.. this is really strange. any other ideas?>

    Joe
      I'm not sure what the problem is, but I'll add a couple of ways to interpolate an array without spaces...
      print "<textarea>", @text, "</textarea>\n"; # (unless you've redefined $,)

      ...or...

      { local $"; print "<textarea>@text</textarea>\n"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://13492]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (1)
As of 2025-07-10 05:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.