Re: put find output in an array



how do I get this into an array?

In the Korn Shell there is an ability to execute a command and put the
results into an array:

#!/bin/ksh
set -A myarray $(find ./ -name "*.pl")
let count=0
while (( $count < ${#myarray[*]} )); do
echo FILE: ${myarray[count]}
let count="count + 1"
done

Also, you could use perl:

#!/usr/bin/perl
open FINDEM,'find ./ -name "*.pl" |' or die "Cannot open pipe: $!\n";
@findarr = <FINDEM>;
for ($i = 0; $i <= $#findarr; $i++) {
print "FILE: $findarr[$i]";
}

You can also use this perl:

#!/usr/bin/perl
@findarr = `find ./ -name "*.pl"`;
for ($i = 0; $i <= $#findarr; $i++) {
print "FILE: $findarr[$i]";
}

But, I think the backtick ( ` ) operator has been deprecated and may
not be available in current or future versions of perl. I'm using
version 5.8.0 of perl -- not sure if this is current.

I didn't use your exact find command for my testing purposes. This will
at least give you a head start.

Hope this helps.

Art Ramos

.



Relevant Pages

  • Re: SQLPlus with Perl
    ... knowledge of the Perl programming language. ... The stuff within qxis a UNIX command string. ... the sql to sqlplus. ... this by assignment to an array. ...
    (comp.lang.perl.misc)
  • Re: Wait for background processes to complete
    ... To be able to execute commands in the background and wait for their ... The documentation I am referring to is http://perldoc.perl.org/. ... You can run a command in the background with: ... There is a general problem with perl documentation: ...
    (comp.lang.perl.misc)
  • Re: Perl For Amateur Computer Programmers
    ... >professional computer programmers could use with the same ease as Basic. ... >Perl For Amateur Computer Programmers ... Also, taking into account that you're appealing to "scientists", it ... Also, as a side note, you seem to use the noun "command" in a naive ...
    (comp.lang.perl.misc)
  • Obtaining complete Unix command line that evoked script as string
    ... If there is a more appropriate list for this, let me know; the other perl lists I've seen seem to specialised for this. ... Note this is not just the arguments of the call to the script, but everything including pipes and redirects, etc., e.g. ... Ideally the perl interpreter would grab the complete command line as its evoked and I'd access this via a variable. ...
    (perl.beginners)
  • Re: When MUST you use map ?
    ... > In my limited experience with perl, I've never had to use the 'amp' ... > So, when do you HAVE to use 'map', when no other option makes sense?! ... Reverse an array without using reverse: ...
    (perl.beginners)