473,379 Members | 1,533 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,379 software developers and data experts.

How to search a word from a text using perl

Hello Sir/Madam,
I am writing a perl script to find a word from a file..

Expand|Select|Wrap|Line Numbers
  1. #!/usr/local/bin/perl
  2. unless (open(VINODH, "vinodh.txt")) { die("Cannot open input file vinodh.txt")        }
  3. $line=<VINODH>;
  4. $count = 0;
  5. while ($line ne "") {
  6.     chop($line);
  7.     @words = split(/ +/, $line);
  8.     print ("@words \n");
  9.         $count += @words;      
  10.         $line = <VINODH>;
  11.         }
  12. print ("Total no. of words: $count \n");
  13.  
In this program I want print the @words array out of the while loop so that i will proceed with the follwing steps:

Expand|Select|Wrap|Line Numbers
  1. $count1 = 0;
  2. if($count1<=$count && $words[$count1] =~ /^<table>$/){
  3. $count1 += $count1;
  4. }
  5. print("$count1");
  6.  
what should i do now..
Sep 16 '07 #1
2 12318
So what exactly is your input/desired output? Do you want to input a word, such as "foobar" and then output the positions that the word occurs in the text?

If so, using regular expressions would be a much simpler way to do this than what you have done so far.

Reply with more info and we can help you better :)
Sep 17 '07 #2
numberwhun
3,509 Expert Mod 2GB
So what exactly is your input/desired output? Do you want to input a word, such as "foobar" and then output the positions that the word occurs in the text?

If so, using regular expressions would be a much simpler way to do this than what you have done so far.

Reply with more info and we can help you better :)
Agreed! More information (specifically a better description of exactly what you are trying to do) along with a sample of the data you are referencing would be wonderful and extremely helpful.

Regards,

Jeff
Sep 17 '07 #3

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

Similar topics

0
by: Zak Chababe | last post by:
Hi, We are in the process of converting thousands of MS word documents into some sort of database files like sql or comma separated files. Is there something out there with Perl that allows me to...
1
by: anilraja | last post by:
how to search within text using vbscript?
3
by: f6600840 | last post by:
Hi, What function I should use if I want to clean text using perl. Example. Input for my perl based shell command is SMI-1234 566.5.2.3.4.5.5.192.168.1.1 = "huuhaa" : SMI-1234...
2
by: pramodkh | last post by:
Hi All I am parsing a word doc using perl. I am using Win32::OLE module for this. I am able to get the Paragraphs/styles/Text from the word doc. But facing some problem when I am trying to get...
4
by: phoenie | last post by:
Hi everyone, I am a newbie in Perl. I would like to know how to extract the abbreviation from a given text using Perl. For example, Dr. Alex is a very smart doctor. He is from USA. Then my...
10
by: islayer | last post by:
i am trying to write a dictionary using perl, the program would use a primary .pl file, and a text file, designated .dat i have no programing background, and am trying to teach myself perl, and...
3
by: flow3rgirlz | last post by:
Hi all, I'm really new to Perl. I'm not sure where to post my topic as it between Perl and Visio. Anyway, I want to run a Visio macro automatically using Perl Script. $vis->Run($macro_to_run);...
0
by: Pramod Elig | last post by:
I developed this code which works fine in my current system which has office 2007, but when I run in word 2000 this doesn’t work. Can you please help me to code word automation using late binding. I...
13
by: Elizabeth H | last post by:
Hi, I had a few questions regarding searching for a string and replacing it using perl scripts. I have 100's of files written in Unix shell scripts and I need to edit them all. Its like ...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.