in reply to Re: Parsing a config file
in thread Parsing a config file

OK moving further along this vein:
#!/usr/bin/perl -w use strict; use diagnostics; use Data::Dumper; my $config="/var/www/cgi-bin/prt.cfg"; open (CFGFILE,$config) || die "unable to open $config: $!\n"; my (@server,@arrayref); foreach $_(<CFGFILE>) { chomp; next unless /^\w/; @server=split(/,/,$_); push (@arrayref, [ @server ]); } print "servers: $arrayref[0][2]";
what if I want to call all servers?
ie print "servers: $arrayref[0 ... $#arrayref][0]
I know that wont work, but it best explains what I want to do...

Replies are listed 'Best First'.
Re^3: Parsing a config file
by Random_Walk (Prior) on Mar 10, 2005 at 17:24 UTC

    you need to loop through the array holding the refs and de-ref the bits you want to print...

    print "$_->[0]\n" for @arrayrefs # or map may be your friend print "servers: ", (join ", ", map {$_->[0]} @arrayrefs), "\n";
    BTW you can also get rid of the intermediate array @servers by just throwing split straight into an anonymous array
    push @arrayrefs, [split(/,/,$_)];

    Cheers,
    R.

    Pereant, qui ante nos nostra dixerunt!