Execution problem with perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execution problem with perl
# 1  
Old 03-10-2010
Execution problem with perl

I got the below error when using the below code...it seem that perl interpret the "'" in the middle and therefore the pipe is not finished.

Code:
perl -wle '
@a=`who| perl -wlane 'print \$F[0];' | sort -u` ;
chomp @a ;
print @a;
'


Code:
the error message in cygwin is:-
perl: No match.
 | sort -u`;chomp @a ; print @a;: Command not found.

Code:
error message on Solaris is:-
Can't find string terminator "`" anywhere before EOF at -e line 2.
bash :  | sort -u
`; chomp @a ;
print @a ;
: command not found

even I try qx// instead of `` without any use.SmilieSmilieSmilie


Thanks in advance.

BR
# 2  
Old 03-10-2010
In your original version, the shell is closing and reopening the single-quoted string. Try:
Code:
perl -wle '
@a=`who| perl -wlane '\''print \$F[0];'\'' | sort -u` ;
chomp @a ;
print @a;
'

Whenever you need to embed single-quotes in a single-quoted string, you need to first close the single-quoted string, add a backslash-escaped single-quote, then reopen the single quoted string immediately afterwards (all of this is to appease the shell's parser, it has nothing to do with perl).

So
Code:
'

becomes
Code:
'\''

for every instance of a single quote you'd like to place inside a single-quoted string.

Regards,
Alister
# 3  
Old 03-10-2010
Try this:

Code:
@a = qx(who| perl -wlane \47print \$F[0];\47 | sort -u);

Why don't you write it all in Perl (without embedding code)?
# 4  
Old 03-10-2010
Quote:
Originally Posted by radoulov
Try this:

Code:
@a = qx(who| perl -wlane \47print \$F[0];\47 | sort -u);

Why don't you write it all in Perl (without embedding code)?
I tried it with the same error this was one of my tries. but with out any use.Smilie actually the system is ignoring the 'print \$F[0]' and print all the who command o/p.

# 5  
Old 03-10-2010
Hm ...

Code:
$ who
drado      pts/1        Mar 10 20:21    (xxx)
drado      pts/2        Mar 10 20:25    (xxx)
$ perl -wle '
  @a = qx(who| perl -wlane \47print \$F[0];\47 | sort -u);
  chomp @a;
  print @a;
'
drado

It works for me.

Last edited by radoulov; 03-10-2010 at 03:24 PM..
# 6  
Old 03-10-2010
Quote:
Originally Posted by alister
In your original version, the shell is closing and reopening the single-quoted string. Try:
Code:
perl -wle '
@a=`who| perl -wlane '\''print \$F[0];'\'' | sort -u` ;
chomp @a ;
print @a;
'

Whenever you need to embed single-quotes in a single-quoted string, you need to first close the single-quoted string, add a backslash-escaped single-quote, then reopen the single quoted string immediately afterwards (all of this is to appease the shell's parser, it has nothing to do with perl).

So
Code:
'

becomes
Code:
'\''

for every instance of a single quote you'd like to place inside a single-quoted string.

Regards,
Alister

Sorry Alister but the problem as in radoulov solution
# 7  
Old 03-10-2010
I would write something like this:

Code:
perl -le'
  $_{(split)[0]} = 1 for qx(who);
  print sort keys %_;
  '

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl execution commands

I don't know to debug the program todaylive.pl program. plz someone let me know what are the commands I need to know to debug the perl programs to find out the error on it. (3 Replies)
Discussion started by: ramkumar15
3 Replies

2. Shell Programming and Scripting

Execution problem

hi all, when i tried executing the script by giving following command $ sh test.sh <parameter> it shows the following output: <none> status code=0 Previously it was working fine.But now its showing this output. (1 Reply)
Discussion started by: sanjay mn
1 Replies

3. Shell Programming and Scripting

Execution problem unix commands in Perl CGI

I am trying to run SSH , mkdir and other unix commands using Perl CGI. But i am not able to Execute these commands. Please help me out !!!! SSH and mkdir is necessity for me. I will be thankful to you...!!!!! I am trying like: In perl CGI file i am writing like: @list = `ssh... (28 Replies)
Discussion started by: Navrattan Bansa
28 Replies

4. Programming

Perl script remote execution as another user

Hi gurus, I have a requirement where I need to remotely run a perl script as another user. Running the script locally as the required user is fine, however I need to su with the script due to filesystem permission issues. I do not want to update permissions on the remote server due to security... (5 Replies)
Discussion started by: melias
5 Replies

5. Programming

"execution problem with perl"

hi everyone, before stating my problem , i just want to say thanks in advance for the time and trouble taken:-) i am an newbie to perl programming, the problem is a text file needed to be parsed, i have looked over regular expressions and string matching but coudnt helped out.. the... (4 Replies)
Discussion started by: raghuraipur
4 Replies

6. Shell Programming and Scripting

Perl during execution???

Hi All, What happens when a Pelr script is executed.??(Jus like in C/C++ we have several stages like preprocessing,assembling,complining ,linkin',loadin'...) So similiarly In Perl we have something like compile pahse and run phase. but what exactly happens during its exec and what all... (3 Replies)
Discussion started by: Ranji Raj
3 Replies

7. Shell Programming and Scripting

Perl execution debugger

If this is the wrong forum, move it. It seemed like the best. Does anyone know of a perl thing that does the same thing as bash -x except for perl? I know I can output the information I want at the right times by actually putting that in the code, but it's harder... (2 Replies)
Discussion started by: killer54291
2 Replies

8. Shell Programming and Scripting

Give input to a perl script while execution

Hi, I have a perl script which prints me the epoch value of a specific date and time given.Now I want to proceed to a next step ie i want to give the input at the time of execution. I have to initialise the date and time values in the script before executing it.But now i want to give the date... (3 Replies)
Discussion started by: jyothi_wipro
3 Replies

9. Shell Programming and Scripting

Shell Command execution through PERL

Hi Guys, I wish to execute some shell commands through PERL. Here is what I desire to do 1) I wish to find list of directories in current working location 2) Then go in each directory and execute few commands like a) rm -rf *.log (Shell command) b) coreBuilder -f cb_tests.tcl (Some... (6 Replies)
Discussion started by: hardik_snps
6 Replies

10. Solaris

Solaris 10.5 perl and cron job execution problem

Hi, I want to run a crontab job on solaris 10.5. I have configured the crontab accordingly 10 * * * * /scripts/dbalter.pl >> /scripts/cronout.txt However this does not work .Then I go to /var/mail/root and find an error in the output: From root@myserver Wed Feb 4 17:02:00 2009... (1 Reply)
Discussion started by: sonu2die4
1 Replies
Login or Register to Ask a Question