in reply to Re: Complex string parsing
in thread Complex string parsing

Hi all, thanks for your replies. I was getting stuck on the the regx for the directory match. I also put in a check to see if the path is in fact a directory. The code below does what I was after.
open(TMP,'file.txt'); while($line = <TMP>) { chomp($line); next if $line =~ /^Total/; next if $line =~ /^\d+/; ($path) = split(/\s+/,$line); if (-d "$path") { if ($path =~ m!/$!) { $dir = (split /\//, $path)[-1]; print "/$dir/=/$dir\n"; } } } close(TMP);
Again, many thanks! Regards, Stacy.

Replies are listed 'Best First'.
Re:{3} Complex string parsing
by jeroenes (Priest) on Apr 25, 2001 at 15:59 UTC
    Maybe you like this concise style:
    open TMP, 'file.txt'; while( <TMP> ){ chomp; next if /^Total/ or /^\d/; s/\s+//; if (-d and m!/$!){ my $dir = (split !/!)[-1]; print "/$dir/=/$dir\n"; } } close TMP;
    But of course, this is subject to taste.
    "We are not alone"(FZ) Update: greenfox pointed out that I forgot the TMP in the while condition...