Advanced-Config

 view release on metacpan or  search on metacpan

t/config/40-validate-modifiers.cfg  view on Meta::CPAN

a2 = ${msg#* }
a2 = ${a2#* }

# Drops the trailing " you send." from ${msg}. -- Can't be nested!
c2 = ${msg% *}
c2 = ${c2% *}

# Just keeps "liberal" from ${msg}.  --  Can't be nested!
e2 = ${msg#* }
e2 = ${e2%% *}

len = ${#msg}         # Returns how long ${msg} is.  65 chars.

# ---------------------------------------------------------------------------

cd = "call die"
# Evaluates :? & ?  --> Call's die if the variable doesn't exist ...
# Commented out ${die1} since calls die while the config file is loading!
# :? Calls die when ${abc} doesn't exist or has no value!
# abc =
# die1 = ${abc:?Did we ${cd} yet?}  # ${abc} doesn't exist, so call die!
# die1 = ${abc:?}                   # ${abc} doesn't exist, so call die with can't msg!
die2 = ${msg:?Will we ${cd}?}       # ${msg} does exist, so die not called!

# ? doesn't call die when the variable is set but has no value.
# So comment out ${abcd} to get things to die while loading!
abcd =
die3 = ${abcd?Did we ${cd} today?}  # ${abc} doesn't exist, so call die!
die4 = ${msg?Will we ${cd}?}        # ${msg} does exist, so call die not called!

# Evaluates :- & -  --> Use a default value if unset!
def0 = The unknown soldier
def1 = ${unknown:-${def0}.}
def2 = ${d:-The known value!}
def3 = ${unknown-${def0} 2.}
def4 = ${abcd-Set to "".}
def5 = ${d-Another known value!}

# Evaluates := & =  --> Assign a Default value if unset!
# Dynamically adds ${zebra} & ${elephant} to the config file.
awa = A
asgn1 = ${zebra:=${awa} wild animal!}
asgn2 = ${zebra:=${awa} wild animal in the Zoo!}
awa = ${awa}nother
asgn3 = ${elephant=${awa} wild animal!}
asgn4 = ${elephant=${awa} wild animal in the Zoo!}

# Evaluates :+ & +  --> Use the Alternate Value if set!
dnu  = Do not use
alt1 = ${unknown:+${dnu}!}               # ""
alt2 = ${d:+Overriding a value is fun!}  # "Overriding a value is fun!"
alt3 = ${abcd:+${dnu}!}                  # ""
alt4 = ${xyz:+${dnu}!}                   # ""
alt5 = ${unknown+${dnu}!}                # ""
alt6 = ${d+Overriding a value is fun!}   # "Overriding a value is fun!"
alt7 = ${abcd+${dnu}!}                   # "Do not use!"
alt8 = ${xyz+${dnu}!}                    # ""

# ---------------------------------------------------------------------------

# Gets the list of variables starting with "y" ...
yellow = bass
list1 = ${!y*}
list2 = ${!y@}

# Indirect variable look ups.
bass = is a fish
indirect1 = ${!yellow}     # Should say "is a fish"!
indirect2 = ${!YELLOW}     # Should say ""!

book = Chapter123
all  = ${book%%[0-9]*}     # Should be Chapter

# ---------------------------------------------------------------------------
# Search and replace withing a given string ...

# Existing var ${msg}
sub_01 = ${msg/in/by}          # Replaces 1st occurance of "in" ...
sub_02 = ${msg//in/by}         # Replaces all occurances of "in" ...

# No-such var ${msg2}
sub_03 = ${msg2/in/by}         # Result: ""
sub_04 = ${msg2//in/by}        # Result: ""

# Existing var ${msg}
sub_05 = ${msg/in/}
sub_06 = ${msg//in/}

# Existing var ${msg}
sub_07 = ${msg/in}
sub_08 = ${msg//in}

sub_09 = "xxx xxxxx"
sub_10 = ${sub_09/#x/Y}        # Result: Yxx xxxxx
sub_11 = ${sub_09/%x/Y}        # Result: xxx xxxxY
sub_12 = ${sub_09/#x}          # Result: xx xxxxx
sub_13 = ${sub_09/%x}          # Result: xxx xxxx

# Parsing sub-strings from a longer string ...
# Putting between quotes so leading/trailing spaces are preserved.
sub_14 = "${msg:34}"           # Result: " conservative in what you send."
sub_15 = "${msg:34:13}"        # Result: " conservative"
sub_16 = '${msg: -11:5}'       # Result: 't you'
sub_17 = "${msg:(-11):5}"      # Result: "t you"
sub_18 = "${msg:11:-18}"       # Result: "in what you accept, and conservative"
sub_19 = "${msg:(-2):-1}"      # Result: "d"
sub_20 = "${msg:(-2):-3}"      # Result: ""  (an error in bash)
sub_21 = "${msg:34:0}"         # Result: ""

# ---------------------------------------------------------------------------
# An exersise in shifting case in a string ...

xcase_00 = "ThIs Is OnE fInE mEsS wE'rE iN!"
xcase_00_opt = "^^"

xcase_01 = ${xcase_00~~}       # Result: Reverses the case of the entire string!
xcase_02 = ${xcase_00~}        # Result: Reverses the case of the 1st char in the string!

xcase_03 = ${xcase_00^^}       # Result: Shifts ${xcase_00} to upper case!
xcase_04 = ${xcase_00,,}       # Result: Shifts ${xcase_00} to lower case!



( run in 0.534 second using v1.01-cache-2.11-cpan-39bf76dae61 )