Viking has asked for the wisdom of the Perl Monks concerning the following question:

The best way to explain this is by showing the code:
for my $key (keys %logins) { my $response = get("http://www.dtdns.net/autodns.cfm?id=$key&p +w=$logins{$key}&ip=$ip"); print "$key: [$response]\n"; }
When I run this I get from the print statement:
key1: [ The Response from key1] key2: [ The Response from key2]
So I decided to strip the \n out of $response so that it was all on one line:
for my $key (keys %logins) { my $response = get("http://www.dtdns.net/autodns.cfm?id=$key&p +w=$logins{$key}&ip=$ip"); $response =~ s/\n//g; print "$key: [$response]\n"; }
Now I get this:
The Response from key1] The Response from key2]
So why do I lose the "key: [" part now that I strip the \n characters?
cheers, Bjorn

Replies are listed 'Best First'.
Re: print not behaving as expected
by merlyn (Sage) on Jan 02, 2001 at 06:59 UTC
      I changed it to $response =~ s/\n|\r//g; and now it works, thanks merlyn
        You ought to change it to:
        $response =~ tr/\n\r//d;
        tr/// is for translating/stripping characters. Save s/// for real regexes :-)