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

problem in finding files

Hi,

I have created a program to find text files in a particular directory or folder.
and to find a particular word in that files

i finding it difficult to put the list in an array and finding the words

I have pasted the code below

Expand|Select|Wrap|Line Numbers
  1. #to Search word in a text file
  2.  
  3. use IO::File;
  4. use File::Find;
  5. use warnings;
  6.  
  7. find(\&search, "D:/User Profiles/akrishna/Desktop/notes/unix");
  8.  
  9.  sub search
  10.      {
  11.      if ((/\.txt$/) )
  12.      {  
  13.  
  14.      @ext = $File::Find::name;
  15.      print "@ext\n";          
  16.  
  17.  }
  18.  }
  19.  
  20.  
  21. foreach (@ext)
  22. {
  23. #open(my $sen, "<", "a.txt") or die "cant open a.txt";
  24. open(my $sen, "<", $_) or die " can open the file";
  25.  
  26. my @list = <$sen>;
  27.  
  28. close $sen;
  29.  
  30. foreach (@list) {
  31. if ($_ =~ /hi/) {
  32.     print " Found word hi \n";
  33. }
  34. }
  35. }
  36.  
Thanks in Advance
Sep 11 '07 #1
1 1340
KevinADC
4,059 Expert 2GB
There might be other problems, but this line looks suspect:

@ext = $File::Find::name;

@ext will only equal whatever the last value of $File::Fine::name was. Maybe you mean to use the push() function to populate the array.

perldoc: push function
Sep 11 '07 #2

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

Similar topics

15
by: Michael | last post by:
Guten Morgen, I am implementing a script that my client wants on their website. Within the script there are several "require" statements. Any time one of these "require" statements is...
7
by: addled | last post by:
Hi there, after reading posts here for a few months, I've built the courage to see if someone can see where I"m going wrong in the webpage I've been working on. In particular the horizontal nav...
22
by: Tony Houghton | last post by:
I'm using pygame to write a game called Bombz which needs to save some data in a directory associated with it. In Unix/Linux I'd probably use "~/.bombz", in Windows something like "C:\Documents...
2
by: John Jumper | last post by:
I am using an XmlDataSource in VS2005Beta1 and setting the TransformFile property in my ASCX and it is finding both files. However, the resulting data does not contain any of the sub nodes of the...
5
by: Jerry Spence1 | last post by:
I have built a Setup file of my project and when I deploy it on another PC is crashes fairly quickly. I ran Dependancy Walker and found that it couldn't find the following files: MSCORPE.DLL...
4
by: Wolfgang | last post by:
Hi, I want to compress all files (also in subfolder). The code is working more or less, but I get a black popup window (command line window) for every file to compress. How do I cave to change...
6
by: Florian Lindner | last post by:
Hello, I have these class declarations class CBauteil { private: int m_iNumber; int m_iWeight; public: int getNumber(); void setNumber(int);
10
by: Ben Sehara | last post by:
Hi, I want to include three php files in index.php file like the code below. But it always shows up only two, any two of the three, any order. <tr> <td><?php include...
4
by: Poldie | last post by:
I'm using Visual Studio 2005 SP1 on a Win2K SP4 system. VS is set up to use "web development settings ". I use VB. If I create a new web application project, then close the project and exit VS...
0
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
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...
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,...

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.