Solved

usage of 'perl -le' in for loop

Posted on 2004-04-07
6
751 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

695 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