I am alos fairly new with perl and completely new with perl one liners. I
see how you can use regex's on the cmd line to edit a file (sort of sed
ish). I tried this

$ perl -pe 's/hello/reverse($1)/' -i test

all it print's is reverse. I was wondering if you knew of a way to read in
a word and reverse it's contents. Not critical but it has intrigued me.
Thank you in advance
David Monarres
<[EMAIL PROTECTED]>

On Wed, 02 May 2001 12:29:08 Me wrote:
> > "how do I tell perl to open a file for reading, do various
> > commands, and then output those changes to a new file"???
> 
> Perl has some great one-liner shortcuts for writing filters.
> 
> First, -e lets you put perl on the command line:
> 
>     perl -e ' print "foo\n" '
> 
> Prints
> 
>     foo
> 
> Second, -p converts your perl to a filter:
> 
>     perl -pe ' s/foo/bar/ ' inputfiles
> 
> Replaces the first 'foo' on each line in inputfiles with 'bar'.
> inputfiles can be omitted (in which case perl processes
> stdin) or can be a single file or a filespec that matches
> multiple files (in which case the files are processed one
> after the other and the output is all written as one long
> string to stdout).
> 
> Third, -i makes a filter work inplace, ie:
> 
>     perl -pie ' s/foo/bar/ ' *
> 
> Would filter all the files in the current directory, directly
> changing them on disk. Dangerous! But easy!!
> 
> There are plenty of variations on the above to let you
> create backups (relevant to the last one-liner), to use
> these options on the first line of a regular script file, eg:
> 
>     #!/usr/bin/perl -i.bkp -p
> 
> For more on command line options, try:
> 
>     perl --help
>     perldoc perlrun
>     perldoc -f command
> 
> The Perl Cookbook is a fabulous source for all sorts
> of practical tidbits like (well, much better) than the above.
> 

Reply via email to