I have the follwoing script
#!/usr/bin/perl
open IN, "/tmp/file";
s/(.*)=/$k{$1}++;"$1$k{$1}="/e and print while <IN>;
how to print the output of the script to file_out in place to print to standard output?
lidia
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Explanation:
opencommand to open fileINfilehandle name/tmp/filename of file and specifier that it is for reading<, i.e."</tmp/file"it also means readingopencommand to open fileOUTfilehandle name>file_out.txtname of file and specifier that it is for reading>, i.e.">file_out.txt"to writes/.../.../eyour substitution (I assume you know what it does)andis a boolean operator that short-circuits, meaning it only does the thing afterwards if the thing beforehand is true. In this case, it will only print if the substitution actually matched something.print OUTprint to the filehandleOUTwhile <IN>for each line from the file behind filehandleINNote:
Used this way, it makes extensive use of the magical default variable
$_. Do a search for$_on the perlintro site. In short:s///substitution what string to work on, it uses$_printwhat to print, it prints$_whileloop going through a filehandle’s data where to put each line, it gets put into$_Your program could have been rewritten: