--- Pedro A Reche Gallardo <[EMAIL PROTECTED]> 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.
#!/usr/bin/env perl -w
# -n puts a while(<>){} loop around the script code
BEGIN { $/=">" } # set record seperator to '>' instead of "\n"
while(<>) { # <> reads files from command line, or STDIN
# c.f. perldoc perlop for IO operators
if (/^\s*(\S+)/) { # if the line just read matches any nonspaces
# preceded by any or no unremembered whitespace
open(F,">$1") # open the remembered pattern as an output file
# $1 is the nonspaces matched from (\S+) above
or warn "$1 write failed:$!\n"; # error logging w/reason($!)
chomp; # knock the newline off the line we read
print F ">", $_; # print the line read to the opened outfile
# prepending the '>' we lost by setting $/ to '>'
}
}
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35
a year! http://personal.mail.yahoo.com/