Solved

usage of 'perl -le' in for loop

Posted on 2004-04-07
6
706 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
Comment Utility
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
Comment Utility
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
Comment Utility
You can use any valid Perl syntax instead of the print.  What are you trying to do?
0
 

Expert Comment

by:rmundkowsky
Comment Utility
You can call other unix commands in perl like so:

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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now