Perl Wizards 
Author Message
 Perl Wizards

I am trying to reuse some perl code that has been given to me.  I am having
problems with this particular line :

grep(m!$/bin/(.{10}) ! && $ps{$1}++, &safe_backtic("ps -ef"));

I don't understand the first pattern matching statement (or if it is a
pattern matching statement !) m! ....!

What do the ! ... ! do ?

Also are the results of this pattern matching being back substituted into
$ps{$1} ??

Any help from perl wizards out there would be useful ..



Wed, 18 Jun 1902 08:00:00 GMT  
 Perl Wizards

Quote:

>I am trying to reuse some perl code that has been given to me.  I am having
>problems with this particular line :

>grep(m!$/bin/(.{10}) ! && $ps{$1}++, &safe_backtic("ps -ef"));

>I don't understand the first pattern matching statement (or if it is a
>pattern matching statement !) m! ....!

>What do the ! ... ! do ?

Why don't you read the documentation about m/PATTERN/cgimosx in perlop
yourself.

Quote:

>Also are the results of this pattern matching being back substituted into
>$ps{$1} ??

Why don't you read the documentation in perlre yourself.

Quote:
>Any help from perl wizards out there would be useful ..

I'm not a wizard so I guess my help won't be useful, so I won't give any
other than the references above.

--
Sam

Another result of the tyranny of Pascal is that beginners don't use
function pointers.
        --Rob Pike



Wed, 18 Jun 1902 08:00:00 GMT  
 Perl Wizards

Please try and select more useful subject lines.  This is not a
question for a 'wizard', and indeed most 'wizards' will likely
ignore it, or flame you for using such a poor subject line.

: I am trying to reuse some perl code that has been given to me.  I am having
: problems with this particular line :

: grep(m!$/bin/(.{10}) ! && $ps{$1}++, &safe_backtic("ps -ef"));

: I don't understand the first pattern matching statement (or if it is a
: pattern matching statement !) m! ....!

: What do the ! ... ! do ?

Let's see...this seems very strange to me...It is a pattern match, they
are simply using m!! instead of m// so they won't have to escape their
slashes.  That part is easily understood.

However, I'd be surprised if this works as expected.  The match, as I
understand it, is looking for an occurance of $/ (input record
separator), followed by 'bin/' and then ten characters and a space.

: Also are the results of this pattern matching being back substituted into
: $ps{$1} ??

The first ten characters following the 'bin/' go into $1

: Any help from perl wizards out there would be useful ..

I honestly have not seen the syntax above before though.  Could
someone help explain it?  Specifically, what is it saying to use
that && and a second expression in the grep?

--



Wed, 18 Jun 1902 08:00:00 GMT  
 Perl Wizards


Quote:
>Please try and select more useful subject lines.  This is not a
>question for a 'wizard', and indeed most 'wizards' will likely
>ignore it, or flame you for using such a poor subject line.

I"m not a wizard either.

Quote:

>: grep(m!$/bin/(.{10}) ! && $ps{$1}++, &safe_backtic("ps -ef"));

>Let's see...this seems very strange to me...It is a pattern match, they
>are simply using m!! instead of m// so they won't have to escape their
>slashes.  That part is easily understood.

>However, I'd be surprised if this works as expected.  The match, as I
>understand it, is looking for an occurance of $/ (input record
>separator), followed by 'bin/' and then ten characters and a space.

Yes -- most bizarre.  Presumably this is meant to match a user with an
8-char username that starts with 'bin/' -- an atypical string with
which to start a username, for sure.  (It has to be 8-char -- at least
on Solaris, where the usernames in the first column are
right-justified.)  Perhaps the $ is a mistake -- in that case, they
could be looking for commands in a bin directory.

Looks like crappy code to me, but maybe it's really good code doing
something I don't understand.

Quote:
>I honestly have not seen the syntax above before though.  Could
>someone help explain it?  Specifically, what is it saying to use
>that && and a second expression in the grep?

x && y is evaluated as follows:
- x is evaluated.  If it evaluates to false, its result is the result of the whole
  expression.
- otherwise, y is evaluated, and its result is the result of the whole expression.

Normally grep is used to extract a subset of a list that satisfies some
pattern.  The subset extracted in this case would be those items that
contained a '$/bin/.{10} ' and where those ten chars had been
encountered previously so $ps{$1} was positive before that one was
processed.  This seems like a highly dubious thing to want, so my guess
would be that the result of the grep is thrown away, and the author
should have done a foreach loop instead.
--

