in reply to Re^2: Equal strings don't match!
in thread Equal strings don't match!

The null character does seem to be the only difference between what you have in @CMD and the literal string. Have you tried removing it? You could remove nulls from everything in that array this way:

tr/\0//d for @CMD;

That means, however, that a command line with several arguments (e.g., "echo one two") will have those arguments all stuck together (e.g., "echoonetwo") instead of separated with nulls.

Without knowing what you're really trying to do, it's hard to give good advice. See XY Problem.

Replies are listed 'Best First'.
Re^4: Equal strings don't match!
by pl (Initiate) on Jul 30, 2008 at 19:16 UTC
    The programm is working now! I developed a monitoring application for linux. I have other arrays with info about each process that I get from the proc fs...This might help to understand:
    sub get_data_from_proc_fs{ opendir(PROC,"/proc"); @PROC = readdir PROC; closedir(PROC); @pid = grep /[0-9]/, @PROC; for($k=0;$k<@PID;$k++){ open(STAT,"<","/proc/$PID[$k]/stat"); ($STAT) = <STAT>; push(@app,(split(" ",$STAT))[1]); push(@pgrp,(split(" ",$STAT))[4]); close(STAT); open(CMDLINE,"<","/proc/$PID[$k]/cmdline") ; ($CMDLINE) = <CMDLINE>; push(@cmd,$CMDLINE); close(CMDLINE); } $/ = "\0"; chomp(@cmd); $/ = "\n"; } #####some code here# &get_data_from_proc_fs ; &get_system_date ; $a = 0 ; $PROC_FS_NEW = 0 ; while( $a < $PS_MONITOR ){ $b = 0 ; $found = 0 ; while( $b < $PS_PROC_FS ){ if( ($cmd_monitor[$a] eq $cmd[$b]) && ($pgrp[$b] eq $pid[$b]) +){ if( $first_time == 1 ){ $status = "NORMAL" ; $process = "${app[$b]}_${pid[$b]}" ; &print_status_info($process,$cmd[$b],$pid[$b]) ; $found++ ; } &save_info_about_running_processes_to_monitor ; $PROC_FS_NEW++ ; } $b++ ; } if(( $found == 0 ) && ( $first_time == 1 )){ $status = "ERROR" ; &print_status_info($app_m[$a],$cmd_m[$a]) ; } $a++ ; #####code continues...#

      Looks like you're trying to reinvent Proc::ProcessTable. I'd recommend you to use that, at least this way you'll avoid most of the pitfalls your code presents (it may crash in a million ways as you don't handle the *many* errors that may occur when processing files from such a volatile file-system as /proc).