Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: quston n File::Find

by 2teez (Priest)
on Oct 30, 2012 at 09:54 UTC ( #1001481=note: print w/ replies, xml ) Need Help??


in reply to question n File::Find

Here are some of the things I spotted in your wanted sub. open temp_file_cy, "$File::Find::name;

  1. I think you want to use a lexical variable my $temp_file_cy instead of a bareword temp_file_cy as your file-handle
  2. then, "$File::Find::name has only one quote at the beginning.
  3. If you may, use 3 agrument open function, then check error if file is not opened
  4. I will advise you use warnings and strict in your script. As it shows several 'mis-typed' variables. It will help alot
UPDATE:
With a second check on the usage of the file test using "-r" in this line:
print "hello 1\n" if (-r tep_file_cy);
check perldoc -f -r
-r File is readable by effective uid/gid.
If 'tep_file_cy' is the file you trying to check up, not been used as file-handle.
Except, you have something else in mind.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me


Comment on Re: quston n File::Find
Select or Download Code
Re^2: quston n File::Find
by skyworld_chen (Acolyte) on Oct 30, 2012 at 12:09 UTC

    thanks for your kind reply.

    a) in fact I insert"use warnings" and "use strict" in my code. I just omitted them for simple demo of my code. And in my real code I didn't miss quote, it is a type error here. Any way, thanks for your kind remind.

    b) accroding to your ideas,I use

    open $temp_file_cy, "$File::Find::name"

    it is interesting that I haven't see "open $filehandle ...", but always "open filehandle ...". in the text book. Can you tell me the difference between them? thanks.

    c) I have checked the attributes of those files, they are all -rw-rw----, so I guess "-r " should be ok here. In fact what I want to do really is this:

     my @matching = grep {/$pattern/} <temp_file_cy>;  

    I always get this message: " readline() on unopened filehandle temp_file_cy at ../cy_find line 99", which make me to insert code "-r temp_file_cy" to see what happened

    can you give me some help on this? thanks

      Maybe there was an error in opening the file. Try autodie or check for errors like this:
      unless (open my $filehandle,"<",$File::Find::name) { warn $!; return; }
      Sorry if my advice was wrong.

        Hi,

        thank your for your advice. I used your advice in my code and this time the error message is as this:

        "No such file or directory at ......."

        I'm sure there are those files and I checked the log to find all "No such file" are files under sub-directory. I guess this maybe a "problem" of File::Find? or maybe I used something wrong in my code? thanks.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (11)
As of 2015-07-07 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls