Solved

usage of 'perl -le' in for loop

Posted on 2004-04-07
6
735 Views
Last Modified: 2013-12-26
I wanted to know what is "perl -le" in the below for loop :

for i in `perl -le 'for(1..10) {print}'`
do
echo $i
done

It would be good if a detailed explanation is given.
0
Comment
Question by:spandana_b
6 Comments
 
LVL 7

Accepted Solution

by:
leflon earned 25 total points
ID: 10774227
Hi spandana_b,

perl -le 'for(1..10){print}'

calls the perl interpreter and executes the perl command supplied in the '...'.
this command will print the numbers from 1 to 10 in the following way

1
2
3
4
5
6
7
8
9
10

-l will have each number printed in seperate line
-e tells perl that a perl script follows in the '...' part

hth
leflon
0
 

Author Comment

by:spandana_b
ID: 10777182
Thanks for that.
I want to know on more thing can any command be given in place of print?

rgds.
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 25 total points
ID: 10779277
You can use any valid Perl syntax instead of the print.  What are you trying to do?
0
 

Expert Comment

by:rmundkowsky
ID: 10795008
You can call other unix commands in perl like so:

perl -le '$blah=`echo "why use Perl"`;print $blah'
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question