473,768 Members | 8,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Script Bug - Inserts spaces after every return character

2 New Member
{NOTE . = space}
I made a script to allow me to edit my webpages online through a text area in my cgi script but I've run into a problem. For whatever reason the text area seems to put spaces in front of each line {except for the first} so,
line one
line two
line three

becomes
line one
.line two
.line three
next time it becomes
line one
..line two
..line three

eventually it winds up being like
line one
............... ............... .........line two
............... ............... .........line three

Its made a mess of my files.
Is there a way to process the input from the text area to remove all of the spaces before the start of the lines?
I'm hoping that I can get it worked out so while using the script my pages will wind up like it was to start with.
Thanks, any help would be greatly appreciated :)
John
Jul 19 '07 #1
4 2299
numberwhun
3,509 Recognized Expert Moderator Specialist
Have you tried anything so far to do it? My hint would be to use a substitution regular expression, something along the lines of the following:

s/^\s+//

I leave it in your hands to pass each line through it and see if it works. Let us know if you need more assistance. If you do (and in the future), please be sure and post your code when asking for help. :-)

Regards,

Jeff
Jul 19 '07 #2
KevinADC
4,059 Recognized Expert Specialist
textareas do not magically put in extra spaces. You can of course use a regexp like Jeff posted to work around your problem. But the real problem is elsewhere, most likely in the function you use to initially process the form data or when you print it to the file.
Jul 19 '07 #3
micronack
2 New Member
I haven't tried anything to fix the problem yet as I'm not really sure how to go about it and you can probably tell from the code below that I'm not real good at writing cgi. I get by but thats about it. Part of the problem may be that the cgi script doesn't start the files, they are normally written using coffee cup or note pad then this script is used for maintaining the pages.
Anyway heres the script its just a little over 100 lines so I posted the whole thing. To run it make a test html file with a link to the cgi script in the file. the password is pass

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. #Setup system variables
  4.  
  5. for ($i = 0; $i < 2; $i++){
  6.     ($i eq 0) ? ($f=<stdin>) : ($f=$ENV{QUERY_STRING});
  7.     @f = split(/\&/, $f);
  8.     foreach $l (@f) {
  9.         ($n,$v) = split(/\=/, $l);
  10.         $v =~ s|\+| |g;
  11.         $v =~ s|%([a-fA-F0-9][a-fA-F0-9])|pack("C", hex($1))|ge;
  12.         $form{$n}=$v;
  13.     }
  14. }
  15.  
  16. $book = $ENV{'HTTP_REFERER'};
  17. @sbook = [split(/\b/, $book)];
  18. $a=0;
  19. while ($sbook[0][$a] ne "") {
  20.     if ($sbook[0][$a] eq "com"){
  21.         $b = $a;
  22.     }
  23.     $a++;
  24. }
  25. $a = $b+2;
  26. while ($sbook[0][$a] ne "") {
  27.     $filename=$filename.$sbook[0][$a];
  28.     $a++;
  29. }
  30. $c = $a-3;
  31. $back = $sbook[0][$c];
  32. $c++;
  33. $back = $back.$sbook[0][$c];
  34. $c++;
  35. $back = $back.$sbook[0][$c];
  36.  
  37. if ($form{ACTION} eq "save") {
  38.     &SAVE;
  39.  
  40. } elsif ($form{ACTION} eq "view") {
  41.     &VIEW;
  42.  
  43. } else {
  44.     &LOGIN;
  45. }
  46.  
  47. sub LOGIN {
  48.     print "Content-type:text/html\n\n";
  49.     print qq~
  50. <center>
  51. <form action="$ENV{SCRIPT_NAME}?ACTION=view" method="post">
  52. <input type="text" name="password" value=""><BR>
  53. <input type="hidden" name="fname" value="$filename">
  54. <input type="hidden" name="bname" value="$back">
  55. <input type="submit" value=" ">
  56. </form>
  57. <a href=$ENV{'HTTP_REFERER'}>Cancel</a>
  58. ~;
  59. }
  60.  
  61. sub VIEW {
  62.     $fname = $form{fname};
  63.     $bname = $form{bname};
  64.     if ($form{password} ne "pass") {
  65.         die;
  66.     }
  67.     open(MESSAGE, "../$fname");
  68.     my @temp = <MESSAGE>;
  69.     close(MESSAGE);
  70.     print "Content-type:text/html\n\n";
  71.     print qq~
  72. <center>
  73. <form action="$ENV{SCRIPT_NAME}?ACTION=save" method="post">
  74. <input type="hidden" name="password" value="$form{password}">
  75. <textarea name="content" rows="20" cols="90">@temp</textarea>
  76. <input type="hidden" name="fname" value="$fname">
  77. <input type="hidden" name="bname" value="$bname">
  78. <BR><input type="submit" value="Save Changes">
  79. </form>
  80. <!--<a href=$ENV{'HTTP_REFERER'}>Cancel</a>
  81. <form action="$ENV{SCRIPT_NAME}?ACTION=edcon" method="post">
  82. <input type="hidden" name="password" value="$form{password}">
  83. <input type="submit" value="Edit Converter">
  84. </form>-->
  85. ~;
  86. }
  87.  
  88.  
  89. sub SAVE {
  90.     $fname=$form{fname};
  91.     $bname=$form{bname};
  92.     if ($form{password} ne "pass") {
  93.         die;
  94.     }
  95.     #get date and create backup
  96.     $a = localtime;
  97.     $g = substr($a,4,3); # month
  98.     $d = substr($a, -4); # year
  99.     $c = substr($a,8,2); # Day
  100.     $e = substr($a,11,2); # hour
  101.     $f = substr($a,14,2); # min
  102.     if ($c<10) {
  103.         $c = "0".substr($c,1);
  104.     } # put 0 in front 03 05 etc
  105.     $date = $g."-".$c."-".$d."---".$e."-".$f;
  106.     open(MESSAGE, "../$fname");
  107.     my @temp = <MESSAGE>;
  108.     close(MESSAGE);
  109.     open(MESSAGE, ">../backup/$date$bname");
  110.     print MESSAGE "@temp";
  111.     close(MESSAGE);
  112.     #endbackup
  113.  
  114.     open(MESSAGE, ">../$fname");
  115.     print MESSAGE "$form{content}";
  116.     close(MESSAGE);
  117.     print "Content-type:text/html\n\n";
  118.     print qq~
  119. <center>
  120. Changes saved<BR>
  121. <a href="$fname">go to page</a>
  122. ~;
  123. }
  124.  
