Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Scalar in structure field name

by dpath2o (Acolyte)
on Sep 30, 2013 at 01:21 UTC ( #1056266=perlquestion: print w/replies, xml ) Need Help??
dpath2o has asked for the wisdom of the Perl Monks concerning the following question:

Dear Perl Monks, I hope a quick question; I had a hard time finding any leads here or here, so I've come here! My problem is that I have a YAML configuration file:

. . . stations : [ ... , ghed, lanc, ... ] . . . ghed : table_type : lluv rdl9 pattern_type : measured lanc : table_type : lluv rdl8 pattern_type : ideal . . .

I read this file in just fine with:

my $params = HFR::SeaSonde::FileOps->new_operation();

which calls the package that, for the purpose of this query, does this:

my $config_file = exists $args{config_file} ? $args{config_file} : +$ENV{"HOME"}.'/acorn_perl.yml'; $self = LoadFile $config_file;

and returning back to the calling script:

my @stations = @{$params->{codenames}->{codar_stations}};

My PROBLEM is this:

foreach my $station (@stations) { my $table_type = $params->{local}->{$station}->{realtime}->{tabl +e_type}; print $table_type."\n"; } exit;

which prints nothing and exits. I know my problem is $station as a 'field name'. Is there a solution to this?

Replies are listed 'Best First'.
Re: Scalar in structure field name (ddumper)
by Anonymous Monk on Sep 30, 2013 at 02:13 UTC

      Jeez! I'm a silly bugger! Sorry for the waste of time here as the problem was completely foolish ...
      here's what I was doing:

      my $table_type = $params->{local}->{$station}->{realtime}->{table_type +};

      and here's what I should be doing:

      my $table_type = $params->{local}->{realtime}->{$station}->{table_type};

      I'll go sit in the corner now with my cap of shame on ...

        To save you some finger strain in the future: all of those ->s beyond the first one are not required.

        my $table_type = $params->{local}{realtime}{$station}{table_type}; Will do the same thing.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1056266]
Approved by mtmcc
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2018-04-26 13:56 GMT
Find Nodes?
    Voting Booth?