in reply to Help needed with reducing function to a single regex
How about getting rid of these just like you do with the other useless lines:
... foreach(@_) { # skip if it doesn't start with either a space or backslash next if (!/^[ \\]/); # skip if it's just "." or ".." next if (/^\s*\.{1,2}\s/); if (/^\\/) { $path = "$_\\" } elsif (/^\s*(.*\S)\s{5,}([HDRSA]+)\s*(\d+)\s*(.*)/) { my ($file,$att,$size,$date) = ($1,$2,$3,$4); my $ext = ( $file =~ /\.([^.]+)$/ ) ? $1 : "DIR"; print ...; } }
That last bit about setting $ext follows your assumption that if there's no dot in the name, it must be a directory (but I think this is not a reliable assumption). Note that file names may contain multiple periods, and I think you want $ext to hold just the characters after the last one (in your original version, a file name like "rel_3.1.tar.gz" would set $ext to "1.tar.gz").
Your expression for getting/setting $path was also a bit odd. The perlre man page says:
And of course, directory names might include dash, period or other punctuation that wouldn't match \w. Your code made it seem like lines with initial slash would contain only a path name and nothing else, so I simplified on that basis (but I don't know if this assumption is correct).Also remember that "|" is interpreted as a literal within square brackets, so if you write "[fee|fie|foe]" you're really only matching "[feio|]".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Happy fun regexping
by cyberconte (Scribe) on Apr 07, 2002 at 12:06 UTC | |
by grinder (Bishop) on Apr 08, 2002 at 12:06 UTC |