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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

open data from aray variable

Status
Not open for further replies.

tom55255

Technical User
Nov 25, 2008
2
GB
Hey,
I am using Perl for two weeks now and I am trying to write a little program that looks up files (*.raw) in a certain directory and then reworks the data in those files and splits them up in little txt files.
There is an error that says it couldn't get the file...
I know It is the link between the aray variable and the scalar variable but I don't seem to get it how to convert them...
It would be most helpfull if anyone could help...
Thanks
Tom


#! C:\Perl\bin\perl.exe
print "Instron data is now converted to individual files!\n";

my $dir = 'D:\Documents\Unief\DataBase\ACCESS\Perl\InputFiles';
opendir DIR, $dir or die "error: cannot open directory \"$dir\" $!";
@rawfiles = sort grep (!/^\.$|^\.\.$/, readdir(DIR));
print "@rawfiles \n";

$filelist = <@rawfiles>;

open(DATA,$filelist) or die "I couldn't get the file";
@filenames = <DATA>;
print @filenames;
close(DATA);

and so on...
 
Hi

You probably want this ( although I am not sure what is your final goal ) :
Code:
[red]foreach[/red] $filelist [red]([/red]@rawfiles[red]) {[/red]

  open(DATA,$filelist) or die "I couldn't get the file";
  @filenames = <DATA>;
  print @filenames;
  close(DATA);

[red]}[/red]

Feherke.
 
I don't understand what this should be
$filelist = <@rawfiles>;

IMHO something like this will do what you want
Code:
use strict;
use warnings;

my $dir = 'D:\Documents\Unief\DataBase\ACCESS\Perl\InputFiles';    
my @rawfiles = glob($dir.'\\'.'*.raw');  

foreach my $file(@rawfiles){
  print "processing file $file...\n"
  # process file
}
 
Hey both!

thanks for the help!!
Both of your solutions worked but there were some more errors further down in my script...but could solve them myself.

thank you very much!
Tom

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top