Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Executing perl code

by pglenski (Beadle)
on Feb 13, 2013 at 18:16 UTC ( #1018592=perlquestion: print w/replies, xml ) Need Help??
pglenski has asked for the wisdom of the Perl Monks concerning the following question:

Hello I am using the module Excel::Writer::XLSX written by John McNamara. It work's great. I have written a perl script which reads a cvs file and then creates a spreadsheet. The module has many characters you can set, such as:
$worksheet = $workbook->add_worksheet(); $workbook->set_landscape() $workbook->set_freeze_panes(2,0)
I would like to populate the settings in a flat file such as:


hide_gridline(), etc

and then have my script read and execute the settings. I know this doesn't work but this is what I want it to do:
while(<IN>) { chomp; $worksheet->$_ }
Is there someway to do what I want?

Replies are listed 'Best First'.
Re: Executing perl code
by SuicideJunkie (Vicar) on Feb 13, 2013 at 18:53 UTC

    Just make sure nobody types "format c:" into that configuration script!

    A much safer way to go about it is to read the config file and look up the provided command in a hash to make sure it is legit.

    my ($cmd, @params) = split ',', <$inputFileHandle>; if (exists $hashOfAllowedCommands{$cmd}) { $worksheet->$hashOfAllowedCommands{$cmd}->(@params) }else{ print "Invalid command ignored in config file at line $.\n"; }

    If you still want to play with the dynamite then take a look into eval

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1018592]
Approved by ig
Front-paged by Corion
[choroba]: $array[0]{key1}[1] {key2}
[thepkd]: ??
[GotToBTru]: I would think temporary variables would help in making the real life meaning of your structure clear
[choroba]: the problems start when you want to "skip a level", i.e. the arrays for all the keys
[LanX]: what are temps?
[moritz]: oh, the question was about creation, not indexing
[thepkd]: temporary variables
[moritz]: [ { a => [ { b => 1 } ] } ]
[choroba]: dereference ne creation
[choroba]: at least in my lingo

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (13)
As of 2016-12-06 13:18 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (104 votes). Check out past polls.