perl array issue

S

sfgroups

I have this code, its not getting unix command output into array.

Here is my code
perl code:

#!/usr/bin/perl
$user="myguest";
@m=( `id $user | perl -pne ' s/^.*gid//; s/[^\(]+\(([^\)]+)\)/"$1" /g;'
|perl -pne 's/"\s*"/", "/g' `);
print "size $#m \n";

foreach $s(@m) { print "$s\n";}

Here is output:
#./grp.plsize 0", " ", " ", " ", " ", " ", " ", " ", "

The command works in command line.

bash code:id myguest | perl -pne ' s/^.*gid//;
s/[^\(]+\(([^\)]+)\)/"$1" /g;' |perl -pne 's/"\s*"/", "/g'"myguest",
"myguest", "wheel", "mail", "games", "ftp", "users"

can you help me on this?
Thanks
SR
 
A

A. Sinan Unur

I have this code, its not getting unix command output into array.

I would only call this "code" in sense of
http://en.wikipedia.org/wiki/Code_(cryptography):

a method used to transform a message into an obscured form,
preventing those not in on the secret from understanding
what is actually transmitted.
Here is my code
perl code:

#!/usr/bin/perl
$user="myguest";
@m=( `id $user | perl -pne ' s/^.*gid//; s/[^\(]+\(([^\)]+)
\)/"$1" /g;' |perl -pne 's/"\s*"/", "/g' `);

You do realize that backticks interpolate, right? So, whatever is in $1
when you invoke this line will first be interpolated into the string
before the string is passed to the shell. Since I do not see any
captures before this point, $1 will probably be interpolated to the
empty string.
can you help me on this?

Can you explain what you are trying to do?

Sinan
 
J

John W. Krahn

sfgroups said:
I have this code, its not getting unix command output into array.

Here is my code
perl code:

#!/usr/bin/perl
$user="myguest";
@m=( `id $user | perl -pne ' s/^.*gid//; s/[^\(]+\(([^\)]+)\)/"$1" /g;'
|perl -pne 's/"\s*"/", "/g' `);
print "size $#m \n";

foreach $s(@m) { print "$s\n";}

Here is output:
#./grp.plsize 0", " ", " ", " ", " ", " ", " ", " ", "

The command works in command line.

bash code:id myguest | perl -pne ' s/^.*gid//;
s/[^\(]+\(([^\)]+)\)/"$1" /g;' |perl -pne 's/"\s*"/", "/g'"myguest",
"myguest", "wheel", "mail", "games", "ftp", "users"

can you help me on this?

#!/usr/bin/perl
use warnings;
use strict;

my $user = 'myguest';

print join ', ',
map qq["$_"],
map /\(([^)]+)\)/g,
grep /^groups=/,
split ' ', `id $user`;

__END__



John
 
H

hymie!

In our last episode, the evil Dr. Lacto had captured our hero,
#!/usr/bin/perl
$user="myguest";
@m=( `id $user | perl -pne ' s/^.*gid//; s/[^\(]+\(([^\)]+)\)/"$1" /g;'
|perl -pne 's/"\s*"/", "/g' `);

I'm almost afraid to ask this, but why are you
* running perl
* starting a subshell
* running perl in that subshell
* twice
?

hymie! http://www.smart.net/~hymowitz (e-mail address removed)
===============================================================================
It was a slap in the face how quickly I was replaced
And are you thinking of me when you ... --Alanis Morissette
===============================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top