in reply to Re: Problem with foreach loop
in thread Problem with foreach loop
So is there a problem using Tie::File? Thanks#!/usr/bin/perl use strict; use warnings; use Tie::File; use Fcntl; #Variable Declaration my @array; my $line=""; my @data; my $map_dir=""; my $dir=""; my $part_no=""; my $chg_lvl=""; my $int_lock=""; my $t_spec=""; my @list=""; my $formatted_list=""; my $i; #Program Main if ($#ARGV == -1) { print "\n"; print "Enter a file containing part number, <R> to Quit: "; chomp($file_name=<>); } else { $file_name=$ARGV[1]; } open (FILE,"$file_name"); ########## These two lines are commented out ################### #tie (@data,'Tie::File',$file, mode=>O_RDWR) or die "Can't tie to $fil +e:$^E\n"; #(tied @data)->defer; ############## ##I am reading the file as an array here ################ @data=<FILE>; foreach (@data) { ($map_dir,$dir,$part_no,$chg_lvl,$int_lock,$t_spec) = split /\s+/; print "@list"; print "$formatted_list"; print " $map_dir,$dir,$part_no,$chg_lvl,$int_lock,$t_spec"; } #(tied @data)->flush;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Problem with foreach loop
by roboticus (Chancellor) on Jan 25, 2008 at 18:20 UTC |