To execute one line of code on a file and print the results to standard output: perl -pe ' your single line of code here ' filename.txt
-e tells perl to execute code between quotes.
-p prints the results to your screen
To execute one line of code on a file, write results to that file and keep a backup copy of the original: perl -p -i~ -e '...your code...' file.txt
The -i tells perl to keep a backup of the original. The ~ is what's appended to the backup file name.
To extract what's inside single quotes using regex - where your regex is enclosed in single quotes:
In a text file you have:
Use: perl -e 's/.*'\''(.*)'\''.*/$1/' -p file1.txt
So you get the first single quote by actually ending the single quoted string, then escape the single quote you wish to insert, then start single quoted string again and continue.
A simpler example:
To print: My O'Reilly Books
In perl it's: print "My O'Reilly Books\n";
In bash shell:
perl -e 'print "My O'\''Reilly Books\n";'
In this example, right after the O, you actually end the single quoted string, then insert your escaped single quote, then start the single quoted string again. Note that those are two single quotes between the backslash and Reilly.
debugging CGI Scripts and passing parameters on your console:
In your browser you have:
http://www.example.com/myScript.cgi?name=joe&city=new%20york
on your console you would:
perl -d myScript.cgi
then paste your parameters starting with the question mark:
?name=joe&city=new%20york
press enter, then press [ctrl] + d to exit and continue with script