They exist both.
chop removes the last character.
chomp removes the last character if it's newline.
To the original problem:
I had a similar problem once.
Maybe your file has DOS-Newlines which are to characters (\r\n).
If you chop, you keep \r at the end which could mess around with
printing it. Perhaps you should try a double chop or something
more sophisticated like:
$string =~ s/[^\da-ZA-Z-_]*$//;
That means remove all on digit (0-9), non word (a-z,A-Z,_-) at the end
of the string.
Please keep in mind that this a bit of a shot in the dark.
So do not:
change code;
sell to customer without testing for big $$$;
call lawyer;
sue collin;
;-)
cr
On Tue, 01 May 2001 09:03:13 -0400, Francis Henry said:
> Craig,
>
> I'm a newbie too, but isn't the function "chomp"?
>
> Francis
>
> Craig Moynes/Markham/IBM wrote:
>
> > A little background. I am running an scp process within a perl script and
> > redirecting the error to a file (scp_err). I then read in the lines of
> > this file and attempt to place them in an error string to log to syslog.
> >
> > Code Sample:
> >
> > #!/usr/bin/perl -w
> > open ( ERR, "<scp_err" );
> > my ( $err_msg ) = "";
> > while ( !eof(ERR) )
> > {
> > my ( $in ) = "";
> > $in = <ERR>;
> > chop $in;
> > print "$in\n";
> > $err_msg = $err_msg . $in;
> > }
> > print "Message - $err_msg\n";
> >
> > Now I have added a lot of extra print statements for debugging purposes.
> >
> > Sample Output:
> > ssh: HOST: Host not found
> > lost connection
> > lost connectionHOST: Host not found
> >
> > The first two lines being each line in the scp_err file, and the last line
> > being the final line.
> >
> > If I remove the chop then it works fine (except for the newline char that I
> > want to remove). If I replace the chop with a s/\n$// then it gives the
> > same output.
> >
> > Any ideas why this is occurring ?
> > -----------------------------------------
> > Craig Moynes
> > Internship Student
> > netCC Development
> > IBM Global Services, Canada
> > Tel: (905) 316-3486
> > [EMAIL PROTECTED]
>
>
>