473,320 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Using chop / chomp to remove spaces and tabs

I am having a file that contains different strings, which in turn are name of folders.

For example test. file has:
test0002
intel/drivers/

Here there can be spaces, tabs after folder names (like we can place space after test0002 or it may happen when you edit file in notepad and use same in Unix test0002 becomes test0002^M).

I used chop and chomp to do it. What I did was I read all contents in array then I did chop (or chomp) for each element of array but nothing works. I m unable to remove extra spaces, tabs.

How can this be done to get desired result?
Mar 24 '06 #1
2 15543
eWish
971 Expert 512MB
Chomp function.
Chop function.

You could use a regex to remove the spaces or tabs.
Expand|Select|Wrap|Line Numbers
  1. my $test  =~ s/\n//g; #removes newline
  2.    $test = s/\t//g; #removes tab
  3.  
  4. #Remove Leading and Trailing Whitespace
  5. my $test =~ s/^\s+//;
  6.    $test =~ s/\s+$//;
--Kevin
Nov 18 '07 #2
KevinADC
4,059 Expert 2GB

I used chop and chomp to do it. What I did was I read all contents in array then I did chop (or chomp) for each element of array but nothing works. I m unable to remove extra spaces, tabs.

How can this be done to get desired result?
chop removes the last character from a string/line, chomp removes the input record seperator (usually a newline) from a string/line. Not sure why you thought either of those functions was appropriate for what you are doing. See Kevins post above.
Nov 18 '07 #3

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

Similar topics

2
by: Matt Taylor | last post by:
I have this piece of code: $/ = ' '; $test = "abc "; chomp $test; print $test; which prints spaces at the end of the line. Shouldn't chomp strip the spaces off the end of my scalar $test?
11
by: gopal srinivasan | last post by:
Hi, I have a text like this - "This is a message containing tabs and white spaces" Now this text contains tabs and white spaces. I want remove the tabs and white...
1
by: Arjen | last post by:
Hello, In code view I use a tab as mark-up character. When I run my web application I can see the tabs with the source viewer in my browser. Is there a way to remove the tabs, extra spaces...
3
by: ReidarT | last post by:
I have accidentally enabled spaces and tabs and ... in code window. How do I disable this? reidarT
135
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...
34
by: Registered User | last post by:
Hi experts, I'm trying to write a program that replaces two or more consecutive blanks in a string by a single blank. Here's what I did: #include <stdio.h> #include <string.h> #define MAX 80
35
by: lnatz | last post by:
Hi, Is there an equivalent to the perl command chomp in C? And if there is no exact equivalent command, how would I go about removing the "\n" at the end of a stdin? Thank you, Natalie
23
by: Steven TK | last post by:
Hi everyone, I wonder who can help me on the filter the Start Date and End Date. I still cannot manage to filter it. Eg. When the user click the StartDate(comboBox as 16/7/07), the Start...
2
by: RAGHAVENDRAS | last post by:
Hi, I am writing a script which should update an excel sheet daily. So how do I determine which is the last row which contains data and then write the latest data into the sheet. use...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.