?
Solved

usage of 'perl -le' in for loop

Posted on 2004-04-07
6
Medium Priority
?
755 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 7

Accepted Solution

by:
leflon earned 100 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 100 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

771 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