in reply to Re: reference question yet again
in thread reference question yet again

what is wrong with this script now? since I have to expand a @attrs_results I thought I could break it down below but program says _status is not recognzized all the way at the bottom when I try to extract it.
use strict; use Text::CSV_XS; my @data; my $count = 0; input (); my @attrs_stop = qw( _status _gwname _ac_ID_field); my @attrs_attempt = qw( _status _gwname _ac_ID_field); sub input { my $csv = Text::CSV_XS->new; while ( <DATA> ) { chomp; next if /^START/; $count++; $csv->parse($_); my @fields = $csv->fields; my %rec; my @attrs_results; if (/^STOP/) { @attrs_results = @attrs_stop; } else { @attrs_results = @attrs_attempt; } @rec{@attrs_results} = @fields; push @data, \%rec; } } foreach my $info (@data) { print "$info->{_status}\n"; } print "There were $count calls\n"; __DATA__ adfadfasdfadsf,"adsf,asdf,adsf",adfasdf adsfasdfasdfasdf,asdfasdfasdf,adsfasdf adsfasdf,"adsf,adsf",adsfadsf "asdfasdf,asdfasdf",adfasdf,asdfasdf

Replies are listed 'Best First'.
Re^3: reference question yet again
by almut (Canon) on Sep 10, 2007 at 00:07 UTC
    what is wrong with this script now?

    You're calling your input() routine before you've set up the arrays @attrs_stop and @attrs_attempt that you're using in the routine...

      gosh.. thank you.
Re^3: reference question yet again
by TGI (Parson) on Sep 10, 2007 at 17:31 UTC

    Be careful with those global variables. @data worries me.

    Why not let input() return an array ref?

    my $data = input(); foreach my $info (@$data) { # do other stuff } # ------------------ sub input { my @data; # do stuff return \@data; }


    TGI says moo