Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Undef values from file open

by Mr. Muskrat (Canon)
on Mar 22, 2016 at 20:56 UTC ( #1158545=note: print w/replies, xml ) Need Help??


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
    typo, Im sorry, its this:
    pp @{ $data }{ (@parms) };

      It works for me.

      1/1/16, Mon, foo ("1/1/16", "Mon", "foo") 1/2/16, Tue, bar ("1/2/16", "Tue", "bar")

      What does your data look like?

        It still prints undefs:
        Test Data:
        01/04/2014,Friday,Joe 02/11/2011,Monday,Mary 05/09/2016,Monday,Ann 07/02/2013,MOnday,Marc
Re^2: Undef values from file open
by Anonymous Monk on Mar 22, 2016 at 21:26 UTC
    Its driving me crazy, I even copied your code and its still:
    (undef, undef, undef) (undef, undef, undef) (undef, undef, undef) (undef, undef, undef) (undef, undef, undef) (undef, undef, undef) (undef, undef, undef) (undef, undef, undef) (undef, undef, undef) (undef, undef, undef)
    Why?? Can't understand it?!!
      You probably have a configuration problem. Download (not cut and paste) Mr.Muskrat's code. Download your own data file and rename it to "file.txt". Run the code that you just downloaded. I have duplicated his results this way.
      Bill

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1158545]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2018-08-20 12:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:









    Results (191 votes). Check out past polls.

    Notices?