Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Looking up elements of an array in another array!

by better (Acolyte)
on Mar 14, 2013 at 23:38 UTC ( [id://1023580]=note: print w/replies, xml ) Need Help??


in reply to Re: Looking up elements of an array in another array!
in thread Looking up elements of an array in another array!

Hello Kenosis,

thanks a lot for your help. Unfortunately it doesn't help. The last entry (>outFile) causes an error. But if I skip that, nothing happens. (But the Ids given in indexDS.txt are matching filenames of the scanned directory) Any suggestions?

better

  • Comment on Re^2: Looking up elements of an array in another array!

Replies are listed 'Best First'.
Re^3: Looking up elements of an array in another array!
by kielstirling (Scribe) on Mar 15, 2013 at 00:18 UTC
    replace the [>outFile] with >outFile ... this is redirecting stdout to the file outFile in the current directory.
Re^3: Looking up elements of an array in another array!
by Kenosis (Priest) on Mar 15, 2013 at 02:06 UTC

    kielstirling ++ is right on target, and my apologies for not explaining the [>fileOut] parameter. This designates an optional argument that's used to direct output to a file, instead of the screen. So, for example, you could do the following on the command line:

    perl script.pl '/the/dir/to/scan' indexDS.txt >results.txt

    Thus, instead of printing to the screen, output's directed to a file. Omitting the last parameter will just print the results to the screen.

      Thanks again, Kenosis. Yes, indeed. Entering the third option without brackets, does create a text file, but without any results(?) The files, I am looking for, however do exist in the directory. So they should be found.

      Hmm.. If I get the two arrays (@ds and @dirFile) in my script listed, I can see that grep /$line/ should find the matching elements in the second array. But @results keeps beeing empty. The funny thing is: if I define @ds writing some of the wanted IDs directly into the script

       @ds = ("I C 7702", "I C 7710");

      the script works perfectly. But I want the array filled by reading a long list of IDs from a text file. Any idea what is going wrong?

        Hi better,

        The files, I am looking for, however do exist in the directory. So they should be found.

        To start with Kenosis' script should work. I tried it, using your description of the problem you posted and I have outputs, though similar filenames which were not included in the "indexDS.txt" were also printed.

        Secondly, how are you using the script, maybe you have some other code over-writing the variable "@result"
        Hope this helps.

        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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-25 17:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found