Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: I want specific word to be stored in a CSV file

by Laurent_R (Canon)
on Jun 20, 2015 at 11:28 UTC ( [id://1131253]=note: print w/replies, xml ) Need Help??


in reply to I want specific word to be stored in a CSV file

This code line is probably not doing what you think (although I am not completely sure of what you think it does) :
@files = grep("EXP", readdir(DIR));
In Perl, the grep function takes an array or a list of items, applies the piece of code supplied as a first argument, and returns the items for which this piece of code evaluates to true.

If you are looking for "EXP" in the file names, then you could try to change it to:

my @files = grep { /EXP/ } readdir(DIR);
which would give you an array of file names matching the /EXP/ pattern.

The second error in your code is that the readdir operator returns a list of files without the path, so that you need to prefix the file names with the $directory variable to be able to open them. Using the glob function might be easier and provide the file list, with the path, in a single step, for example you might try something like this:

my @files = glob ("/home/grds/datafile/*EXP*.*");
You haven't said enough for me to be able to provide more guidance at this point.

Update: fixed a typo.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1131253]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-24 22:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found