The Internet stock bubble didn't burst on 1999-11-08.  Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>



Wed, 18 Jun 1902 08:00:00 GMT  
 Perl Wizards
[no wizards are likely to answer a Subject: line like that - in
future, please write a more descriptive subject]

Quote:

> I am trying to reuse some perl code that has been given to me.

That's a potential problem right there.  Aren't you worried
about worms, Trojan horses, security holes, etc. from using
a steaming heap of code you don't understand?

Quote:
>                                                       I am having
> problems with this particular line :

> grep(m!$/bin/(.{10}) ! && $ps{$1}++, &safe_backtic("ps -ef"));

> I don't understand the first pattern matching statement (or if it is a
> pattern matching statement !) m! ....!
> What do the ! ... ! do ?

Neither do I.  The ! ... ! are acting as an alternative to the
usual m// , but I don't see how this can match anything, when
$ matches the end-of-line.  What does &safe_backtic do that
backticks won't?  It's not like the code is allowing arbitrary
commands there.  And it's not like there isn't a better way
to get the process table info.  Are you *sure* you want to
trust this code?

Quote:
> Also are the results of this pattern matching being back substituted into
> $ps{$1} ??

In theory, yes.  In practice.. well, what happens when you print
out the contents of %ps ?  Is there anything in there that wasn't
there before this line?

Quote:
> Any help from perl wizards out there would be useful ..

Okay, here's my best advice.  Get Andrew Johnson's book
"Elements of Programming with Perl" and learn enough that
you don't have to depend on wonky code from Heaven only
knows where.

David
--

Senior computing specialist
mathematical statistician



Wed, 18 Jun 1902 08:00:00 GMT  
 Perl Wizards


Quote:
>[no wizards are likely to answer a Subject: line like that - in
>future, please write a more descriptive subject]

The fact of your posting contradicts your words :)
--

The Internet stock bubble didn't burst on 1999-11-08.  Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>


Wed, 18 Jun 1902 08:00:00 GMT  
 Perl Wizards
On Wed, 10 Nov 1999 22:57:03 GMT,

Quote:


> >[no wizards are likely to answer a Subject: line like that - in
> >future, please write a more descriptive subject]

> The fact of your posting contradicts your words :)

He said likely. This is just an exception :)

Martien
--
Martien Verbruggen                      |
Interactive Media Division              | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |



Wed, 18 Jun 1902 08:00:00 GMT  
 Perl Wizards


...

Quote:
> > grep(m!$/bin/(.{10}) ! && $ps{$1}++, &safe_backtic("ps -ef"));

> > I don't understand the first pattern matching statement (or if it is a
> > pattern matching statement !) m! ....!
> > What do the ! ... ! do ?

> Neither do I.  The ! ... ! are acting as an alternative to the
> usual m// , but I don't see how this can match anything, when
> $ matches the end-of-line.

Ooh.  Look again.  As has already been noted, that leading '$'
interpolates the value of '$/', not matches 'end-of-line'.  So it is
approximately a 'start-of-line' anchor.

--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/



Wed, 18 Jun 1902 08:00:00 GMT  
 Perl Wizards

Quote:



> >[no wizards are likely to answer a Subject: line like that - in
> >future, please write a more descriptive subject]

> The fact of your posting contradicts your words :)

Flattery will get you nowhere.  Well, okay, it will get you
pretty much what you want.  I'm easy.

But I don't consider myself a Perl wizard.  Just a satisfied
customer.  Abigail, Larry, Uri, Damian...  They're wizards.

David
--

Senior computing specialist
mathematical statistician



Wed, 18 Jun 1902 08:00:00 GMT  
 Perl Wizards
[snip]

Quote:
> Ooh.  Look again.  As has already been noted, that leading '$'
> interpolates the value of '$/', not matches 'end-of-line'.  So it is
> approximately a 'start-of-line' anchor.

Mea culpa.  I thought I checked that first.  See, I *told*
Kragen I wasn't a wizard.  :-)

So how in the Sam Hill is 'bin' at the very beginning of a line
with no prior spaces ever going to match anything output from
`ps -ef` ?  It doesn't come close on the versions of ps with
which I am familiar.

David
--

Senior computing specialist
mathematical statistician



Wed, 18 Jun 1902 08:00:00 GMT  
 Perl Wizards

Quote:



