http://www.perlmonks.org?node_id=1007918


in reply to How can I run an folder full of text files through a perl script?

Just for completeness and fun a simple GUI solution for the Mac using AppleScript:

set theWindowTitle to "PerlMonks" set theSuffix to text returned of (display dialog "Enter a file suffix +:" & return default answer "" with title theWindowTitle) set theFolder to (choose folder with prompt "Enter directory") set thePerlScript to quoted form of (POSIX path of ((choose file with +prompt "Select a script:") as Unicode text)) -- display dialog "Script: " & thePerlScript with title theWindowTitle tell application "Finder" set theFiles to (every file of theFolder whose name extension is t +heSuffix) --as alias list end tell repeat with theFile in theFiles set theFile to quoted form of (POSIX path of (theFile as Unicode t +ext)) display dialog "Found: " & theFile with title theWindowTitle set theResult to do shell script thePerlScript & " " & theFile display dialog "Result: " & theResult with title theWindowTitle -- beep end repeat

Perl script:

#!/usr/bin/perl while (<>) {print}

Files:

Karls-Mac-mini:find karl$ cat foo.txt bar.txt foo bar

Regards, Karl

«The Crux of the Biscuit is the Apostrophe»

Replies are listed 'Best First'.
Re^2: How can I run an folder full of text files through a perl script?
by tobyink (Canon) on Dec 08, 2012 at 20:55 UTC

    I've written a couple of AppleScripts before but had forgotten how appallingly bad that language is. Clearly my subconscious had blotted out those memories as some kind of coping mechanism. But now it's all coming flooding back...

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

      It was my first one, honestly! Regards, Karl

      «The Crux of the Biscuit is the Apostrophe»