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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Simple regex
by g0n (Priest) on Jan 19, 2005 at 12:20 UTC
    What do you mean by 'exactly the contrary'?
Re: Simple regex
by gellyfish (Monsignor) on Jan 19, 2005 at 12:21 UTC

    Change the =~ to !~

    /J\

Re: Simple regex
by Dietz (Curate) on Jan 19, 2005 at 12:55 UTC
    Maybe this is what you're looking for:
    $text =~ s/(.+\s)\S*\.\S*/$1/g;


    OUTPUT:
    0000 636d6400 5589e583 ec0831c0 83e4f0e8 0010 00000000 e8000000 0083ec0c 68000000 0020 00e80000 000031c0 c9c39090 90909090

      thanks for your help but the problem is still there.
      this is my source code :
      #!perl -w # use strict; # # Hashes my %struct_compilation = ( "objdump" => "%s -j .text -s -z %s", ); my %compilation = ( "objdump" => "", ); my %return = ( "objdump" => "", ); my $path = "D:/Progs/Programmation/Dev-Cpp/bin/"; my %compiler = ( "objdump" => $path . "objdump.exe", ); # # Main if( @ARGV < 1 ) { exit( 0 ); } my $src = $ARGV[0]; $compilation{"objdump"} = sprintf( $struct_compilation{"objdump"}, $co +mpiler{"objdump"}, $src ); $return{"objdump"} = `$compilation{"objdump"}`; $return{"objdump"} =~ s/[0-9a-f]{4}//g ; print $return{"objdump"};
      i want to print the hexa decimal string whitch is returned by objdump but my regex do the contrary !
        Replace
        $return{"objdump"} =~ s/[0-9a-f]{4}//g;
        with
        $return{"objdump"} = join("",$return{"objdump"} =~ /[0-9a-f]{4}/g)

        For those of us not blessed with windows and objdump can you post a frag of the objdump output so we can see what to aim for.

        Thanks,
        R.

        Pereant, qui ante nos nostra dixerunt!
Re: Simple regex
by Random_Walk (Prior) on Jan 19, 2005 at 13:47 UTC

    the {4} in your regex makes me think perhaps you wanted something like this to strip out the leading blocks of four which I assume go hex.

    $text=~s/(^|\n)[0-9a-f]{4} /\1/g # gives 636d6400 5589e583 ec0831c0 83e4f0e8 cmd.U.....1..... 00000000 e8000000 0083ec0c 68000000 ............h... 00e80000 000031c0 c9c39090 90909090 ......1.........

    Cheers,
    R.

    Pereant, qui ante nos nostra dixerunt!
Re: Simple regex
by Isothop (Acolyte) on Jan 19, 2005 at 13:51 UTC
    objdump outputs :
    cls.c.o: file format pe-i386 Contents of section .text: 0000 636d6400 5589e583 ec0831c0 83e4f0e8 cmd.U.....1..... 0010 00000000 e8000000 0083ec0c 68000000 ............h... 0020 00e80000 000031c0 c9c39090 90909090 ......1.........
    what i want the reget to output :
    0000636d64005589e583ec0831c083e4f0e8001000000000e80000000083ec0c680000 +00002000e80000000031c0c9c3909090909090

      print for $text=~/[0-9a-f]{4}/g;

      Cheers,
      R.

      Pereant, qui ante nos nostra dixerunt!
      so what you really want to do is strip the last 17 (decimal) bytes (or 18 or 19 depending on your newline) from each line and join on the resultant line ends and spaces?

      Also, do you mean to imply that there will be 3 lines (per item) of useful info in the dump, or do you need to deal with a variable (unpredictable) number of lines?

      Yes, there's a premium on brevity here, but an even higher premium on precision!
Re: Simple regex
by Isothop (Acolyte) on Jan 19, 2005 at 17:24 UTC
    this is the code which i use finally. it works. thanks you guys :)
    $return{"objdump"} = join( "", $return{"objdump"} =~ /[0-9a-f]{8}/g ); my $length = length $return{"objdump"}; for( my $i = 0 ; $i < $length ; $i += 2 ) { print "\\x" . substr( $return{"objdump"}, $i, 2 ); }
      Here's another way to do the same thing:
      $return{"objdump"} =~ s/.*?([0-9a-f]{8}|$)/$1/gs; print "\\x$_" for $return{"objdump"} =~ /../g;
      The first line strips out every string preceding an eight-digit hex number or end of string. The second line splits the string into two-digit substrings and prints them.

      Caution: Contents may have been coded under pressure.