You are not logged in.
Announcement
Unanswered posts
|
Pages: 1

Hi,
I am tired of typing @output_row[0] = trim(@output_row[0]);
@output_row[1] = trim(@output_row[1]);
ect...
for every element in my array. How can I write code that will apply the trim function to every column using the @output_row array, so I only have to type this once? I'm trying a foreach loop but I just can't seem to figure it out (the output is always a one column dataset, with the value of the column = 4).
Thanks,
Michael
Offline
Hello
Perl does not have a built-in trim function. You need use tPerl component to define a trim function first, eg:
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}Best regards
shong
Offline

Thanks Shong,
I'm sorry, I was unclear. I have built the trim function--What I'd like to do is apply it to all columns in an array without needing to write a line of code invoking the function for each column.
I was hoping something like @output_row = trim(@input_row) in a tperlrow node would work, but it doesn't. I've tried building a subroutine using a foreach loop and failed there as well.
Any idea how to accomplish this?
Thanks,
Michael
Offline
Hello
but it doesn't. I've tried building a subroutine using a foreach loop and failed there as well.
Yes, if there are so many columns, it is a big work to write each line of code invoking the function for each column. Using a foreach loop could be a good solution.
for example:
on tPerlRow:
for ($count = 0; $count <=3; $count++) { #suppose there are 4 columns
@output_row[$count] = trim(@input_row[$count]);
}Best regards
shong
Offline
Pages: 1