Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
444 views
in Technique[技术] by (71.8m points)

perl - push not appending to the end of the array

  DB<2> n
  main::(/home/repsa/temper.pl:84):  my $tttdiskhumber=$myTemprecord[-1];
   DB<2> n
  main::(/home/repsa/temper.pl:87):  push(@myMainrecord,$tttdiskhumber);
   DB<2> p @myMainrecord
   t2agvio701vhost03t2adsap7011
   DB<3> p $tttdiskhumber
  hdisk6
   DB<4> n
   main::(/home/repsa/temper.pl:88): @myTemprecord=();
    DB<4> p @myMainrecord
    hdisk6o701vhost03t2adsap7011
   DB<5>

Why my last push is not appending to the end of the array? Any help is appreciated....

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

oh it is. The problem is that you're sending a carriage return to the screen. It's probably trailing the previous element in the array.

$ perl -e'print "abc", "def
", "ghi", "
";'
ghidef

You probably read a Windows text file on a non-Windows system without convert the line endings, either in advance (using dos2unix) or when you read the file (by using s/s+z//; instead of chomp;).


As jordanm suggested in a comment, the debugger's x command will show you what you have better than p.

$ perl -d

Loading DB routines from perl5db.pl version 1.33
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

my @a = ("abc", "def
", "ghi");
1;
^D
main::(-:1):    my @a = ("abc", "def
", "ghi");
  DB<1> s
main::(-:2):    1;
  DB<1> p @a
ghidef
  DB<2> x @a
0  'abc'
1  "defcM"
2  'ghi'
  DB<3> q

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...