[24588] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 6764 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 3 21:05:39 2004

Date: Sat, 3 Jul 2004 18:05:05 -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           Sat, 3 Jul 2004     Volume: 10 Number: 6764

Today's topics:
        access ARP table in Win32 <perlcdr@mail.rumania>
    Re: access ARP table in Win32 <Petri_member@newsguy.com>
    Re: access ARP table in Win32 <perlcdr@mail.rumania>
    Re: Deleting blank elements from a list (dutone)
    Re: Deleting blank elements from a list <noreply@gunnar.cc>
    Re: Logfile name hack <Joe.Smith@inwap.com>
    Re: My 1st question about locking (and other related is <nilram@hotpop.com>
    Re: Newbie: How do I  filter output to the screen and w (Mav)
    Re: Newbie: How do I  filter output to the screen and w <jurgenex@hotmail.com>
    Re: Newbie: How do I  filter output to the screen and w <daedalus@videotron.ca>
    Re: Newbie: How do I  filter output to the screen and w <jurgenex@hotmail.com>
    Re: Newbie: How do I  filter output to the screen and w <daedalus@videotron.ca>
    Re: Newbie: How do I  filter output to the screen and w <Joe.Smith@inwap.com>
    Re: perl vs Unix grep (Anno Siegel)
        Search using a variable in a Perl Script (Philip Scobie)
    Re: Search using a variable in a Perl Script <norfernuman@yahoo.com>
    Re: Search using a variable in a Perl Script <invalid-email@rochester.rr.com>
    Re: win32::job window attributes <Petri_member@newsguy.com>
    Re: win32::job window attributes <MrReallyVeryNice.NOVIRUS@NoSpam.yahoo.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sat, 03 Jul 2004 20:21:54 GMT
From: perl coder <perlcdr@mail.rumania>
Subject: access ARP table in Win32
Message-Id: <CzEFc.2008$w56.989@bignews1.bellsouth.net>

I need to read the contents of the ARP table from a Win32 GUI program
(ActiveState "perlapp -gui" binary).  Since the -gui switch disables
the stdin/out/err file descriptors, I can't just parse the output from
arp.exe or even redirect it to a file.  So I need a way to access the ARP
tables from wherever arp.exe is getting its data from (presumably a system
call).  Is there a module that does this?  Or does anyone happen to know
which system call? (maybe Win32-API will work then)


-- 
No crazy stuff in my email. ;-)


------------------------------

Date: 3 Jul 2004 14:27:01 -0700
From: Petri <Petri_member@newsguy.com>
Subject: Re: access ARP table in Win32
Message-Id: <cc78b505uc@drn.newsguy.com>

In article <CzEFc.2008$w56.989@bignews1.bellsouth.net>, perl coder says...
> So I need a way to access the ARP tables from wherever arp.exe
> is getting its data from (presumably a system call).
> Is there a module that does this?

Why ask when you can look for yourself?

http://search.cpan.org/search?query=ARP&mode=all

>Or does anyone happen to know which system call? (maybe Win32-API will work
>then)

What did you find when you searched for it?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/getipnettable.asp


Petri



------------------------------

Date: Sun, 04 Jul 2004 00:48:19 GMT
From: perl coder <perlcdr@mail.rumania>
Subject: Re: access ARP table in Win32
Message-Id: <ntIFc.3467$w56.509@bignews1.bellsouth.net>

Petri said:
> Why ask when you can look for yourself?

Cause I'm programming in windows and it's making my brain hurt. :-(
 
> What did you find when you searched for it?

I found stuff about a GetIpNetTable system call that doesn't work in
Win95 or WinNT before sevice pack 4.  And apparently before that you had
to use SNMP to access some local MIB table.  That's crazy talk!

Well at least I don't have to parse the registry. :-) :-) :-)

> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/getipnettable.asp

Thanks.  But how come when I follow this URL with Lynx, Microsoft
decides to hijack my browser and take me to this place instead:
http://msdn.microsoft.com/library/shared/deeptree/bot/bot.asp?dtcnfg=/library/deeptreeconfig.xml

We hates the Microsoft!  We hates them!


-- 
No crazy stuff in my email. ;-)


------------------------------

