open(HNDL, "1.txt") or die "Cannot open text file";
while (<HNDL>)
{
if($.==2)
{
print $_;
$_ =~ s/\s//g;
print "after removing spaces $. :",$_;
}
}
output --
" 1 0 0 "
Actually, I need it as "100". So that I can perform some arithmetic operations.
Excuse if there is silly mistakes in using substitute. I'm just a beginner in perl..!!
10 1258
Hi Raj,
I have checked your script with DATA handler as below, it is working fine. -
use strict;
-
use warnings;
-
-
while (<DATA>)
-
{
-
if($.==2)
-
{
-
print $_;
-
$_ =~ s/\s//g;
-
print "after removing spaces $. :",$_;
-
}
-
}
-
__DATA__
-
1000
-
1 0 0
-
I suspect your file content, could you please show us your file content ?
Hi Vino,
Thanks for the reply..!!
here's the content.. I'm sending you little part of it.
--content in text file --
"XXXXXXXXXXXRemaining
100 "
these are the first two lines of the text file
Ok, Lets check this way,
1.First confirm that "1 0 0" comes in the second line only.
2.From your sample input, I can see that, 100 spaces removed already?
1.First confirm that "1 0 0" comes in the second line only.
[Raj] Yes, 1 0 0 comes in the second line itself
2.From your sample input, I can see that, 100 spaces removed already?
[Raj] In the text file spaces are not there. But, when you read it to a variable by using above script.. the variable is storing with a space for each character.
Even if i print first line, output will be
X X X X X R E M A N I N G
Interesting!
1.What is the perl version you are using ?
2.How you code this 1.txt file, which generated by any other scripts ?
3.If you are from linu/unix execute this "file 1.txt" and let me know the output.
1.What is the perl version you are using ?
Perl 5.16
2.How you code this 1.txt file, which generated by any other scripts ?
it's an internal tool generated from batch file
3.If you are from linu/unix execute this "file 1.txt" and let me know the output.
I'm using Windows
-Raj
I got you now, as you are windows, your file will be in different encoding.
Try this, -
open my $fh, '<:encoding(UTF-16LE)', 1.txt or die "Couldn't read '1.txt': $! / $^E";
-
while (<$fh>) {
-
print $_;
-
};
Thanks Vinoth.. That's the problem.. I have tried saving the file in ANSI encoding format and now it's working..
But, I think we need a encoding module to be dowloaded right?
I do not think you need additioal modules as you are using the latest perl version only, if needed you can install it.
OK.. anyways.. it's working now..Thanks a lot..!!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: multimatum2 |
last post by:
Hello,
I need to enable/disable input text forms...
But...
I need to have the same style (color...) in both modes..
Could you help me ?
Thanx a lot
A small sample...
...
|
by: Magix |
last post by:
Hi,
Everytime I received a fix-length of string, let say 15 (the unused portion
will filled with Spaces before receive), I want to remove the Spaces from
END until I encounter a non-space char....
|
by: Ali |
last post by:
I have 3 html input tex in my asp.net form. Two of them are calling
javascript client side to calculate the differnce of two dates and put the
result into the third input text. i haven't include...
|
by: acecraig100 |
last post by:
I am fairly new to Javascript. I have a form that users fill out to
enter an animal to exhibit at a fair. Because we have no way of
knowing, how many animals a user may enter, I created a table...
|
by: kvnsmnsn |
last post by:
I've written the following Javascript file that includes an input text
field and an output text field, the latter of which is initialized to
zero. Each time the user enters a number in the input...
|
by: John Grewar |
last post by:
Hello,
In MS Access I have a field that contains data which looks like this example, GZQ 678239; GZQ 014312; etc. How do I remove the spaces to make it become (not just look like) GZQ678239;...
|
by: =?Utf-8?B?R3VoYW5hdGg=?= |
last post by:
Hi,
In a web page we have many single line input text boxes inside table,which
has the max length of 250 characters and few drop downs where auto post back
property is true.
When we provide 250...
|
by: ramu |
last post by:
Hi,
Suppose I have a string like this:
"I have a string \"and a inner string\\\" I want to remove space in
this string but not in the inner string"
In the above string I have to remove...
|
by: backups2007 |
last post by:
I want to be able to pass rows of queried data to rows of input text boxes. As the example below shows, I have come up with this incomplete solution. But this code only passes the data to the first...
|
by: aadsaca |
last post by:
Deleting/Removing lines on Text File in VB
--------------------------------------------------------------------------------
Hi there,
i just want to know the syntax on how
to remove line on...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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 project—planning, coding, testing,...
| |