Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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
[jedikaiti]: Pretty!
[erix]: ( TBH, I think it's a load of bull -- but maybe I'm mistaken )
[erix]: Hey that's Hungary - wave down ambrus and tell him to reboot his systems!
[choroba]: it might be a problem if you expect to reach the maximal possible value soon without squashing the ids
[erix]: that's really impossible with bigint
[erix]: and the site is still only 'hopefully' active :)
[erix]: but fair enough, he may think he solves a problem

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2017-06-23 15:45 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (551 votes). Check out past polls.