user3350919 user3350919 - 22 days ago 6
Perl Question

creating array fields under 'ifdef using perl

I'm writing a script that creates a database of name, and this database have different versions.
My script is getting the version as input (it has a default version in case of no input)
each database version is based on the previouse versions, but contains some additional names.

I'm trying to find a way to define some of the enteries to my array as a function of the iversion.
Therefore im using something like verilog IFDEF

for example:

my @DATABASE = (
"Arik",
"Ben",

if ($version = 1.3) {
"Suzie",
"Dan",
}

"Roth"
);


at this example, the names Arik,Ben and Roth will be at the data base for all versions, but Suzie and Dan will only be at the version 1.3 database

Is there a good way to do that?

Answer

It's not clear what you want, but this may help

use strict;
use warnings;

use Data::Dump;

my $version = '1.3';

my @database = (
    "Arik",
    "Ben",
    $version eq '1.3' ? (
      "Suzie",
      "Dan",
    ) : (),
    "Roth",
);

dd \@database;

output

["Arik", "Ben", "Suzie", "Dan", "Roth"]