Home > Archive > PERL CGI Beginners > December 2005 > indexing... in some way
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
indexing... in some way
|
|
| Adriano Allora 2005-12-11, 6:55 pm |
| hi to all,
this question isn't exactly a cgi-question, but I need to solve this
problem before writing the cgi interface.
I've got a list of tagged files.
I've listed all the couple word+tag.
now, for each word+tag I want to write a file containing all the
filename in which compare the couple.
This is the script:
`sort tagged_files/* | uniq > word+tag.txt`;
open(IDX, "<word+tag.txt");
while(<IDX> )
{
next if /^\W.+/;
open(TMP, ">indexes/$_.txt");
$where = `grep -L '$_' tagged_files/*`;
print TMP $where;
close(TMP);
}
someone would tell me why the line with grep does not work?
Is this the fastest way?
thank you a lot,
alladr
|^|_|^|_|^| |^|_|^|_|^|
| | | |
| | | |
| |*\_/*\_/*\_/*\_/*\_/* | |
| |
| |
| |
| http://www.e-allora.net |
| |
| |
**************************************
| |
| Shawn Corey 2005-12-11, 6:55 pm |
| Adriano Allora wrote:
> `sort tagged_files/* | uniq > word+tag.txt`;
???
All files in tagged_files/* are unique. This looks like a lot of make
work. Try File::Find instead. See `perldoc File::Find`.
> open(IDX, "<word+tag.txt");
> while(<IDX> )
> {
> next if /^\W.+/;
> open(TMP, ">indexes/$_.txt");
> $where = `grep -L '$_' tagged_files/*`;
This says you are looking for the file _NOT_ in the files' content.
Perhaps you want '-l' instead? See `man grep`.
> print TMP $where;
> close(TMP);
> }
>
> someone would tell me why the line with grep does not work?
> Is this the fastest way?
Considering the amount of work this does outside of Perl, no. A shell
script would be faster. (But, of course, anything written in Perl is
automatically better than everything else ;)
--
Just my 0.00000002 million dollars worth,
--- Shawn
"Probability is now one. Any problems that are left are your own."
SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_
| |
| John W. Krahn 2005-12-12, 7:55 am |
| Adriano Allora wrote:
> hi to all,
Hello,
> this question isn't exactly a cgi-question, but I need to solve this
> problem before writing the cgi interface.
>
> I've got a list of tagged files.
> I've listed all the couple word+tag.
> now, for each word+tag I want to write a file containing all the
> filename in which compare the couple.
>
> This is the script:
>
> `sort tagged_files/* | uniq > word+tag.txt`;
perldoc -q "backticks in a void context"
> open(IDX, "<word+tag.txt");
You should verify that the file was actually opened.
> while(<IDX> )
> {
> next if /^\W.+/;
> open(TMP, ">indexes/$_.txt");
You should verify that the file was actually opened.
> $where = `grep -L '$_' tagged_files/*`;
> print TMP $where;
> close(TMP);
> }
>
> someone would tell me why the line with grep does not work?
The string in $_ has a newline at the end.
> Is this the fastest way?
sort -u tagged_files/* > word+tag.txt
grep -L -f word+tag.txt tagged_files/*
Or did you really want to do it in Perl?
Maybe if you could explain in more detail exactly what you want to do?
John
--
use Perl;
program
fulfillment
|
|
|
|
|