Hello,
I hope someone can help me with this!
I have a problem editing a text file my file looks like this
11
13
15
16
23
I want to read the file a line at a time and add 0.5 to every line so this is the script i used. - open(my $a, '>File.txt');
-
$b ="\t0.5\n";
-
open (Data, 'Data.txt');
-
while ($c = <Data>){
-
-
print $a "$c\t$b";
-
}
-
-
close $a
-
close (Data)
I want my output to look like this
11 0.5
13 0.5
15 0.5
16 0.5
23 0.5
but it looks like this
11
0.5
13
0.5
15
0.5
16
0.5
23
0.5
How do i get my data printed on one line?
10 1358
Hello,
I hope someone can help me with this!
I have a problem editing a text file my file looks like this
11
13
15
16
23
I want to read the file a line at a time and add 0.5 to every line so this is the script i used. - open(my $a, '>File.txt');
-
$b ="\t0.5\n";
-
open (Data, 'Data.txt');
-
while ($c = <Data>){
-
-
print $a "$c\t$b";
-
}
-
-
close $a
-
close (Data)
I want my output to look like this
11 0.5
13 0.5
15 0.5
16 0.5
23 0.5
but it looks like this
11
0.5
13
0.5
15
0.5
16
0.5
23
0.5
How do i get my data printed on one line?
Try adding the following two lines to your code before printing to the new file: -
chomp($a);
-
chomp($b);
-
chomp($c);
-
Regards,
Jeff
I tried this but it works for some of the numbers but not all. The output looks like this i want a tab in between the numbers.But i only get it for numbers who have two digits, if they have only one i get just a space.
[HTML]
11 0.5
12 0.5
1 0.5
2 0.5
5 0.5
22 0.5
44 0.5[/HTML]
Try adding the following two lines to your code before printing to the new file: -
chomp($a);
-
chomp($b);
-
chomp($c);
-
Regards,
Jeff
I tried this but it works for some of the numbers but not all. The output looks like this i want a tab in between the numbers.But i only get it for numbers who have two digits, if they have only one i get just a space.
[HTML]
11 0.5
12 0.5
1 0.5
2 0.5
5 0.5
22 0.5
44 0.5[/HTML]
Hi..
Your code is working fine for me... and I am gettting equal space between the numbers no matter if they are one digit or 2 digit. -
-
open(my $a, '>File.txt');
-
$b ="\t0.5\n";
-
open (Data, 'Data.txt');
-
while ($c = <Data>){
-
chomp($c);
-
print $a "$c\t$b";
-
}
-
-
close $a;
-
close (Data);
-
I am attaching the input and output files....
Hi..
Your code is working fine for me... and I am gettting equal space between the numbers no matter if they are one digit or 2 digit. -
-
open(my $a, '>File.txt');
-
$b ="\t0.5\n";
-
open (Data, 'Data.txt');
-
while ($c = <Data>){
-
chomp($c);
-
print $a "$c\t$b";
-
}
-
-
close $a;
-
close (Data);
-
I am attaching the input and output files....
If tried it several times om my data but it only gives a tab at the largest number of digits i have different numbers of digits in my data and only the one's with the most digits get's a tab in between my output keeps looking like this.
[HTML]1234 0.5
123 0.5
12 0.5
1234 0.5
1 0.5
1234 0.5
1234 0.5[/HTML]
My data is in a text file could that be a problem should it be in another format?
hi,
i worked with this code, it is working fine as like your required output. -
open(my $a, '>File.txt');
-
$b ="0.5\n";
-
open (Data, 'Data.txt');
-
while ($c = <Data>){
-
chomp($c);
-
print $a "$c $b";
-
}
-
close $a;
-
close (Data);
-
Hi..
Your code is working fine for me... and I am gettting equal space between the numbers no matter if they are one digit or 2 digit. -
-
open(my $a, '>File.txt');
-
$b ="\t0.5\n";
-
open (Data, 'Data.txt');
-
while ($c = <Data>){
-
chomp($c);
-
print $a "$c\t$b";
-
}
-
-
close $a;
-
close (Data);
-
I am attaching the input and output files....
hi,
can u tell me how to attach a file.
Hi
if tried it on a couple of data sets but my output remains not properly outlined.
I attached my data files so you can look for yourself the output is misaligned
hi,
can u tell me how to attach a file.
You can attach a file when editing a post
hi,
i worked with this code, it is working fine as like your required output. -
open(my $a, '>File.txt');
-
$b ="0.5\n";
-
open (Data, 'Data.txt');
-
while ($c = <Data>){
-
chomp($c);
-
print $a "$c $b";
-
}
-
close $a;
-
close (Data);
-
I had to edit your post to add the required code tags. Please be sure any time that you post code to the forum, that you surround it in the necessary code tags.
Regards,
Jeff
Sign in to post your reply or Sign up for a free account.
Similar topics
by: ZoombyWoof |
last post by:
Hi. Im very new to php, and I have a problem here that I cant find the
solution for. I have problems with session variables, I want some
variables to maintain their value between different php...
|
by: Graham Taylor |
last post by:
I've tried posting this in the 'microsoft.public.access' but I will post it
here also, as I think it might be the webserver which is causing my problem.
---------
I have an Access 2003 database...
|
by: David Nedrow |
last post by:
I'm trying to set up the cyrus imap server using PostgreSQL as the
authentication backend.
Currently, the issue I'm having is that I'm unable to connect via psql
on the loopback address...
|
by: sam.collett |
last post by:
Is there a basic guide on Xml document creation and editing (simpler
than the MSDN docs). Say I want to create a file containing the
following:
<?xml version="1.0" encoding="utf-8"...
|
by: NewBob |
last post by:
Since Access automatically highlights all of the text in a text
control (I use it to hold data from a memo field) when the control is
activated, I've added the following code to put the cursor at...
|
by: E. Tom Jorgenson |
last post by:
I've run into a problem on a couple of projects that I think I've
identified - but would like confirmation of what I think is going on. Also
interested in any fast solutions to fix the user...
|
by: Jeigh |
last post by:
My host has been 'upgrading' lately and its caused me a whole mess of problems. The last of which being that my CAPTCHA form no longer works. I remember to get the CAPTCHA working it took me weeks to...
|
by: Sinan Alkan |
last post by:
Hi All,
I have a method to resize any image file to the specific dimensions and
save this new image to a path.
I found it on a web page(By Joel Neubeck) and i changed it for my project.
The...
|
by: priyamtheone |
last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have:
1) Initially all the cells of the dtp column should be...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
| |