R
Robert TV
I am trying to manipulate the data of my @rray based on the first character
of each array element. My array contains many names sorted alphabetically.
EG:
Adam
Aron
Brian
Bert
Chris
Daniel
Derk
Ernie
Frank
and so on ....
Now, I want my script to dected the first letter of the name and take action
based on it like this:
foreach $name (@names) {
if (first letter of $name eq "A" or "a") {
$condition = "True";
$name = "A:$name\n";
} else {
$condition = "False";
}
}
So if the above syntax was valid, the names in the @rray would now print
like this:
A:Adam
A:Aron
Brian
Bert
Chris
Daniel
Derk
Ernie
Frank
I realize the script above will only do "A" ... and i'll need to figure out
how to do the whole alphabet ... but one step at a time, still need some
help how to detect the first letter and take action if conditions meet. TIA
Randy
of each array element. My array contains many names sorted alphabetically.
EG:
Adam
Aron
Brian
Bert
Chris
Daniel
Derk
Ernie
Frank
and so on ....
Now, I want my script to dected the first letter of the name and take action
based on it like this:
foreach $name (@names) {
if (first letter of $name eq "A" or "a") {
$condition = "True";
$name = "A:$name\n";
} else {
$condition = "False";
}
}
So if the above syntax was valid, the names in the @rray would now print
like this:
A:Adam
A:Aron
Brian
Bert
Chris
Daniel
Derk
Ernie
Frank
I realize the script above will only do "A" ... and i'll need to figure out
how to do the whole alphabet ... but one step at a time, still need some
help how to detect the first letter and take action if conditions meet. TIA
Randy