Solved

Removing preceeding space

Posted on 2001-07-20
9
189 Views
Last Modified: 2008-02-26
I am trying to find if a certain string is found in a file.
I noticed that when i read from the file and split each line into tokens the token with which i wnat to test the search string is always preceeded with spaces.Hence the pattern matching alwasy fails, is there any function which would remove the whitespaces in a string(like how chomp behaves, removing the new line)
Thank you
0
Comment
Question by:Amulya
9 Comments
 

Author Comment

by:Amulya
ID: 6303319
is  it possible to create a pattern matching rule which ignores spaces .
$token1=" value1"
$search="value1"
I tried ($token =~/^$search)
i do not know exactly how many spaces will preceed token1.
0
 
LVL 84

Accepted Solution

by:
ozo earned 25 total points
ID: 6303342
$token =~/$search/
0
 
LVL 3

Assisted Solution

by:interiot
interiot earned 25 total points
ID: 6303385
$token =~ s/^\s*//;


should remove the preceding spaces.
0
 
LVL 8

Expert Comment

by:shlomoy
ID: 6307624
$findme="some text you want to find";
open(IN,$filename) or die "Can't open $filename: $!\n";
$file_content=join '',<IN>;
close(IN);
if ($file_content=~m/$findme/s) {
     # found!
} elsif ($file_content=~m/$findme/si) {
     # found case insensitive
} else {
     #not found!
}
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Expert Comment

by:aravindin2k
ID: 6321213
may be u can say

$word =~ /^(\s|\s+|$search)

by this way u can escape if the space is present like what i mean is that the search will get okay

0
 
LVL 2

Expert Comment

by:hilltop
ID: 6393889
$search =~ s/\n//gs;
0
 
LVL 2

Expert Comment

by:hilltop
ID: 6393915
$search =~ s/\s//gs;
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6802606
Thanks for returning here, and finalizing one open question.  BUT please update and finalize all the other open questions you have as well.  There are 13 of them.....
Some are current, many old.  If you need special handling help in any of them comment with details and I'll respond when I can.  The HELP DESK link on the left provides guidance in terms of Member Agreement, Guidelines and the Question/Answer processes.

If you award anything less than an "A" grade, please be sure to add comments as to why.

http://www.experts-exchange.com/jsp/qShow.jsp?ta=unix&qid=20108784
http://www.experts-exchange.com/jsp/qShow.jsp?ta=progsoftgen&qid=20107243
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cprog&qid=20164605
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20195786
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20263024
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20262125
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20261705
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20259183
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20259140
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20243128
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20201666
http://www.experts-exchange.com/jsp/qShow.jsp?ta=perl&qid=20182968
http://www.experts-exchange.com/jsp/qShow.jsp?ta=perl&qid=20154466

I will monitor them all and update each of them for you with this information so you can quickly and easily navigate through them, and to ensure that you receive Email notifications of these requests.

Expert input is always welcome if more is needed, and/or these remain open after one week so we can determine the fair outcome of the older items.

Thanks all,

Moondancer
Community Support Moderator @ Experts Exchange
0
 
LVL 20

Expert Comment

by:jmcg
ID: 9482509
Nothing has happened on this question in over 12 months.
I will leave a recommendation in the Cleanup topic area that
the answers from ozo and interiot be accepted (25-25 point split).

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now