473,408 Members | 2,477 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,408 software developers and data experts.

FileHandle - searching single word from a txt file

16
hello guys

i set this code , and i would like to know if its possible set "quotes" on the searched word.

Thank You


Expand|Select|Wrap|Line Numbers
  1. #word searching program within a txt file
  2. #!C:/perl/bin/perl.exe
  3. start:
  4. #Handle Area - file opening
  5. open FILE, "c:/perl/notice.txt" or die "failed to open notice.txt $!\n";
  6. @read=<FILE>;
  7. close FILE;
  8. chomp @read;    
  9.  
  10. #Searching Area
  11.     print "Search a word\?\n";
  12.         $choose=<STDIN>; chomp $choose;
  13. unless($choose =~/y|Y|[Y,y]es/){
  14.         print "invalid \n"; 
  15.         goto start;
  16. }
  17.  
  18.        print "Type the word\n";
  19.                $choose=<STDIN>; chomp $choose;
  20.                my @result= grep(/$choose/,@read); 
  21.        print "Sorry, this word was not found" unless(@result);  
  22.                foreach(@result) { 
  23.             print "results: ''$_''";               
  24.  
  25.         }
May 26 '09 #1
5 3511
eWish
971 Expert 512MB
If you want the quotes to print just escape them. Or you can do the following.
Expand|Select|Wrap|Line Numbers
  1. my $word = 'perl';
  2. print qq{The word you searched was "$word"};
--Kevin
May 26 '09 #2
Sevla
16
sorry i didnt get what you meant with these codes,
May 26 '09 #3
numberwhun
3,509 Expert Mod 2GB
@Sevla
Try putting the code that eWish has provided into your script and see if it does what you want. The way he has written it, it will print the quotes around one of the words.

You will probably need to read up on the qq as to what it does so you understand.

Regards,

Jeff
May 27 '09 #4
Sevla
16
i see, the results quoted the word i typed on STDIN, but if i would like to keep the whole text line still on the results but with the quote on the exact word i entered on STDIN, ... could it be possible??


Thanks for patience
May 27 '09 #5
eWish
971 Expert 512MB
Yes. Simply use my example from above and replace the text and variables with those from your code.

--Kevin
May 28 '09 #6

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

Similar topics

3
by: Tarrant | last post by:
Hello, I am having amazing difficulties in getting SQL to search for a single word in a text field. I have tried using PATINDEX and LIKE statements but they don't work, sure they 'work', but not in...
5
by: Daniel Walzenbach | last post by:
Hi, I need to know how I could populate a word file from within ASP.NET and stream it out to some user (I can rely on all users have at least Word XP installed). The preferable solution would be...
1
by: Franck | last post by:
Hello, I'm trying to diplay the content of a word file on a aspx page only the content if possible... not the file I tried the folowing but it doesn't work... Response.ContentType =...
2
by: CopynPaste | last post by:
Hi, I wrote a VB.net program that import a text file, which I will parse and place into arrays. My question is how to open an existing Word file without the Dialog Box that has a 4x10 table and...
8
by: John Salerno | last post by:
I figured my first step is to install the win32 extension, which I did, but I can't seem to find any documentation for it. A couple of the links on Mark Hammond's site don't seem to work. ...
5
by: bir | last post by:
I have a folder which contains the xml files with the word CICM in the filename (can also contain some other files) I need to search for all these xml files and create a single zip file for all...
11
by: sandeepkedlaya | last post by:
Hello, I need to copy images from a folder and copy to a word document. I have done as follows.. but It copies only last image. Can any one of you help me in this.. Private Sub Page_Load(ByVal...
1
by: coolminded | last post by:
hi all, i am using vb6 and a listview to display all the records of students. now i want all the details of each student to be exported in word file. i exported in a single column. but i wanted...
2
by: shanmugamit | last post by:
hi, i have 2 lacks word file in that i want search the keyword from that word files. but i using file method it too much time to search data.any one give idea to search data good method like any...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
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...
0
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...
0
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 project—planning, coding, testing,...
0
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...

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.