in reply to Undef values from file open
Did you not see the compilation error?
Global symbol "$rec" requires explicit package name at ./1158543.pl line 27. Execution of ./1158543.pl aborted due to compilation errors.
You never defined $rec.
Update: I'd probably rewrite that like this:
#!/usr/bin/perl use strict; use warnings; use Data::Dump 'pp'; use Data::Dumper; my $file_name = "file.txt"; open my $lines, '<', $file_name or die "Can't open file $file_name, $!"; my @parms = qw( date day name ); while (my $line = <$lines>) { chomp $line; my $data; ( $data->{ date }, $data->{ day }, $data->{ name } ) = split(/,/, $ +line); print "\n $data->{ date }, $data->{ day }, $data->{ name }\n"; pp @{ $data }{ (@parms) }; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Undef values from file open
by Anonymous Monk on Mar 22, 2016 at 20:59 UTC | |
by Mr. Muskrat (Canon) on Mar 22, 2016 at 21:07 UTC | |
by Anonymous Monk on Mar 22, 2016 at 21:12 UTC | |
by poj (Abbot) on Mar 22, 2016 at 21:24 UTC | |
by AnomalousMonk (Archbishop) on Mar 22, 2016 at 21:27 UTC | |
by Anonymous Monk on Mar 22, 2016 at 21:31 UTC | |
| |
|
Re^2: Undef values from file open
by Anonymous Monk on Mar 22, 2016 at 21:26 UTC | |
by BillKSmith (Monsignor) on Mar 23, 2016 at 03:08 UTC |