Link to home
Start Free TrialLog in
Avatar of matgold
matgold

asked on

How to push data to an array?

Can you see why  $ns = blank, when do a print?

open(DAT, "lxfer.tmp") ;
@raw_data=<DAT>;
close(DAT);
open(ORA, ">>list_of_file.bat");
print ORA "cd $rdir\n";
foreach my $filename (@raw_data)
{
   @fname = split(/\s+/, $filename);
   print ORA "get $fname[8]\n";
   print ORA "del $fname[8]\n";
  $ns = "$fname[8]";    
  push(@fles, $ns);      
print  "filename:  $ns\n";
}
print ORA "quit\n";
close(ORA);
#
Avatar of ozo
ozo
Flag of United States of America image

perhaps because $filename  does not have at least 9 whitespace separated fields
Avatar of matgold
matgold

ASKER

there is nothing wrong with $filename.

print ORA "get $fname[8]\n";
print ORA "del $fname[8]\n";

if the two lines above are not blank, then the print command below should have something in it.
$ns = "$fname[8]";    
  push(@fles, $ns);      
print  "filename:  $ns\n";
> if the two lines above are not blank, then the print command below should have something in it
Yes, that is correct.
Can you post the lxfer.tmp file?
Add a

print "$filename\n";

before the

print "filename: $ns\n";

and post the output.

Note that you should also ensure you add error checking in case files can be opened/writen to, eg:

open DAT, "lxfer.tmp" or die "Can not open lxfer.tmp $!\n";

ASKER CERTIFIED SOLUTION
Avatar of matgold
matgold

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial