in reply to Re^2: Matching hyphens in file path to extract zip code
in thread Matching hyphens in file path to extract zip code

just a little more code

Not significantly, I just wrote it more verbosely.

use File::Basename; my ($zip) = fileparse($file) =~ /^(\d{5})\D/;

Replies are listed 'Best First'.
Re^4: Matching hyphens in file path to extract zip code
by Anonymous Monk on Feb 05, 2020 at 15:28 UTC
    I have to say that is makes the code cleaner and less prone to errors with a long regexp. Thank you!
      Path::Tiny
      #!/usr/bin/perl -- use strict; use warnings; use Path::Tiny qw/ path /; my $pdf = path( '-/xy/-/02239_04_04_1989_PkW.pdf' ); print $pdf->basename, $/; print $pdf->basename =~ m{^(\d+)_}, $/; __END__ 02239_04_04_1989_PkW.pdf 02239