Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating an array containing an ls listing

Status
Not open for further replies.

jtripper6

Technical User
Oct 18, 2008
4
US
I need to create an array that contains a list of the files in a directory. I know it needs to be a comma separated list, and I tried using join, but couldn't get it to work the way I hoped it would. I used the following code:

Code:
#!/usr/bin/perl 
  2 @fnames = system ls;
  3 @fnames = join (",",$fnames);
  4 print $fnames[0];
When I print $fnames[0], I want to get the first element in the array, but I get the entire array (without commas). Can someone tell me what I'm doing wrong?
Thanks....
 
system does not return data. Try using qx (same as backtiks):

Code:
$var = qx{ls};
print $var;

see what $var is.


------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Kevin,
Your solution does exactly what I'm looking for. Thank you VERY much!
jt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top