in reply to perl pattern match for end of string using STDIN and chomp

Running the first example code you posted and entering your string does not yield your posted output; rather, it yields the correct output from your second code sample. Have you tested your posted code as written?

#!/usr/bin/perl print "get some string: "; chomp($string = <STDIN>); #$string = $ARGV[0]; #chomp($string); $string =~ m/\/([[:alnum:]]+)_.*\.(.+)$/; print "$1\n"; $type = $2; print "$type\n"; $string =~ m/(.+)\.${type}$/; #$string =~ m/(.+)\.${type}\Z/; #$string =~ m/(.+)\.${type}\z/; #$string =~ m/(.+)\.${type}/; print "$1\n"; exit 0;

~/sandbox$ perl junk.pl get some string: /xxxx/yyyy/ZZZ_xxxx.CCC ZZZ CCC /xxxx/yyyy/ZZZ_xxxx

Replies are listed 'Best First'.
Re^2: perl pattern match for end of string using STDIN and chomp
by cbolcato (Novice) on Oct 08, 2009 at 19:04 UTC
    perl 5.8.0 run on Linux 2.4.21-40.ELsmp DOES NOT WORK, you are correct I ran on perl 5.8.7 on my windows machine and it worked fine, going to try and find a more current version on our Linux machine and try and find if it is a perl version problem or if it is directly related to linux
      Ditto on ikegami above, tested v5.8.8 built for x86_64-linux-gnu-thread-multi on Ubuntu 8.04 LTS as well as Windows. What happens when you run this?

      #!/usr/bin/perl print "get some string: "; $dropped = chop($string = <STDIN>); print ord $dropped, " ", ord $/, "\n"; #$string = $ARGV[0]; #chomp($string); $string =~ m/\/([[:alnum:]]+)_.*\.(.+)$/; print "$1\n"; $type = $2; print "$type\n"; $string =~ m/(.+)\.${type}$/; #$string =~ m/(.+)\.${type}\Z/; #$string =~ m/(.+)\.${type}\z/; #$string =~ m/(.+)\.${type}/; print "$1\n"; exit 0;
        When i run your code i get this:
        get some string: /xxxx/xxxxx/YYY_xxxxx.CCC 10 10 YYY CCC YYY

      Works for me in 5.8.0

      get some string: /xxxx/yyyy/ZZZ_xxxx.CCC ZZZ CCC /xxxx/yyyy/ZZZ_xxxx

      And there's no reason it shouldn't. $ not matching the end of the string would have been caught by tests. Your build is very broken if the last pattern doesn't match given the specified input.