Perl Scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl Scripting
# 8  
Old 05-30-2013
In perl, to read lines from a file, you need to open a file handle and read line by line:

Code:
open FILEHANDLE, "< file.txt";
while (<FILEHANDLE>) {
    chomp;
    <do something with line>;
}
close FILEHANDLE;

This User Gave Thanks to balajesuri For This Post:
# 9  
Old 05-30-2013
Quote:
Originally Posted by balajesuri
In perl, to read lines from a file, you need to open a file handle and read line by line:

Code:
open FILEHANDLE, "< file.txt";
while (<FILEHANDLE>) {
    chomp;
    <do something with line>;
}
close FILEHANDLE;


thank you!

---------- Post updated at 04:19 PM ---------- Previous update was at 04:33 AM ----------

i want to create a shell script which input parameters(scripts) and then save(in file) one line in time.
then i want to create perl script who can read one line in time.
i want all this in loop
any idea?
# 10  
Old 05-30-2013
Quote:
Originally Posted by Evelin90
thank you!

---------- Post updated at 04:19 PM ---------- Previous update was at 04:33 AM ----------

i want to create a shell script which input parameters(scripts) and then save(in file) one line in time.
then i want to create perl script who can read one line in time.
i want all this in loop
any idea?
Perl Scripting-untitled11png
# 11  
Old 05-31-2013
@Evelin90: You must understand that you can read files line by line using a shell script too. Why do you want to invoke perl for that? I am, to some extent, able to understand the flowchart that you've attached in your post, but what is the exact purpose of having such a workflow? Why can't you have it this way:
Code:
----------
|  cmd   |
----------
    |
    |
    V
----------
|  .sh   |----> Save file
----------
    |
    |
    V
---------------
| Read file   |
| using shell |
| script      |
---------------

---------- Post updated at 12:42 ---------- Previous update was at 09:11 ----------

This is the best I could think of from your question:

In your shell script, write a line of code that will echo all arguments into a file. Then scp that file to myserver. Hope you have enabled password-less access by sharing the public key from host-machine to myserver. I think yes, since you're already ssh-ing to myserver. Once you copy arguments.dat to myserver, open the file in perl and process the arguments as required.

Here's the shell script:
Code:
echo $* > arguments.dat
scp arguments.dat user@myserver:/path/to/
ssh myserver "/path/to/some_perl_script.pl"

Here's the perl snippet:
Code:
open ARGFILE, "< arguments.dat";
while (<ARGFILE>) {
    chomp;
    <do something with arguments>;
}
close ARGFILE;

This User Gave Thanks to balajesuri For This Post:
# 12  
Old 05-31-2013
thank you!
I think in shell script we must check if user entering script..i will find it!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

need help in PERL Scripting

I am having file xyz.log Its content is like this int main() { d; #ifdef e; f; #else g; #ifdef h. #else i; (2 Replies)
Discussion started by: naaj_ila
2 Replies

2. Web Development

Perl scripting or shell scripting?

i am going to study any one of the scripting languages mentioned above(shell 0r perl scripting) . Which is having more scope for a fresher? (1 Reply)
Discussion started by: Anna Hussie
1 Replies

3. What is on Your Mind?

Shell Scripting vs Perl scripting

Gents, I have been working in a Solaris/Unix environment for about 9 months. I took some linux classses online before getting the job. But, I am not very good at scripting. I want to learn how to script. Do you think that I should start with Shell scripting or Perl? I wanted to continue with... (2 Replies)
Discussion started by: Pouchie1
2 Replies

4. What is on Your Mind?

Shell scripting vs Perl scripting

Hi all, I would like to start developping some good scripting skills. Do you think it would be best to start with shell scripting or Perl? I already got a fundation, really basics, in perl. but I am wondering what would be best to be good at first. Can you please help me determine which one to... (14 Replies)
Discussion started by: Pouchie1
14 Replies

5. UNIX for Dummies Questions & Answers

Need help configuring Active Perl on Windows Vista.: Perl Scripting on Windows

Hi All, Need help configuring Active Perl on Windows Vista. I am trying to install Active Perl on Windows Vista. The version of Active Perl i am trying to install is : ActivePerl 5.10.1 Build 1006 After installing it through cmd, When i try to run perl -v to check the version, i get the... (2 Replies)
Discussion started by: Vabiosis
2 Replies

6. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

7. Shell Programming and Scripting

Need help in perl scripting.

Hi, To run a perl script i am giving command like this in DOS prompt d:> perl D:\<dir_name>\<dir_name>\sample.pl Its throwing the following error while running the above syntax error at <eval 4> line 1, near "use D:" Can anyone help? (3 Replies)
Discussion started by: mvictorvijayan
3 Replies

8. Shell Programming and Scripting

perl scripting

Hi does anyone know how to ouput "I love scripting" to "scripting love I" without using reverse() function in perl? Thanks (2 Replies)
Discussion started by: ccp
2 Replies

9. Shell Programming and Scripting

Perl Scripting

Hi, I want to use the mailx command or sendmail command in perl script. I am trying this one and getting error: system "mailx -s \"Test mail\" $ar1"; Error: The flags you gave are used only when sending mail. (10 Replies)
Discussion started by: vaibhav
10 Replies

10. UNIX for Advanced & Expert Users

Perl scripting

hi Can any one suggest me book for perl scripting on UNIX Platform. Regards (2 Replies)
Discussion started by: rochitsharma
2 Replies
Login or Register to Ask a Question