usage of 'perl -le' in for loop

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.
spandana_bAsked:
Who is Participating?
 
leflonConnect With a Mentor Commented:
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
 
spandana_bAuthor Commented:
Thanks for that.
I want to know on more thing can any command be given in place of print?

rgds.
0
 
TintinConnect With a Mentor Commented:
You can use any valid Perl syntax instead of the print.  What are you trying to do?
0
 
rmundkowskyCommented:
You can call other unix commands in perl like so:

perl -le '$blah=`echo "why use Perl"`;print $blah'
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.