in reply to Matching hyphens in file path to extract zip code
Is the ZIP code always at the beginning of the filename? You can use the core module File::Basename to strip off the path:
use warnings; use strict; use File::Basename qw/fileparse/; my @files = ( '-/yf/-/22211_01_09_2000_XYz.pdf', '_/gt/-/02239_04_04_1989_PkW.pdf', '-/xy/-/02239_04_04_1989_PkW.pdf' ); for my $file (@files) { my $bn = fileparse($file); my ($zip) = $bn =~ /^(\d{5})\D/; print "$file => $zip\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Matching hyphens in file path to extract zip code
by Anonymous Monk on Feb 05, 2020 at 15:13 UTC | |
by haukex (Archbishop) on Feb 05, 2020 at 15:17 UTC | |
by Anonymous Monk on Feb 05, 2020 at 15:28 UTC | |
by Anonymous Monk on Feb 05, 2020 at 23:24 UTC |