Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl Syntax

Status
Not open for further replies.

M626

Programmer
Joined
Mar 13, 2002
Messages
299
I found this code to delete every that is *.tst but how can i can it to delete anything that's ._*.*



unlink qq($dir\\$file) if $file=~/\.tst$/i;
 
In long hand, something like this:

Code:
[url=http://perldoc.perl.org/functions/use.html][black][b]use[/b][/black][/url] [green]File::Spec::Functions[/green] [red]qw([/red][purple]catfile[/purple][red])[/red][red];[/red]

[black][b]use[/b][/black] [green]strict[/green][red];[/red]

[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]$dir[/blue] = [red]'[/red][purple]foo[/purple][red]'[/red][red];[/red]

[url=http://perldoc.perl.org/functions/opendir.html][black][b]opendir[/b][/black][/url][red]([/red][black][b]my[/b][/black] [blue]$dh[/blue], [blue]$dir[/blue][red])[/red] or [url=http://perldoc.perl.org/functions/die.html][black][b]die[/b][/black][/url] [red]"[/red][purple]Can't open [blue]$dir[/blue]: [blue]$![/blue][/purple][red]"[/red][red];[/red]
[olive][b]foreach[/b][/olive] [black][b]my[/b][/black] [blue]$name[/blue] [red]([/red][url=http://perldoc.perl.org/functions/readdir.html][black][b]readdir[/b][/black][/url][red]([/red][blue]$dh[/blue][red])[/red][red])[/red] [red]{[/red]
	[olive][b]next[/b][/olive] [olive][b]if[/b][/olive] [blue]$name[/blue] !~ [red]m{[/red][purple]^[purple][b]\.[/b][/purple]_.*[purple][b]\.[/b][/purple].*$[/purple][red]}[/red][red];[/red]
	
	[black][b]my[/b][/black] [blue]$file[/blue] = [maroon]catfile[/maroon][red]([/red][blue]$dir[/blue], [blue]$name[/blue][red])[/red][red];[/red]
	
	[url=http://perldoc.perl.org/functions/unlink.html][black][b]unlink[/b][/black][/url] [blue]$file[/blue] or [black][b]die[/b][/black] [red]"[/red][purple]Can't unlink [blue]$file[/blue]: [blue]$![/blue][/purple][red]"[/red][red];[/red]
[red]}[/red]
[url=http://perldoc.perl.org/functions/closedir.html][black][b]closedir[/b][/black][/url][red]([/red][blue]$dh[/blue][red])[/red][red];[/red]
[tt]------------------------------------------------------------
Pragmas (perl 5.8.8) used :
[ul]
[li]strict - Perl pragma to restrict unsafe constructs[/li]
[/ul]
Core (perl 5.8.8) Modules used :
[ul]
[li]File::Spec::Functions - portably perform operations on file names[/li]
[/ul]
[/tt]

- Miller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top