Passing bash array to perl

I have a shell script that checks how many instances of an application that are open and I would like to check the length of it to decide what to do next, currently I'm doing:

LIST=`pidof urxvt`
CNT=`perl -e '@ret=qw($LIST); print scalar @ret;'`
if [ "$CNT" -le 2 ]; then
    ...
fi

The problem is that the $CNT always = 1, it's pretty obvious that I'm not using the correct syntax to pass $LIST into the line of perl but I can't seem to find how to do it correctly. There's likely other ways of doing this than using perl but I'm more interested in how to do using perl than I am by using awk, python, or any of the numerous other options.

Thanks in advance.
LVL 3
coandaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SuperdaveCommented:
$LIST is not being expanded when included in your perl script because it's inside single quotes.  Switch the single quotes to double-quotes.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TintinCommented:
And to give you the non-perl answer


CNT=$(pidof urxvt | wc -l)
if [ $CNT -le 2 ]; then
    ...
fi

Open in new window

0
TintinCommented:
Whoops, I meant to write
CNT=$(pgrep urxvt | wc -l)
if [ $CNT -le 2 ]; then
    ...
fi

Open in new window

0
TintinCommented:
In fact, you can simplify it further
if [ $(pgrep -c urxvt) -le 2 ]
then
   ...
fi

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.