Find the answer to your Linux question:
Results 1 to 8 of 8
OK...I'm re-writing my IRC bot (after a bad incident with rm and a misplaced *). This time, I'm using modules to make everything look better. Here's the code that is ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Guru sarumont's Avatar
    Join Date
    Apr 2003
    Location
    /dev/urandom
    Posts
    3,682

    Perl Help


    OK...I'm re-writing my IRC bot (after a bad incident with rm and a misplaced *). This time, I'm using modules to make everything look better. Here's the code that is giving me problems:

    Code:
    sub quoteAdd
    {
            my $path = $_[0];
            my $quote = $_[1];
            my $addedBy = $_[2];
                                                                                                    
            chomp( $quote );
                                                                                                    
            open( QUOTE, ">>$path/quotes.txt" ) or return( 1 );
                                                                                                    
            print QUOTE "^C15,1$quote ^C0(^C13added by ^C9$addedBy^C0)\n";
                                                                                                    
            close QUOTE;
            return( 0 );
                                                                                                    
    }
    And the call from the main program:

    Code:
    		if( $text =~ /^!addquote/ )
    		{
    			chop( $text );
    			( my $junk, my $quote ) = split( /!addquote /, $text );
    			my $result = &Quote::quoteAdd( $path, $quote, $nick );
    Now...this works fine and dandy except for the fact that it inserts a wierd character (^M) into the string.

    ^C15,1WELCOME TO CORNERIA!^M ^C0(^C13added by ^C9sarumont^C0)
    It shows up in gedit as a line break and a space on the new line...but I can't figure out where it's coming from or why. Anyone have a clue?
    "Time is an illusion. Lunchtime, doubly so."
    ~Douglas Adams, The Hitchhiker's Guide to the Galaxy

  2. #2
    Linux Guru sarumont's Avatar
    Join Date
    Apr 2003
    Location
    /dev/urandom
    Posts
    3,682
    I seem to remember that the ^M is like a DOS line break?

    /me shrugs.

    That still doesn't explain how it gets into the middle of my string...
    "Time is an illusion. Lunchtime, doubly so."
    ~Douglas Adams, The Hitchhiker's Guide to the Galaxy

  3. #3
    Linux Engineer Giro's Avatar
    Join Date
    Jul 2003
    Location
    England
    Posts
    1,219
    try dos2unix it will strip all control charecters out.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Newbie
    Join Date
    Aug 2001
    Location
    USA, Texas
    Posts
    217
    do an s/\^M//g; on it before printing. though you may have to actuall type CTRL+V then M I think instead of \^M as 3 chars. if you use the CTRL+V M you could probably leave out the \
    [ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ];
    /* Don\'t make me use it! */

  6. #5
    Linux Guru sarumont's Avatar
    Join Date
    Apr 2003
    Location
    /dev/urandom
    Posts
    3,682
    I tried this:

    Code:
    $quote =~ s/\^M//;
    and it did nothing.

    Tried it with the 'g' at the end and without the \, but still nothing.
    "Time is an illusion. Lunchtime, doubly so."
    ~Douglas Adams, The Hitchhiker's Guide to the Galaxy

  7. #6
    Linux Guru sarumont's Avatar
    Join Date
    Apr 2003
    Location
    /dev/urandom
    Posts
    3,682
    Ahem...nvm...copy/pasted the character in mc and it ended up working (with the 'g' only, though).

    Thanks guys.

    "Time is an illusion. Lunchtime, doubly so."
    ~Douglas Adams, The Hitchhiker's Guide to the Galaxy

  8. #7
    Linux Engineer kriss's Avatar
    Join Date
    Jun 2003
    Posts
    1,113
    So... are #linuxforums getting a bot soon?

  9. #8
    Linux Guru sarumont's Avatar
    Join Date
    Apr 2003
    Location
    /dev/urandom
    Posts
    3,682
    As soon as I get the admin./chan. moderation things on him, I'll throw him in.
    "Time is an illusion. Lunchtime, doubly so."
    ~Douglas Adams, The Hitchhiker's Guide to the Galaxy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •