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

Firstly I is uber newbie @ perl. I'm attempting to write a script that rips out transaction information from a PGP encyrpted email.

Anyway it all works fin except that its handling the string $bob very strangely.

        print "$bob 123\n";

This is just a diagnostic line (as is the one before it). However it writes 123 over the contents of $bob. eg if $bob contained "Hello World", it would display "123lo World".

WTF.

Any help would be really appreciated.

#!/usr/bin/perl -w #use strict; #while (</var/spool/imap/user/matt/VVSettlements/*.>) { while (</tmp/42.>) { open(F, "cat $_ | pgp +batchmode +force +verbose=0 -f -z \"not + much\" 2>/dev/null |"); while (<F>){ if (/(BATCH .*)( 199. | 200. )/) { $year = $2; # print "\n\nSTART".$year."END\n\n"; } if (/SALE .*/) { unshift @a, $&; } } $bob = shift @a; print "$bob 123\n"; print $bob.$year while (defined($bob = shift @a)); }

Replies are listed 'Best First'.
Re: String handling frustrations
by japhy (Canon) on Jul 31, 2001 at 00:33 UTC
    Your string ends in a \r (carriage return). Remove it: $str =~ s/\r$//;. Or remove all of them: $str =~ tr/\r//d;.

    _____________________________________________________
    Jeff japhy Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      Thanks. (test)

      ----------------------
      My very owen signature

Re: String handling frustrations
by ginseng (Pilgrim) on Jul 31, 2001 at 01:01 UTC
      (I think Windows uses just the carriage return, and UNIX uses both?)

      Close, the other way round though;

      • \r\n - Window$
      • \n - *nix
      cLive ;-)

        And, for completeness:

        • \r - MacOS

        This is not a portability issue for scripts (MacPerl Does What You Mean when you print "\n"), but it is for the files containing them. :-)



        If God had meant us to fly, he would *never* have given us the railroads.
            --Michael Flanders

      interesting..

      though jaffy's method works in my case and since pgp is not changing its fine.

      the other thing I could have done I think, would have been to just not include the \r in the first place.

      this is my line

      /SALE .*/

      I would need to modify it so that it goes to the end of the line but doesn't include \r.



      Except I dunno how to do that. :P
      ----------------------
      My very owen signature
        I'm all in favor of sticking with what works, but you may want to check out Ovid's Death to Dot Star. I think it will give you alternatives to your regex, including how to modify to the end of the line.