Sometimes I want to process a list of “things” easily in PowerShell where the list is not in an external file but in the script itself.
Ideally this list would not be separated by e.g. a comma so it can be easily copy/pasted from external data sources.
Something like this:
powershell
Download
$List = @("
John Doe
Jane Doe
James Bond
And so the list goes on
")With a little trickery we can!
powershell
Download
$List = @("
John Doe
Jane Doe
James Bond
And so the list goes on
") -split "`n" | where {[byte]$_[1] -ne 0x0}
foreach ($Entry in $List)
{
"Performing surgery on $Entry"
}
and people complain about Perl being line noise :D
my @list = qw(one two three four five six seven) ;
for my $entry ( @list ) {
say "The number is $entry" ;
}
Does it work in perl when you split on several lines?
my @list = qw(
one
two
three
...