WxResearcher has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to parse this path but because it is a directory of subdirectories the last part of the path is variable. I want to assign the last directory in the path a variable so I can print it later on but I've had no luck. Any help is greatly appreciated. Thanks!
#!/usr/bin/perl + #KDUX station METARS throughout a certain directory + + use strict; use warnings; use File::Find; use File::Basename; my($filename, $directories, $suffix) = basename("/d2/aschwa/archive_pr +oject/METAR_data/#lastdirectoryname"); my @folder = ("/d2/aschwa/archive_project/METAR_data/"); open(OUT , '>',+ 'KDUX_METARS.txt') or die "Could not open $!"; + +print OUT "Station, Day/Time, Obs Type, Wind/Gust (Kt), Vis (SM), Sky +, T/Td (C), Alt, Rmk\n"; print STDOUT "Finding METAR files\n"; my $criteria = sub {if(-e && /^2012/) { open(my $file,$_) or die "Could not open $_ $!\n"; while(<$file>) { print OUT $lastdirectoryname, $_ if /KDUX ....55Z|KDUX +....05Z/; } } + }; + find($criteria,@folder); + close OUT;
|
|---|