Date: 3 Jul 2004 14:00:35 -0700
From: dutone@hotmail.com (dutone)
Subject: Re: Deleting blank elements from a list
Message-Id: <7d56a4da.0407031300.1120b29a@posting.google.com>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<2kjvicF361rgU1@uni-berlin.de>...
> Just in wrote:
> > If I do this:-
> > 
> > use strict;
> > use warnings;
> > 
> > my @Arr1 = split /\D+/, $Str1;
> > my @Arr2 = split /\D+/, $Str2;
> > 
> > foreach my $i(0..$#Arr1)
> > {
> >     foreach my $j(0..$#Arr2)
> 
> To increase efficiency and prevent uninitialized warnings:
> 
>      foreach my $j (reverse 0..$#Arr2)
> 
> >     {
> >         if($Arr1[$i] eq $Arr2[$j])
> >         {
> >             delete $Arr2[$j];
> 
>      splice @Arr2, $j, 1;
> 
> >         }
> >     }
> > }
> > 
> > In some instances @Arr2 ends up looking like this ('', '',
> > 'Value3', Value4', '')
> > 
> > How can I make @Arr2 = ('Value3', 'Value4') i.e. $#Arr2 == 1
> > rather than 4?
> 
> See suggestions above. You should also study
> 
>      perldoc -q duplicate


You suggested....  

To increase efficiency and prevent uninitialized warnings:
     foreach my $j (reverse 0..$#Arr2)

Can you tell me how this will increase efficiency?

Thanks


------------------------------

Date: Sun, 04 Jul 2004 00:26:02 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Deleting blank elements from a list
Message-Id: <2koqhcF46m1sU1@uni-berlin.de>

dutone wrote:
> Gunnar Hjalmarsson wrote:
>>To increase efficiency and prevent uninitialized warnings:
>>
>>     foreach my $j (reverse 0..$#Arr2)
> 
> Can you tell me how this will increase efficiency?

Fewer iterations under certain conditions, and (I think) more accurate 
result. Please consider this code:

     my $Str1 = '1 2 3 4 5';
     my $Str2 = '1 1 2 2 6';
     my $iter;

     my @Arr1 = split /\D+/, $Str1;
     my @Arr2 = split /\D+/, $Str2;

     for my $i (0..$#Arr1) {
         for my $j (0..$#Arr2) {
             if ($Arr1[$i] eq $Arr2[$j]) {
                 splice @Arr2, $j, 1;
             }
             $iter++;
         }
     }

     print "Left in \@Arr2: @Arr2\n";
     print "$iter iterations\n";

Besides a couple of "uninitialized" warnings it outputs:
Left in @Arr2: 1 2 6
18 iterations

But if you change

         for my $j (0..$#Arr2) {

to

         for my $j (reverse 0..$#Arr2) {

it outputs:
Left in @Arr2: 6
11 iterations

(and no warnings).

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: Sat, 03 Jul 2004 21:23:56 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Logfile name hack
Message-Id: <QrDFc.19752$Oq2.12787@attbi_s52>

magoo wrote:

> After much consideration, I am going to go with this now:
>  chomp($date = `date`);

Why are you calling an external program to do that?
Using localtime() in scalar context returns everything but the timezone.
    $date = localtime();

	-Joe


------------------------------

Date: 03 Jul 2004 16:22:25 -0500
From: Dale Henderson <nilram@hotpop.com>
Subject: Re: My 1st question about locking (and other related issues)
Message-Id: <87pt7c3hwu.fsf@camel.tamu-commerce.edu>

>>>>> "MD" == Michele Dondi <bik.mido@tiscalinet.it> writes:

    MD> On 01 Jul 2004 21:26:25 -0500, Dale Henderson
    MD> <nilram@hotpop.com>
    MD> wrote:

    >> Another approach would be to write the pid into the
    >> "lockfile". This would allow for the possibility of checking
    >> for stale lock files although I do not know of any good way to
    >> check for a process given a pid or verify it's the correct
    >> process (i.e. not another process that just happens to have
    >> inherited your pid).

    MD> As a wild guess I'd say that this approach would tend to be
    MD> more complicated than that suggested before, but indeed I've
    MD> seen something along these lines...

     Unfortunately it would be MUCH more complicated.

     
    >> This also allows for a "kill" script in the .bash_logout that
    >> would open the "lockfile" and send an appropriate signal to the
    >> specified pid. Of course this is problematic for it would kill
    >> your sigfile "daemon" when the first shell exited. I presume
    >> you would want the "daemon" to continue until the last shell
    >> exited.

    MD> Well, I think that *if* I have a duplicate processes
    MD> prevention mechanism *and* if it continues until the shell it
    MD> was started from is exited, *then* that shell will be "the
    MD> last to be exited".

     I don't follow this. Consider: 

     Shell 1 starts (daemon starts)

     Shell 2 starts
     
     Shell 1 exits (daemon stops)

     Shell 2 exits

     So the daemon stops with shell 1 but shell 2 is the last to exit.


-- 
Dale Henderson 

"Imaginary universes are so much more beautiful than this stupidly-
constructed 'real' one..."  -- G. H. Hardy


------------------------------

Date: 3 Jul 2004 12:53:16 -0700
From: mluvw47@yahoo.com (Mav)
Subject: Re: Newbie: How do I  filter output to the screen and writing the orginal output to a file?
Message-Id: <dfaafecd.0407031153.34043659@posting.google.com>

Yes, system(@args) on my case will give me the build output on the
screen.
'coz the args I parse in is execute an application that will print all
the step on the screen.

However, I want to print out only certain pattern on the screen, at
the same time got the orginal output into the log file. (If you look
at my orginal post).

Regards,
Mav


Tad McClellan <tadmc@augustmail.com> wrote in message news:<slrncecj4l.ag4.tadmc@magna.augustmail.com>...
> Mav <mluvw47@yahoo.com> wrote:
> 
> > I need to execute (using system(@args)) in order to get the output. 
> 
> 
> system() does not give you the output!
> 
> You need something else ("perldoc -f system" may suggest what "else" is).
> 
> 
> [ snip 50 lines of upside-down full-quote.
>   Please do not do that.
> ]


------------------------------

Date: Sat, 03 Jul 2004 20:18:01 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Newbie: How do I  filter output to the screen and writing the orginal output to a file?
Message-Id: <ZvEFc.5306$Xq4.1588@nwrddc02.gnilink.net>

Mav wrote:
> Yes, system(@args) on my case will give me the build output on the
> screen.
> 'coz the args I parse in is execute an application that will print all
> the step on the screen.

And exactly that is the problem. system() doesn't capture the output. This
means
- your application still prints to the terminal
- your Perl program never recieves the output, doesn't know about it, can't
process it, can't filter it, can't do anything with it.

> However, I want to print out only certain pattern on the screen, at
> the same time got the orginal output into the log file. (If you look
> at my orginal post).

Then --as other have suggested already-- use a different method to call the
external application. A method that allows your Perl program to capture and
process the output as needed.

jue




------------------------------

Date: Sat, 3 Jul 2004 16:54:31 -0400
From: "Daedalus" <daedalus@videotron.ca>
Subject: Re: Newbie: How do I  filter output to the screen and writing the orginal output to a file?
Message-Id: <w%EFc.74691$t55.1936208@wagner.videotron.net>

> And exactly that is the problem. system() doesn't capture the output. This
> means

OReilly's Learning Perl (3rd Ed)
"The system function:
 ...The child process inherits Perl's standard input, standard output, and
standard error..."

There must be something I'm missing.





------------------------------

Date: Sat, 03 Jul 2004 21:06:34 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Newbie: How do I  filter output to the screen and writing the orginal output to a file?
Message-Id: <udFFc.5030$6e7.3322@nwrddc03.gnilink.net>

Daedalus wrote:
>> And exactly that is the problem. system() doesn't capture the
>> output. This means
>
> OReilly's Learning Perl (3rd Ed)
> "The system function:
> ...The child process inherits Perl's standard input, standard output,
> and standard error..."
>
> There must be something I'm missing.

Maybe you are missing the meaning of "inherits".
If e.g. the file descriptor STDOUT in the Perl program is linked to a file
"foobar", then the child process will inherit this connection, i.e. in the
child process STDOUT will be linked to "foobar", too.

jue




------------------------------

Date: Sat, 3 Jul 2004 18:31:52 -0400
From: "Daedalus" <daedalus@videotron.ca>
Subject: Re: Newbie: How do I  filter output to the screen and writing the orginal output to a file?
Message-Id: <HqGFc.76921$t55.1974345@wagner.videotron.net>

> >> And exactly that is the problem. system() doesn't capture the
> >> output. This means
> >
> > OReilly's Learning Perl (3rd Ed)
> > "The system function:
> > ...The child process inherits Perl's standard input, standard output,
> > and standard error..."
> >
> > There must be something I'm missing.
>
> Maybe you are missing the meaning of "inherits".
> If e.g. the file descriptor STDOUT in the Perl program is linked to a file
> "foobar", then the child process will inherit this connection, i.e. in the
> child process STDOUT will be linked to "foobar", too.

Ok I think I got it. Is this would be a good way to capture the child
process output into perl ?

open PROCRETURN, "@ARGV|"

or maybe

@procreturn = `@ARGV`


Thanks
DAE





------------------------------

Date: Sat, 03 Jul 2004 19:09:31 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Newbie: How do I  filter output to the screen and writing the orginal output to a file?
Message-Id: <LvDFc.17974$a24.5834@attbi_s03>

Mav wrote:

> At the same time, how do I only print the following on the screen?
> #To screen
> Build Item A
> Build Item B 
> How do I filter the STDOUT(to file) at the same time output to screen?

   print OLDSTDOUT "Build Item A\n";
   system(@args_A);
   print OLDSTDOUT "Build Item B\n";
   system(@args_B);

	-Joe


------------------------------

Date: 3 Jul 2004 23:55:21 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perl vs Unix grep
Message-Id: <cc7h19$4v4$1@mamenchi.zrz.TU-Berlin.DE>

Al Belden <abelden@comcast.net> wrote in comp.lang.perl.misc:
> Hi all,
>     I've been working on a problem that I thought might be of interest: I'm
> trying to replace some korn shell scripts that search source code files with
> perl scripts ...

[...]

> 1. Reading each file a line at a time, testing for a match and keeping a
> line counter or using $NR or $..
> 2. Reading the file into an array and processing a line at a time
> 3. Creating index files for the source files that store line offsets and
> using them with the slurp method in the paragraph above
> 4. Creating an in-memory index for each file that contains a match and using
> it for subsequent matches in that file
> 
> 1, 2 and 4 above suffer performance degradation relative to unix grep. #3
> provides good performance and is the method I am currently using but it
> requires creating and maintaining index files. I was wondering if I could
> tie a scalar to a file and use the slurping loop above. Then perhaps $NR and
> $. would contain the current line number as the file would be read as the
> loop is traversed. Any other ideas would be welcome

The Tie::File module (a standard module) ties a file not to a scalar
but an array of lines.  Line numbers are then represented as the
array index (starting at 0).  The behavior of grep -n can be simulated
like this:

    use Tie::File;

    my @line;
    tie @line, 'Tie::File', $_ or
        die "can't tie file '$_': $!" for '/tmp/x';

    print "$_:$line[ $_ - 1]\n" for
        grep $line[ $_ - 1] =~ /aaa/, 1 .. @line;

No idea about performance, but I'd give it a try.

Anno


------------------------------

Date: 3 Jul 2004 16:51:07 -0700
From: philipscobie@hotmail.com (Philip Scobie)
Subject: Search using a variable in a Perl Script
Message-Id: <d2c030d8.0407031551.28a27119@posting.google.com>

I am searching "myfile.txt" which looks like this:

Perl.1234
HTML.1234
PHP.1234
CGI.1234

I am trying to print a single line based on a variable name, such as
"Perl" or "HTML". Maybe if I show you my code it will make more sense:


my $value = param ('incoming_parameter')   (e.g. 'Perl')

open (LOG, "myfile.txt");
while (<LOG>){
   if(/$value/){      <-Search for the word "Perl"???
       print $_;      <-If matched, print the current line.
   }
}


With an 'incoming_parameter' of "Perl", it should match and print
"Perl.1234". But it doesn't.

HELP!


------------------------------

Date: Sat, 03 Jul 2004 23:58:01 GMT
From: norfernuman <norfernuman@yahoo.com>
Subject: Re: Search using a variable in a Perl Script
Message-Id: <dKHFc.10646$Kj4.10248@newssvr27.news.prodigy.com>

Philip Scobie wrote:
> I am searching "myfile.txt" which looks like this:
> 
> Perl.1234
> HTML.1234
> PHP.1234
> CGI.1234
> 
> I am trying to print a single line based on a variable name, such as
> "Perl" or "HTML". Maybe if I show you my code it will make more sense:
> 
> 
> my $value = param ('incoming_parameter')   (e.g. 'Perl')
> 
> open (LOG, "myfile.txt");
> while (<LOG>){
>    if(/$value/){      <-Search for the word "Perl"???
>        print $_;      <-If matched, print the current line.
>    }
> }
> 
> 
> With an 'incoming_parameter' of "Perl", it should match and print
> "Perl.1234". But it doesn't.
> 
> HELP!

Google this group archive for 'Tad', 'test open'


------------------------------

Date: Sun, 04 Jul 2004 00:51:08 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Search using a variable in a Perl Script
Message-Id: <40E7547B.2000800@rochester.rr.com>

Philip Scobie wrote:

> I am searching "myfile.txt" which looks like this:
> 
> Perl.1234
> HTML.1234
> PHP.1234
> CGI.1234
> 
> I am trying to print a single line based on a variable name, such as
> "Perl" or "HTML". Maybe if I show you my code it will make more sense:
> 
> 
> my $value = param ('incoming_parameter')   (e.g. 'Perl')


Your "code" doesn't compile.  Don't say you're showing us your code if 
you aren't.


> 
> open (LOG, "myfile.txt");


How do you know your open statement is succeeding?  I'll bet when your 
CGI script runs, it's not running with the current directory set where 
you think it is.  Modify the above to something like:

   open LOG,'myfile.txt' or die "Oops, couldn't open myfile.txt, $!";

and

   use CGI::Carp qw(fatalsToBrowser);

Then when you see the file isn't there, specify the absolute path to 
your data file when you open it.


> while (<LOG>){
>    if(/$value/){      <-Search for the word "Perl"???
>        print $_;      <-If matched, print the current line.
>    }
> }
> 
> 
> With an 'incoming_parameter' of "Perl", it should match and print
> "Perl.1234". But it doesn't.
> 
> HELP!
> 

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



------------------------------

Date: 3 Jul 2004 13:52:19 -0700
From: Petri <Petri_member@newsguy.com>
Subject: Re: win32::job window attributes
Message-Id: <cc76a30316r@drn.newsguy.com>

In article <e4dad21a.0407030706.279bda92@posting.google.com>, Cameron says...
> but the application (a bastardized copy of wIntegrate used by car
> dealers to access an old PICK system from Reynolds & Reynolds) still
> refuses to open in a minimised window.

You could of course use SendKeys to send alt-space, n to the window when it
opens.

http://search.cpan.org/search?query=sendkeys&mode=all

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsmthsendkeys.asp


Petri



------------------------------

Date: Sat, 3 Jul 2004 17:44:46 -0700
From: "MrReallyVeryNice" <MrReallyVeryNice.NOVIRUS@NoSpam.yahoo.com>
Subject: Re: win32::job window attributes
Message-Id: <2LidnU4-VY1iz3rdRVn-jw@comcast.com>

Hello again,

In addition to trying SendKeys as suggested by Petri, you might also
validate if your application (Link32.exe) has not been built/compiled with
the wrong switch. In which case no matter what you try, you will not be able
to minimize/hide it.

In the spirit of helping you debugging this problem, and certainly not
trying to drive you away from Perl, I would suggest that you take a look at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/pla
tform/shell/reference/objects/ishelldispatch2/shellexecute.asp. If you
create a small VBScript, you will have a second data point. If you are
successful with a VBScript then you can decide to debug Win32::Job or try to
find another Perl module.

Here is a little untested sample program with Link32:
=== Beginning Script ===
Option Explicit
fnShellExecuteVB()

function fnShellExecuteVB()
    dim objShell
    set objShell = CreateObject("Shell.Application")
    objShell.ShellExecute "Link32.exe", "", "D:\Link32", "open", 2
    set objShell = nothing
end function
=== End Script ===

As earlier, please report your failures/successes.
MrReallyVeryNice




------------------------------

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 6764
***************************************


home help back first fref pref prev next nref lref last post