ok, all you perl guys who were here last night, help me out.

notfred

Lifer
Feb 12, 2001
38,241
4
0
look at this code fragment:
--------------------------------------------------------------
for(my $i=0; $i<=$#users; $i++){
if($users[$i][0] eq $name){
chop($users[$i][2]);
my @projects = split(/,/, $users[$i][2]);
return @projects;
}
}
--------------------------------------------------------------

it works fine. However, to get it to work CORRECTLY, I have to replace the 'chop' with a 'chomp'.

If I do that, it doesn't work. it wont remove the trailing newline with a chomp. I've tried about everything I can think of, and nothing is working.

It's redhat 7.1 running perl 5.6.0.

This is pissing me off...


edit: posted blank message.
 

crackersjacks

Member
Aug 29, 2001
156
0
0
What is chomp removing when you use it?
Sorry if I'm not any help, I've been up for 43 hours straight and I can't even read my own Perl now.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
ugh. $/ is set to ascii 010 when run on the server, and \n is 013, at least on my editing box....

hmm......

well, now that I know how to fix it, how do I force 010 or 013?
 

crackersjacks

Member
Aug 29, 2001
156
0
0
I'm not sure I understand what you're asking (Sorry, I'm beat and ready to pass out). Do you just want to set it to the newline before your code? Something like: local ($/) = "\n"; perhaps?
Edit for lack of semicolon goodness
 

notfred

Lifer
Feb 12, 2001
38,241
4
0


<< I'm not sure I understand what you're asking (Sorry, I'm beat and ready to pass out). Do you just want to set it to the newline before your code? Something like: local ($/) = "\n"; perhaps?
Edit for lack of semicolon goodness
>>



tried that, whole script bombed.

Apparently, sometimes the newline is ascii character 10, and sometimes it's 13, and chomp is only worknig when it's 10....
 

notfred

Lifer
Feb 12, 2001
38,241
4
0


<< Well, that just sucks, I don't really know what else to tell you, sorry I couldn't be more help. >>



43 hours is too long to be up, go to bed :)
 

crackersjacks

Member
Aug 29, 2001
156
0
0
Oh how I wish I could. Unfortunately this is kind of a graduate or don't graduate deal. Woohoo, two all-nighters for me...so pleased.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0


<< Oh how I wish I could. Unfortunately this is kind of a graduate or don't graduate deal. Woohoo, two all-nighters for me...so pleased. >>



argh, chomp's an asshole. stupid chomp.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
well, here's my idea (not tested yet): Instead of chomp($string);

I get to do:

if(substr($string, length($string)) == chr(10) || substr($string, length($string)) == chr(13)){chop($string)}

I think it'll work.
 

Geforcekj

Banned
Apr 19, 2001
1,260
0
0
ok I just thought I'd let you know I don't understand any of that...sorry I couldn't be of more help....
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
ah, instead of that big long giant thing with substr and stuff in it, I'm using this regex: s/[^ -~]//g;

:)