On Mon, Jun 04, 2001 at 11:46:00AM -0400, Pedro A Reche Gallardo wrote:
> Hi, please have a look to this perl one line command.
> perl -ne 'BEGIN{$/=">"}if(/^\s*(\S+)/){open(F,">$1")|| warn"$1 write
> failed:$!\n";chomp;print F ">", $_}'
>
> This command will take a file like this:
>
> >name1: anything
> kdkdkkdkk
> dkdkkdkdk
> >name2: anything
> slkslsksksl
>
> and convert it into two files, named as name1 and name2, and containing
> the following information
>
> >name1
> kdkdkkdkk
> dkdkkdkdk
>
> in the file name1
>
> >name2
> slkslsksksl
>
> in the file name2.
>
> Here is the question, can anyone help me to decipher this one-line perl
> command and put into a perl script.
> Thanks for your help.
Okay, I'll give it a go:
"perl -ne":
wraps 'while (<>) {...}' around script after -e
"BEGIN{$/=">"}":
sets input record separator to ">"
"if(/^\s*(\S+)/){":
if line matches optional whitespace + stuff, put stuff
in $1, then do...
"open(F,">$1")|| warn"$1 write failed:$!\n";"
open file named after contents of $1; bitch if it fails
"chomp;":
strip $_ (is this broken by $/ change above?)
"print F ">", $_":
print ">" and $_ to the file opened above
"}":
end of if block
--
The cost of software has always been development cost, not replication
cost. Sharing that cost among even a few users radically cuts the
per-user cost.
-- F. Brooks fails to predict IP disputes in _No Silver Bullet_