Why the same script have different behavior when executed in Normalor Debug mode?

Discussion in 'Perl Misc' started by djslls@sina.com, Mar 3, 2009.

  1. Guest

    I'm a beginner in perl. I met a problem today. I don't know why. Here
    is the scenario:

    Test on Windows XP, Perl v5.8.6, Locale: English

    #!/usr/bin/perl
    use strict;
    use warnings;
    use Encode;
    use Text::parseWords qw(parse_line);

    my $teststr="123#abc#xyz";
    $teststr=decode("ascii",$teststr); ###(1) pay attention here

    my @testarray=parse_line("#",0,$teststr);
    my $test=$testarray[0];

    print $test;

    in Normal executing mode, I get "123" in output;
    however, when debugging, I type "p $test" just before the last line, I
    get nothing. It should be "123".

    What happens here? Is there anybody know something about it?

    Thanks in advance!

    ps. if we comment the decode line, the script will work well in both
    mode.
     
    , Mar 3, 2009
    #1
    1. Advertising

  2. Guest

    Re: Why the same script have different behavior when executed inNormal or Debug mode?

    After refreshing perl to v5.10, the problem does not exist any more.

    Thanks, Bob


    On 3ÔÂ3ÈÕ, ÏÂÎç12ʱ12·Ö, Bob Walton <bwal...@nospam..invalid> wrote:
    > wrote:
    > > I'm a beginner in perl. I met a problem today. I don't know why. Here
    > > is the scenario:

    >
    > > Test on Windows XP, Perl v5.8.6, Locale: English

    >
    > > #!/usr/bin/perl
    > > use strict;
    > > use warnings;
    > > use Encode;
    > > use Text::parseWords qw(parse_line);

    >
    > > my $teststr="123#abc#xyz";
    > > $teststr=decode("ascii",$teststr); ###(1) pay attention here

    >
    > > my @testarray=parse_line("#",0,$teststr);
    > > my $test=$testarray[0];

    >
    > > print $test;

    >
    > > in Normal executing mode, I get "123" in output;
    > > however, when debugging, I type "p $test" just before the last line, I
    > > get nothing. It should be "123".

    >
    > > What happens here? Is there anybody know something about it?

    >
    > Well, when I try your program verbatim, it works fine -- "p $test" at
    > the indicated point gives "123":
    >
    > c:\junk>perl -d junk605.pl
    >
    > Loading DB routines from perl5db.pl version 1.3
    > Editor support available.
    >
    > Enter h or `h h' for help, or `perldoc perldebug' for more help.
    >
    > main::(junk605.pl:7): my $teststr="123#abc#xyz";
    >
    > DB<1> n
    > main::(junk605.pl:8): $teststr=decode("ascii",$teststr); ###(1) pay
    > attentio
    > n here
    >
    > DB<1> n
    > main::(junk605.pl:10): my @testarray=parse_line("#",0,$teststr);
    >
    > DB<1> n
    > main::(junk605.pl:11): my $test=$testarray[0];
    >
    > DB<1> n
    > main::(junk605.pl:13): print $test;
    >
    > DB<1> p $test
    > 123
    >
    > DB<2> n
    > 123Debugged program terminated. Use q to quit or R to restart,
    > use o inhibit_exit to avoid stopping after program termination,
    > h q, h R or h o to get additional info.
    >
    > DB<2> q
    >
    > c:\junk>perl -v
    >
    > This is perl, v5.10.0 built for MSWin32-x86-multi-thread
    > (with 5 registered patches, see perl -V for more detail)
    >
    > Copyright 1987-2007, Larry Wall
    >
    > Binary build 1004 [287188] provided by ActiveStatehttp://www.ActiveState.com
    > Built Sep 3 2008 13:16:37
    >
    > Perl may be copied only under the terms of either the Artistic License
    > or the
    > GNU General Public License, which may be found in the Perl 5 source kit.
    >
    > Complete documentation for Perl, including FAQ lists, should be found on
    > this system using "man perl" or "perldoc perl". If you have access to the
    > Internet, point your browser athttp://www.perl.org/, the Perl Home Page.
    >
    > c:\junk>
    >
    >
    >
    > > Thanks in advance!

    >
    > > ps. if we comment the decode line, the script will work well in both
    > > mode.

    >
    > HTH.
    > --
    > Bob Walton
    > Email:http://bwalton.com/cgi-bin/emailbob.pl
     
    , Mar 3, 2009
    #2
    1. Advertising

  3. Re: Why the same script have different behavior when executed inNormal or Debug mode?

    On 2009-03-03, <> wrote:
    *SKIP*
    > #!/usr/bin/perl
    > use strict;
    > use warnings;
    > use Encode;
    > use Text::parseWords qw(parse_line);
    >
    > my $teststr="123#abc#xyz";
    > $teststr=decode("ascii",$teststr); ###(1) pay attention here
    >
    > my @testarray=parse_line("#",0,$teststr);
    > my $test=$testarray[0];
    >
    > print $test;
    >
    > in Normal executing mode, I get "123" in output;
    > however, when debugging, I type "p $test" just before the last line, I
    > get nothing. It should be "123".


    (wild guess) Consider adding explicit newline (C<"\n">) (there're many
    ways to do this in Perl though). That's possible, that your output
    happens to overwritten with debugger's.

    *CUT*

    --
    Torvalds' goal for Linux is very simple: World Domination
    Stallman's goal for GNU is even simpler: Freedom
     
    Eric Pozharski, Mar 3, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Johnny Ruin
    Replies:
    5
    Views:
    504
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,036
    Smokey Grindel
    Dec 2, 2006
  3. Christopher Brewster
    Replies:
    5
    Views:
    349
    John Machin
    Nov 14, 2008
  4. Benman
    Replies:
    0
    Views:
    133
    Benman
    Dec 9, 2005
  5. sg
    Replies:
    4
    Views:
    311
Loading...

Share This Page