Thanks for your advice Jim.

Although it makes very good sense to me, I am having a little
difficult implementing it. I will have to admit referencing is still a
bit foreign to me.

I am getting the following error and I am not sure how to fix it.

Type of arg 1 to push must be array (not reference constructor) at
./headers.pl line 11, near "$setref)"
Execution of ./headers.pl aborted due to compilation errors.


### SCRIPT ###

#!/usr/bin/perl
use warnings;
use strict;

use Data::Dumper;

my %seen;
my @header;
my @data;
my $setref = {};
push(\@data,$setref);
my $delim = ",";

while(<DATA>) {
  chomp;

  if(/(.*)=(.*)/) {
    $seen{$1}++;
    $setref->{$1} = $2;

    if ($seen{$1} == 1) {
      push(@header,$1);
    }
  }

  elsif(/^\s*$/) {
    push(@data,$setref);
    print Dumper \@data;
  }
}

print join($delim,@header),"\n";


__DATA__
>csno=1
rfpi=1
vrp0=3423000
vrp1=3423000
trl=1700000
repl=100
repl_d1=100
rrl=20
row[1]=yes
rfpc0=0
rfpc1=0

>csno=1
rfpi=2
vrp0=3423000
vrp1=3423000
trl=1700000
repl=100
repl_d1=100
row[4]=no
rrl=20
rfpc0=0
rfpc1=0

>csno=1
rfpi=3
vrp0=3423000
vrp1=3423000
trl=1700000
repl=100
repl_d1=100
rrl=20
rfpc0=0
rfpc1=0

>csno=2
rfpi=1
vrp0=3423000
vrp1=3423000
trl=1700000
repl=100
repl_d1=100
rrl=20
line=yes
rfpc0=0
rfpc1=0

>csno=2
rfpi=2
vrp0=3423000
vrp1=3423000
trl=1700000
repl=100
repl_d1=100
rrl=20
rfpc0=0
line=value
row[15]=
tti=1
rfpc1=0

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to