Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help on

Status
Not open for further replies.

gm199

Programmer
Aug 9, 2001
37
US
I'm doing the same thing over and over again for hours with no results!
Seems very stupid but help me find what is wrong ...

I have two arrays:
@tirar that grabs user form input (checkbox)
@thecats - populated from DB in form of 1|43|56|74 ($mailcats)

The script is supposed to remove the values @tirar from @thecats.

I can print the results after subtract BUT instead of x|y|z I'm getting x|y|z| (note the | at the end)
I can't get rid of the last | no matter what I do.

Code:
my @tirar = $IN->param('apagar');
my @thecats = split(/\|/,$mailcats);
my ($teste,$i);

# unique ---------
my %exclude =  map {$_,$_} @tirar;
@thecats = grep {!exists($exclude{$_})} @thecats;

my $tamanho = @thecats;
for ($i=0;$i<=($tamanho-1);$i++){
	if($thecats[$i] ne ""){
		$teste .= $thecats[$i] . "|"; }
		#$teste .= $thecats[$tamanho];
	}
	$teste .= $thecats[$tamanho+1]; # adding 1 or not doesn't change results?????

I appreciate your help.
 
why don't you just use the join() function?

Code:
my @tirar = $IN->param('apagar');
my @thecats = split(/\|/,$mailcats);
# unique ---------
my %exclude =  map {$_,$_} @tirar;
@thecats = grep {!exists($exclude{$_})} @thecats;
my $teste = join('|',@thecats);

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Kevin,
THANK YOU VERY MUCH.

You amaze me every single time!!!!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top