> >Please try and select more useful subject lines.  This is not a
> >question for a 'wizard', and indeed most 'wizards' will likely
> >ignore it, or flame you for using such a poor subject line.

> I"m not a wizard either.


> >: grep(m!$/bin/(.{10}) ! && $ps{$1}++, &safe_backtic("ps -ef"));

> >Let's see...this seems very strange to me...It is a pattern match, they
> >are simply using m!! instead of m// so they won't have to escape their
> >slashes.  That part is easily understood.

> >However, I'd be surprised if this works as expected.  The match, as I
> >understand it, is looking for an occurance of $/ (input record
> >separator), followed by 'bin/' and then ten characters and a space.

> Yes -- most bizarre.  Presumably this is meant to match a user with an
> 8-char username that starts with 'bin/' -- an atypical string with
> which to start a username, for sure.  (It has to be 8-char -- at least
> on Solaris, where the usernames in the first column are
> right-justified.)  Perhaps the $ is a mistake -- in that case, they
> could be looking for commands in a bin directory.

I believe "Nobody" is trying to match a command prompt:

        $/bin/abcdefgh >

or something of the sort. But, I've been wrong before.

Quote:
> Looks like crappy code to me, but maybe it's really good code doing
> something I don't understand.

No. Coming from someone with a nickname "Nobody", I wouldn't assume it
was that good.

Again, I might be wrong.

--Ala



Wed, 18 Jun 1902 08:00:00 GMT  
 Perl Wizards


Quote:

> [snip]
> > Ooh.  Look again.  As has already been noted, that leading '$'
> > interpolates the value of '$/', not matches 'end-of-line'.  So it is
> > approximately a 'start-of-line' anchor.

> Mea culpa.  I thought I checked that first.  See, I *told*
> Kragen I wasn't a wizard.  :-)

> So how in the Sam Hill is 'bin' at the very beginning of a line
> with no prior spaces ever going to match anything output from
> `ps -ef` ?  It doesn't come close on the versions of ps with
> which I am familiar.

Well, $/ could be "\n     ", which would match a user 'bin' on my HP-Ux
system.  But what about that '/' after 'bin'?  I agree, it's hopeless.

--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/



Wed, 18 Jun 1902 08:00:00 GMT  
 Perl Wizards
On Wed, 10 Nov 1999 16:55:16 -0800, David Cassell

Quote:

>But I don't consider myself a Perl wizard.  Just a satisfied
>customer.  Abigail, Larry, Uri, Damian...  They're wizards.

I'm a Perl Druid, if that's any help.  :-)

dha

--

America leads the world in shocks.
        - Gil Scott-Heron



Wed, 18 Jun 1902 08:00:00 GMT  
 Perl Wizards

Quote:

> On Wed, 10 Nov 1999 16:55:16 -0800, David Cassell

> >But I don't consider myself a Perl wizard.  Just a satisfied
> >customer.  Abigail, Larry, Uri, Damian...  They're wizards.

> I'm a Perl Druid, if that's any help.  :-)

I didn't mean to slight a fellow Member Of The Tribe, but
it seemed that adding what would look like my own first name
could be confusing, given the context.  :-)

David
--

Senior computing specialist
mathematical statistician



Wed, 18 Jun 1902 08:00:00 GMT  
 Perl Wizards

<URL::">
~~ On Wed, 10 Nov 1999 16:55:16 -0800, David Cassell
~~
~~ >But I don't consider myself a Perl wizard.  Just a satisfied
~~ >customer.  Abigail, Larry, Uri, Damian...  They're wizards.
~~
~~ I'm a Perl Druid, if that's any help.  :-)

I hope you live close to Central Park....

Abigail
--
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
                                      print } sub __PACKAGE__ { &
                                      print (     __PACKAGE__)} &
                                                  __PACKAGE__
                                            (                )

  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 18 post ]  Go to page: [1] [2]

 Relevant Pages 

1. A question to Perl wizards

2. A call to PERL wizards

3. One for the Perl Wizards...

4. Perl Wizard Quiz

5. Any CGI/Perl Wizards in Utah?

6. RFQ: Tk::Wizard - a wizard style widget for Perl/Tk

7. RFQ: Tk::Wizard - a wizard style widget for Perl/Tk

8. Answers to questions the Perl wizards won't answer!

9. Perl for Netware wizards out there?

10. HELP: (please help, wizards) Memory problems

11. Defining a wizard (was: Okay...)

 

 
Powered by phpBB® Forum Software