[24795] in Perl-Users-Digest
Perl-Users Digest, Issue: 6948 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 2 18:06:19 2004
Date: Thu, 2 Sep 2004 15:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 2 Sep 2004 Volume: 10 Number: 6948
Today's topics:
Re: ActivePerl and @INC on Win2k <rene.larsen@spamfilter.dk>
Re: C<sub'a>? (Anno Siegel)
Re: New to perl <matternc@comcast.net>
Newbie needs help on pattern matching <msdebian@yahoo.com>
Re: Newbie needs help on pattern matching <tadmc@augustmail.com>
Re: Newbie needs help on pattern matching <nobull@mail.com>
Re: Newbie needs help on pattern matching (Kenny McCormack)
PLJava module need help (harris)
Re: RE-Redirecting STDOUT <nobull@mail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 02 Sep 2004 22:49:41 +0200
From: René Larsen <rene.larsen@spamfilter.dk>
Subject: Re: ActivePerl and @INC on Win2k
Message-Id: <VA.00000001.00d0c6b2@spamfilter.dk>
In article <53867fbe.0409020449.763156e3@posting.google.com>, Horst
Walter wrote:
>
> I have just installed ActivePerl and want to start the ppm. There I
> get the following error
>
> Can't locate Win32/TieRegistry.pm in @INC (@INC contains:
> C:/ActivePerl/5.8.4/lib .) at C:\ActivePerl\5.8.4\bin\ppm.bat line 15.
It seems like ActiveState have made an error.
Try starting a DOS shell (AKA Command prompt) and type the following:
set PERL5LIB=C:/ActivePerl/5.8.4/site/lib
ppm
and see if the problem is solved. If it is, you need to get Windows to
set this environment variable.
Regards, René
------------------------------
Date: 2 Sep 2004 20:45:31 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: C<sub'a>?
Message-Id: <ch80pb$nhd$1@mamenchi.zrz.TU-Berlin.DE>
Juha Laiho <Juha.Laiho@iki.fi> wrote in comp.lang.perl.misc:
> Michele Dondi <bik.mido@tiscalinet.it> said:
> >A friend of mine has just written his first japh. A thing that I
> >couldn't understand at first[*], and that continued puzzling for quite
> >a while is a small fragment of code along the lines of
> >
> > sub'a{that does something}
>
> Ok...
>
> >At first I was surprised that such a beast did even parse,
>
> "Me too!"
>
> >but now I'm highly confident I've understood why it does, although not
> >*completely* sure...
> >
> >Well, here it comes: in earlier versions of perl you used e.g.
> >C<<$pkg'var>> instead of C<<$pkg::var>>, and that syntax is still
> >supported for backwards compatibility, so
> >
> > sub'a
> >
> >should be equivalent to
> >
> > sub ::a # a.k.a. main::a
>
> Something akin to that would've been my guess as well - but the truth
> seems different. Check what you get from the perl parser for each
> of these:
> perl -MO=Deparse -e "sub'a{9} print a;"
> perl -MO=Deparse -e "sub::a{9} print a;"
Put a blank between the sub keyword and the following name, that
removes an ambiguity. The second example is parsed entirely different
from what's intended.
Perl thinks "sub::a" is a method name and {9} is a block in indirect
object position (the lexer's catch-all, it seems). What follows are
parameters for the method call, only one in this case, namely what is
returned from "print a". At run-time this would result in a fatal
error. Perl will find that 9 is neither an object nor a class name,
so it can't call anything through it.
So don't be fooled by that result, it is bogus in this context.
"sub ::a{9}" and "sub 'a{9}" compile indeed the same code.
Anno
------------------------------
Date: Thu, 02 Sep 2004 16:33:10 -0400
From: Chris Mattern <matternc@comcast.net>
Subject: Re: New to perl
Message-Id: <TIWdnauwmf4bHqrcRVn-vQ@comcast.com>
David K. Wall wrote:
> Gus <gmestousis@yahoo.com> wrote in message
> <news:e7bef82a.0409020822.43ccd9a7@posting.google.com>:
>
>> I want to cat /admin/log/fileA, and grep any lines that have the
>> name "joe", then send the output to /admin/log/fileB. Then I want
>> to view /admin/log/fileB
>
> Why use Perl for this when you have other tools to make it easy?
>
> grep "joe" /admin/log/fileA | tee /admin/log/fileB | less
>
> I don't know why you need to save the grepped stuff to fileB, but tee
> will do it.
It's September. I smell homework.
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Thu, 02 Sep 2004 16:37:18 -0400
From: Madhusudan Singh <msdebian@yahoo.com>
Subject: Newbie needs help on pattern matching
Message-Id: <2ppejjFnj5lcU1@uni-berlin.de>
Hi
I am kind of new to perl (dabbled in it a little bit 4-5 years ago, but
never needed it till now - I am writing an application).
I need to extract some info from /sbin/iwconfig eth1 :
$ /sbin/iwconfig eth1 | grep "Link"
Link Quality:90/92 Signal level:-8 dBm Noise level:-148 dBm
(updated)
I want to extract 90/92 from the stuff above. How do I code it ?
If it is possible to use awk to do the above ('{print $2}' yields
"Quality:90/92", when I need to extract 90/92 or even better 90 and 92
separately, that is also ok.
How does one embed an awk command in perl ? I tried :
$info=`/sbin/iwconfig eth1 | grep "Link" | awk '{print $2}'`; but it did
not work (just reproduced o/p as if the second pipe were not even present).
Thanks.
------------------------------
Date: Thu, 2 Sep 2004 16:08:21 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Newbie needs help on pattern matching
Message-Id: <slrncjf2u5.dai.tadmc@magna.augustmail.com>
Madhusudan Singh <msdebian@yahoo.com> wrote:
> I need to extract some info from
> Link Quality:90/92 Signal level:-8 dBm Noise level:-148 dBm
> I want to extract 90/92 from the stuff above. How do I code it ?
with the m// operator and the appropriate regex.
if ( $_ =~ m/Link Quality:(\S*)/ ) {
$qual = $1;
}
> I need to extract 90/92 or even better 90 and 92
> separately,
Use a m// in list context instead of the above then:
my($first, $second) = $_ =~ m!Link Quality:(\d+)/(\d+)!;
> How does one embed an awk command in perl ? I tried :
^^^^^^^
^^^^^^^
The same way you embed any other external program call in Perl.
Please spend a few seconds searching the Perl FAQ *before* posting
to the Perl newsgroup.
perldoc -q command
Q: How can I capture STDERR from an external command?
A: There are three basic ways of running external commands: ...
Or, write what you need in awk, and then run it through the "a2p"
(awk to Perl) translator program that ships with the perl distribution.
But anything you can do with awk, you can do with native Perl, so
you don't need to shell-out to awk anyways. :-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 02 Sep 2004 22:49:12 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Newbie needs help on pattern matching
Message-Id: <ch84gn$s0q$1@slavica.ukpost.com>
Madhusudan Singh wrote:
> Subject: Newbie needs help on pattern matching
Subject lines are important don't waste space with words like "Newbie
needs help on" that carry no valusable information. The waste of space
in the subject lines only serves to predispose people against you.
> I am kind of new to perl (dabbled in it a little bit 4-5 years ago, but
> never needed it till now - I am writing an application).
>
> I need to extract some info from /sbin/iwconfig eth1 :
>
> $ /sbin/iwconfig eth1 | grep "Link"
>
> Link Quality:90/92 Signal level:-8 dBm Noise level:-148 dBm
> (updated)
>
> I want to extract 90/92 from the stuff above. How do I code it ?
It is more easily done in a single step.
my ($link_quality) = `/sbin/iwconfig eth1` =~ /Link Quality:(\S+)/;
Note: this isn't very smart wrt errors. If the command fails in any way
to emit the string 'Link Quality:' then $link_quality will simply be
undefined.
>
> If it is possible to use awk to do the above ('{print $2}' yields
> "Quality:90/92", when I need to extract 90/92 or even better 90 and 92
> separately, that is also ok.
>
> How does one embed an awk command in perl ? I tried :
Why would you want to? You can usually simply re-state it more simply
in Perl.
>
> $info=`/sbin/iwconfig eth1 | grep "Link" | awk '{print $2}'`; but it did
> not work (just reproduced o/p as if the second pipe were not even present).
The `` quoting construct is interpolative - if you want to put a literal
$ into the command that is passed to /bin/sh you'll need to escape it
with a backslash. If you don't then the $2 in the command will be
replaced with the value of the Perl variable $2.
BTW: Did you perhaps "forget" to enable warnings in Perl?
Do not attempt to learn to free-climb from the outset. Learn to climb
with ropes. Then and only then should you consider sometimes going
without. It may seem like more work - right upto the point where you
first slip and fall.
In Perl the ropes are 'strict' and 'warnings'. If you have problems
because to fail to use these the expericenced climbers are not going to
be very sympathetic.
------------------------------
Date: Thu, 02 Sep 2004 22:00:21 GMT
From: gazelle@yin.interaccess.com (Kenny McCormack)
Subject: Re: Newbie needs help on pattern matching
Message-Id: <ch85ik$8an$1@yin.interaccess.com>
In article <2ppejjFnj5lcU1@uni-berlin.de>,
Madhusudan Singh <msdebian@yahoo.com> wrote:
...
> How does one embed an awk command in perl ? I tried :
The same way one embeds a few extra greps, seds, cuts, pastes, and, don't
forget, one or more UUOCs.
------------------------------
Date: 2 Sep 2004 12:17:18 -0700
From: harris_m@yahoo.com (harris)
Subject: PLJava module need help
Message-Id: <af968c64.0409021117.6659fd7c@posting.google.com>
I am using PLJava module on Windows 2k. The module compiled and test
program works okay.
I tried following code which does not run and it crashes.
import perl5.Perl ;
import perl5.SV ;
public class testsub {
public static void main(String argv[]) {
Perl.eval("print qq`Hello World!\n` ;") ;
///////////////////
SV foo = Perl.NEW("foo") ; // $foo = new foo() ;
foo.call("test", "123,456") ; // $foo->test(123,456) ;
}
}
There is separate file foo.pm in same path where java class file is
located, which is not found by above testsub program. foo.pm looks as
follows-
#
#foo.pm
package foo;
sub new {
bless{};
}
sub test {
print print qq`FOO>> @_\n`
}
sub DESTROY {
print qq`DEST>> @_\n` ;
}
1;
Any ideas why this fails? Thanks in advance.
Harris M.
------------------------------
Date: Thu, 02 Sep 2004 20:08:04 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: RE-Redirecting STDOUT
Message-Id: <ch7r2j$q1e$1@slavica.ukpost.com>
aisarosenbaum@yahoo.com wrote:
> No I'm not a stuttering typist. ;^)
>
> I'm in the pecular position of working in an environment in which
> STDOUT has been rudely redirected by a script (A) that runs my
> scripts (B). I want to take STDOUT back without knowing the
> handle to which it was redirected. I've found a lot of advise
> on redirecting STDOUT, but I need to re-redirect it back to the
> console from 'B' without hacking 'A'.
>
> (This is on Solaris)
On Unix-like OS opening the virual device /dev/tty opens the current
session's controling terminal.
This, of course, has nothing to do with Perl.
>
> Any ideas?
>
> Aisa
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 6948
***************************************