Jul 19 '07 #4
KevinADC
4,059 Recognized Expert Specialist
I can't tell what might be the problem just by looking at the code. BTW, the code is really quite bad. I urge you to not use it at all.
Jul 20 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
31178
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it will split myString up using the delimiter of 1 space so that
7
2334
by: Lowell Kirsh | last post by:
I have a script which I use to find all duplicates of files within a given directory and all its subdirectories. It seems like it's longer than it needs to be but I can't figure out how to shorten it. Perhaps there are some python features or libraries I'm not taking advantage of. The way it works is that it puts references to all the files in a dictionary with file size being the key. The dictionary can hold multiple values per key....
5
36886
by: Jonathan Ng | last post by:
Hi, I was wondering if there was a way to include the white spaces in a string. Currently, I am using: scanf("%s", &input); However, this doesn't include the 'space' character or any other white spaces. Is there a way I can include the 'space' character rather than skip in.
9
6279
by: Durgesh Sharma | last post by:
Hi All, Pleas help me .I am a starter as far as C Language is concerned . How can i Right Trim all the white spaces of a very long (2000 chars) Charecter string ( from the Right Side ) ? or how can i make a fast Right Trim Function in c,using Binary search kind of fast algorithm ? Offcourse...I can use the classical approach too. like : Start from the right most charecter of the string to the left of the
135
7517
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about which is better. It has become what's known as “religious war” — a heated fight over trivia. In this essay, i like to explain what is the situation behind it, and which is proper.
40
2747
by: raphfrk | last post by:
I have a program which reads in 3 filenames from the command line prog filename1 filename2 filename3 However, it doesn't work when one of the filenames has spaces in it (due to a directory name with a space in it) because that filename gets split into 2. I tried
9
2004
by: Synapse Syndrome | last post by:
Hi I've been given what I am told is a PHP script to be used on my server. I do not know any PHP. I am trying to use a feature of a program called ArchiCAD. This feauture allows CAD drawing files to be published on a webpage, and viewed and commented on using a java applet. The problem is that with ArchiCAD v10, it now makes spaces and uses other
15
15627
by: DanielJohnson | last post by:
I am writing a program in which I am removing all the spaces from the string. I thought that I could do it two ways. One was parsing the string character by character and copying onto another output string. But this was trivial. The other option is to use pointers and shift all the characters after the space by one space to the left. I did this program using pointers and then using array too and I get segmentation fault. What is going...
8
2495
by: need2know2 | last post by:
I'm filling an array with explode(";" $linetoread) and then using the array to write to a file. When I open the file the array elements have spaces between each character. I've tried split as well with the same results. If viewed in a browser, all the spaces are missing even though they exist in the source.
0
9408
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10018
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9845
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8841
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7387
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6657
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5287
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5425
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3935
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.