[29576] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 820 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 4 21:09:39 2007

Date: Tue, 4 Sep 2007 18:09:07 -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           Tue, 4 Sep 2007     Volume: 11 Number: 820

Today's topics:
    Re: Get file list over http <rohit.makasana@gmail.com>
        How to 'use' all of libwww-perl-5.808 from a local inst <perl4hire@softouch.on.ca>
    Re: How to 'use' all of libwww-perl-5.808 from a local  <noreply@gunnar.cc>
    Re: How to 'use' all of libwww-perl-5.808 from a local  <perl4hire@softouch.on.ca>
    Re: How to 'use' all of libwww-perl-5.808 from a local  <noreply@gunnar.cc>
    Re: How to 'use' all of libwww-perl-5.808 from a local  <perl4hire@softouch.on.ca>
    Re: How to generate http error in script <spamtrap@dot-app.org>
        implementation of system() <markhn@rpi.edu>
    Re: implementation of system() <klaus03@gmail.com>
    Re: implementation of system() (Alan Curry)
    Re: implementation of system() <nospam-abuse@ilyaz.org>
    Re: implementation of system() <ben@morrow.me.uk>
    Re: implementation of system() (Alan Curry)
    Re: implementation of system() <nospam-abuse@ilyaz.org>
    Re: Monitoring a list? <ben@morrow.me.uk>
    Re: Monitoring a list? <jismagic@gmail.com>
        Perl variable to shell command...? <rohit.makasana@gmail.com>
    Re: Perl variable to shell command...?  usenet@DavidFilmer.com
    Re: Perl variable to shell command...? <rohit.makasana@gmail.com>
    Re: Perl variable to shell command...? <tadmc@seesig.invalid>
    Re: Perl variable to shell command...? <glex_no-spam@qwest-spam-no.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 04 Sep 2007 21:50:53 -0000
From:  Rohit <rohit.makasana@gmail.com>
Subject: Re: Get file list over http
Message-Id: <1188942653.961964.67650@19g2000hsx.googlegroups.com>

On Sep 2, 3:59 pm, Christian Winter <thepoet_nos...@arcor.de> wrote:
> Rohitwrote:
> > Hi, I am trying to write a script, which downloads files over http. I
> > am usingcurlcommand to download the file, but usingcurlI have to
> > pass filename. Filename on server would be changing frequently, so is
> > there any way to get list of files over http? Once I get filename,
> > then I can pass that filename tocurland download the file.
>
> > I would also be thankful, if you can suggest any other way to achieve
> > this task.
>
> To 'get a list of files over http' usually means to retrieve
> the index of a directory. Depending on the configuration of
> the server, this may be allowed/provided or not. If the browser
> displays an explorer-like view when accessing a URL ending with
> a directory name, it serves back a html page with a list of
> links to each file.
>
> To retrieve this index page, you can use the LWP::Simple module.
> To extract links from the page, HTML::LinkExtor or HTML::TreeBuilder
> can aid you. If you have successfully extracted the links (all
> modules come with a number of examples) you can once again
> use LWP::Simple and retrieve the files directly to disk with its
> getstore() method.
>
> HTH
> -Chris
>
> --
> print +(chr(-32+ord)^("Only Waiting for  Perl 6" =~
> /./g)[$c++])for('%;?- V/& !+5 V* l 8$1\'ed'=~/./g);

Thanks Chris, It works great.



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

Date: Tue, 04 Sep 2007 16:31:04 -0400
From: Amer Neely <perl4hire@softouch.on.ca>
Subject: How to 'use' all of libwww-perl-5.808 from a local install
Message-Id: <NejDi.1497$k22.1334@read2.cgocable.net>

I'm trying to get WWW::Mechanize to work on a client's server.

However, it requires newer versions of some modules than are installed, 
so I'm trying to install them in a local directory myself. I don't have 
shell access so this all has to be done via a Perl script.

Instead of installing numerous individual modules, I'm attempting to 
install the newest libwww-perl-5.808:

#! /usr/bin/perl
use strict;
use warnings;
my @SysCmd;
@SysCmd=("perl -MCPAN -e 'install Bundle::LWP' PREFIX = 
/home/user241/cgi-bin/PerlMods");

After running this little script, I try to run my original one:

#! /usr/bin/perl
use strict;
use warnings;
use lib '/home/usr241/cgi-bin/PerlMods/WWW-Mechanize-1.18/lib';
use WWW::Mechanize;
 .
 .
 .

but I get this error:
HTTP::Request version 1.3 required--this is only version 1.27 at 
/home/usr241/cgi-bin/PerlMods/WWW-Mechanize-1.18/lib/WWW/Mechanize.pm 
line 101.
BEGIN failed--compilation aborted at 
/home/usr241/cgi-bin/PerlMods/WWW-Mechanize-1.18/lib/WWW/Mechanize.pm 
line 101.
Compilation failed in require at test_mech.1.pl line 14.
BEGIN failed--compilation aborted at test_mech.1.pl line 14.

So, is there a way I can tell my script/s to use the local modules for 
ALL of WWW::Mechanize?

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
"Others make web sites. We make web sites work!"


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

Date: Tue, 04 Sep 2007 22:48:54 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to 'use' all of libwww-perl-5.808 from a local install
Message-Id: <5k5uluF29nisU1@mid.individual.net>

Amer Neely wrote:
> ... I'm trying to install them in a local directory myself. I don't have 
> shell access so this all has to be done via a Perl script.
> 
> Instead of installing numerous individual modules, I'm attempting to 
> install the newest libwww-perl-5.808:
> 
> #! /usr/bin/perl
> use strict;
> use warnings;
> my @SysCmd;
> @SysCmd=("perl -MCPAN -e 'install Bundle::LWP' PREFIX = 
> /home/user241/cgi-bin/PerlMods");

But that script doesn't change anything, does it?

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


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

Date: Tue, 04 Sep 2007 17:00:30 -0400
From: Amer Neely <perl4hire@softouch.on.ca>
Subject: Re: How to 'use' all of libwww-perl-5.808 from a local install
Message-Id: <nGjDi.1499$k22.962@read2.cgocable.net>

Gunnar Hjalmarsson wrote:
> Amer Neely wrote:
>> ... I'm trying to install them in a local directory myself. I don't 
>> have shell access so this all has to be done via a Perl script.
>>
>> Instead of installing numerous individual modules, I'm attempting to 
>> install the newest libwww-perl-5.808:
>>
>> #! /usr/bin/perl
>> use strict;
>> use warnings;
>> my @SysCmd;
>> @SysCmd=("perl -MCPAN -e 'install Bundle::LWP' PREFIX = 
>> /home/user241/cgi-bin/PerlMods");
> 
> But that script doesn't change anything, does it?
> 

Well, it must have done something, because now I have ...

ftp> cd libwww-perl-5.808
250 "/cgi-bin/PerlMods/libwww-perl-5.808" is new cwd.
ftp> dir
200 PORT command successful.
150 Opening ASCII mode data connection for /bin/ls.
-rw-r--r--   1 usr241   usr241        4088 Dec  8  2005 AUTHORS
-rw-r--r--   1 usr241   usr241       92887 Aug  5 09:20 Changes
-rw-r--r--   1 usr241   usr241        5384 Aug  5 09:19 MANIFEST
-rw-r--r--   1 usr241   usr241       32061 Sep  4 16:02 Makefile
-rw-r--r--   1 usr241   usr241        7699 Jul 19 16:45 Makefile.PL
-rw-r--r--   1 usr241   usr241        3839 Dec  8  2005 README
-rw-r--r--   1 usr241   usr241        1217 Dec  1  1999 README.SSL
drwxr-xr-x   2 usr241   usr241        4096 Sep  4 16:02 bin
drwxr-xr-x   9 usr241   usr241        4096 Sep  4 16:02 lib
-rw-r--r--   1 usr241   usr241        9136 Nov 30  2004 lwpcook.pod
-rw-r--r--   1 usr241   usr241       25458 Nov 30  2004 lwptut.pod
drwxr-xr-x   8 usr241   usr241        4096 Sep  4 16:02 t
-rw-r--r--   1 usr241   usr241        1399 Jun  4  2006 talk-to-ourself

and under lib I have ...

ftp> cd lib
250 "/cgi-bin/PerlMods/libwww-perl-5.808/lib" is new cwd.
ftp> dir
200 PORT command successful.
150 Opening ASCII mode data connection for /bin/ls.
drwxr-xr-x   2 usr241   usr241        4096 Sep  4 16:02 Bundle
drwxr-xr-x   2 usr241   usr241        4096 Sep  4 16:02 File
drwxr-xr-x   2 usr241   usr241        4096 Sep  4 16:02 HTML
drwxr-xr-x   5 usr241   usr241        4096 Sep  4 16:02 HTTP
drwxr-xr-x   4 usr241   usr241        4096 Sep  4 16:02 LWP
-rw-r--r--   1 usr241   usr241       21427 Aug  5 09:23 LWP.pm
drwxr-xr-x   3 usr241   usr241        4096 Sep  4 16:02 Net
drwxr-xr-x   3 usr241   usr241        4096 Sep  4 16:02 WWW

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
"Others make web sites. We make web sites work!"


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

Date: Tue, 04 Sep 2007 23:20:40 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to 'use' all of libwww-perl-5.808 from a local install
Message-Id: <5k60hgF29st1U1@mid.individual.net>

Amer Neely wrote:
> Gunnar Hjalmarsson wrote:
>> Amer Neely wrote:
>>> ... I'm trying to install them in a local directory myself. I don't 
>>> have shell access so this all has to be done via a Perl script.
>>>
>>> Instead of installing numerous individual modules, I'm attempting to 
>>> install the newest libwww-perl-5.808:
>>>
>>> #! /usr/bin/perl
>>> use strict;
>>> use warnings;
>>> my @SysCmd;
>>> @SysCmd=("perl -MCPAN -e 'install Bundle::LWP' PREFIX = 
>>> /home/user241/cgi-bin/PerlMods");
>>
>> But that script doesn't change anything, does it?
> 
> Well, it must have done something, because now I have ...

<output from FTP program snipped>

Whatever you did to get those file there, you must have done something 
else but running the above script. The above script only assigns a 
string to the first element of the @SysCmd array...

Anyway, since you - one way or the other - seem to have installed the 
LWP bundle, did you possibly forget to add the path to the 'use lib' 
statement?

     use lib (
         '/home/usr241/cgi-bin/PerlMods/WWW-Mechanize-1.18/lib',
         '/home/usr241/cgi-bin/PerlMods/libwww-perl-5.808/lib',
     );

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


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

Date: Tue, 04 Sep 2007 17:44:54 -0400
From: Amer Neely <perl4hire@softouch.on.ca>
Subject: Re: How to 'use' all of libwww-perl-5.808 from a local install
Message-Id: <_jkDi.1503$k22.1492@read2.cgocable.net>

Gunnar Hjalmarsson wrote:
> Amer Neely wrote:
>> Gunnar Hjalmarsson wrote:
>>> Amer Neely wrote:
>>>> ... I'm trying to install them in a local directory myself. I don't 
>>>> have shell access so this all has to be done via a Perl script.
>>>>
>>>> Instead of installing numerous individual modules, I'm attempting to 
>>>> install the newest libwww-perl-5.808:
>>>>
>>>> #! /usr/bin/perl
>>>> use strict;
>>>> use warnings;
>>>> my @SysCmd;
>>>> @SysCmd=("perl -MCPAN -e 'install Bundle::LWP' PREFIX = 
>>>> /home/user241/cgi-bin/PerlMods");
>>>
>>> But that script doesn't change anything, does it?
>>
>> Well, it must have done something, because now I have ...
> 
> <output from FTP program snipped>
> 
> Whatever you did to get those file there, you must have done something 
> else but running the above script. The above script only assigns a 
> string to the first element of the @SysCmd array...
> 
> Anyway, since you - one way or the other - seem to have installed the 
> LWP bundle, did you possibly forget to add the path to the 'use lib' 
> statement?

Well, I'm no magician - really all I did was run that script from my 
browser :) I had forgot to add
system(@SysCmd);

but it seems to have executed anyway.

> 
>     use lib (
>         '/home/usr241/cgi-bin/PerlMods/WWW-Mechanize-1.18/lib',
>         '/home/usr241/cgi-bin/PerlMods/libwww-perl-5.808/lib',
>     );
> 

Anyway, you've answered my question - I did forget to 'use' the new 
installation. Thanks ! Now all I'm getting for an error is
"No form defined at test_mech.1.pl line 29"

which I figure out from here.

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
"Others make web sites. We make web sites work!"


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

Date: Tue, 04 Sep 2007 15:38:23 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: How to generate http error in script
Message-Id: <m2ejhe9q6o.fsf@dot-app.org>

"Petr Vileta" <stoupa@practisoft.cz> writes:

> By my mind
> logically flow from it that user try _login_ but with _wrong_
> username, so the HTTP error should be the same as human readable
> message "Bad login" = Status: 401.
> But this is the question to controversy :-)

401, by definition, refers to standard HTTP authorization. Since you're
not using standard HTTP authorization, it's an incorrect response. It's
not controversial, *every* reply you've received has told you the same.

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Tue, 04 Sep 2007 15:36:18 -0400
From: "Nicholas R. Markham" <markhn@rpi.edu>
Subject: implementation of system()
Message-Id: <46ddb3bb$0$18964$4c368faf@roadrunner.com>

While working on a souped-up replacement for system(), I realized that 
it's significantly more magical than I originally thought. 
Specifically, I can't explain how it's able to set $! and return -1 when 
exec() fails, since the exec() happens after a fork(), in the child process.

The examples I can find of the fork-and-exec paradigm (IPC::Open3, for 
example) invariably seem to just croak or die when exec fails, leaving 
the parent with no surefire way to distinguish between a failed exec() 
and a successful exec() followed by a failure in the new program.  Can 
anyone shed some light on how system() works its magic?


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

Date: Tue, 04 Sep 2007 13:36:58 -0700
From:  Klaus <klaus03@gmail.com>
Subject: Re: implementation of system()
Message-Id: <1188938218.673308.157320@y42g2000hsy.googlegroups.com>

On Sep 4, 9:36 pm, "Nicholas R. Markham" <mar...@rpi.edu> wrote:
> While working on a souped-up replacement for system(), I realized that
> it's significantly more magical than I originally thought.
> Specifically, I can't explain how it's able to set $! and return -1 when
> exec() fails, since the exec() happens after a fork(), in the child process.
>
> The examples I can find of the fork-and-exec paradigm (IPC::Open3, for
> example) invariably seem to just croak or die when exec fails, leaving
> the parent with no surefire way to distinguish between a failed exec()
> and a successful exec() followed by a failure in the new program.  Can
> anyone shed some light on how system() works its magic?

the answer lies probably in perldoc -f system:
===================================
[...]
Return value of -1 indicates a failure to start the program or an
error of the wait(2) system call (inspect $! for the reason).
[...]
You can check all the failure possibilities by inspecting $?
like this:
    if ($? == -1) {
        print "failed to execute: $!\n";
    }
    elsif ($? & 127) {
        printf "child died with signal %d, %s coredump\n",
            ($? & 127),  ($? & 128) ? 'with' : 'without';
    }
    else {
        printf "child exited with value %d\n", $? >> 8;
    }
or more portably by using the W*() calls of the POSIX extension;
see perlport for more information.
===================================

--
Klaus



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

Date: Tue, 4 Sep 2007 20:39:02 +0000 (UTC)
From: pacman@TheWorld.com (Alan Curry)
Subject: Re: implementation of system()
Message-Id: <fbkfp6$1le$1@pcls6.std.com>

In article <46ddb3bb$0$18964$4c368faf@roadrunner.com>,
Nicholas R. Markham <markhn@rpi.edu> wrote:
>While working on a souped-up replacement for system(), I realized that 
>it's significantly more magical than I originally thought. 
>Specifically, I can't explain how it's able to set $! and return -1 when 
>exec() fails, since the exec() happens after a fork(), in the child process.

It creates a pipe before forking and the child writes errno to the pipe after
exec failure. This makes it more magical and friendly than C's system(). It
has been this way since perl 5.6

-- 
Alan Curry
pacman@world.std.com


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

Date: Tue, 4 Sep 2007 21:04:57 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: implementation of system()
Message-Id: <fbkh9p$19lb$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Alan Curry
<pacman@TheWorld.com>], who wrote in article <fbkfp6$1le$1@pcls6.std.com>:
> In article <46ddb3bb$0$18964$4c368faf@roadrunner.com>,
> Nicholas R. Markham <markhn@rpi.edu> wrote:
> >While working on a souped-up replacement for system(), I realized that 
> >it's significantly more magical than I originally thought. 
> >Specifically, I can't explain how it's able to set $! and return -1 when 
> >exec() fails, since the exec() happens after a fork(), in the child process.
> 
> It creates a pipe before forking and the child writes errno to the pipe after
> exec failure. This makes it more magical and friendly than C's system().

No.  Only on legacy OSes it is more friendly than C's one.  On
contemporary OSes system() already behaves this way (since they are
not based on the botched fork()/exec() paradigm).

*This* was the motivation to implement this feature...

Hope this helps,
Ilya


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

Date: Tue, 4 Sep 2007 22:35:23 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: implementation of system()
Message-Id: <rlv0r4-b33.ln1@osiris.mauzo.dyndns.org>


Quoth "Nicholas R. Markham" <markhn@rpi.edu>:
> While working on a souped-up replacement for system(), I realized that 
> it's significantly more magical than I originally thought. 
> Specifically, I can't explain how it's able to set $! and return -1 when 
> exec() fails, since the exec() happens after a fork(), in the child process.
> 
> The examples I can find of the fork-and-exec paradigm (IPC::Open3, for 
> example) invariably seem to just croak or die when exec fails, leaving 
> the parent with no surefire way to distinguish between a failed exec() 
> and a successful exec() followed by a failure in the new program.  Can 
> anyone shed some light on how system() works its magic?

Err, yes, pp_system in pp_sys.c in the perl distribution can, though
it's a little hard to follow. Basically, system creates a pipe before
forking, the child makes sure it's set to close-on-exec (so if the exec
succeeds it doesn't affect the new program in any way), and if the exec
fails the child writes errno to the pipe before _exitting. So the parent
either gets a closed pipe (exec succeeded) or an errno value followed by
a closed pipe (exec failed).

Ben



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

Date: Tue, 4 Sep 2007 21:50:36 +0000 (UTC)
From: pacman@TheWorld.com (Alan Curry)
Subject: Re: implementation of system()
Message-Id: <fbkjvc$qdn$1@pcls4.std.com>

In article <fbkh9p$19lb$1@agate.berkeley.edu>, some PoB barfed up:
>Alan Curry
>> It creates a pipe before forking and the child writes errno to the pipe after
>> exec failure. This makes it more magical and friendly than C's system().
>
>No.  Only on legacy OSes it is more friendly than C's one.  On
>contemporary OSes system() already behaves this way (since they are
>not based on the botched fork()/exec() paradigm).
>
>*This* was the motivation to implement this feature...

Yeah, we were jealous of Windoze. You've got it exactly. Nobody in the unix
world ever does anything original, like invent perl for instance. No need to
pay any more attention to us.

-- 
Alan Curry
pacman@world.std.com


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

Date: Wed, 5 Sep 2007 00:43:54 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: implementation of system()
Message-Id: <fbku4a$1dq7$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Alan Curry
<pacman@TheWorld.com>], who wrote in article <fbkfp6$1le$1@pcls6.std.com>:
> >it's significantly more magical than I originally thought. 
> >Specifically, I can't explain how it's able to set $! and return -1 when 
> >exec() fails, since the exec() happens after a fork(), in the child process.
> 
> It creates a pipe before forking and the child writes errno to the pipe after
> exec failure. This makes it more magical and friendly than C's system(). It
> has been this way since perl 5.6

The major trick is to CLOEXEC the kid side of the pipe.  So if exec()
succeeds, the parent knows immediately.

Hope this helps,
Ilya



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

Date: Tue, 4 Sep 2007 22:17:52 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Monitoring a list?
Message-Id: <0lu0r4-b33.ln1@osiris.mauzo.dyndns.org>


Quoth jis <jismagic@gmail.com>:

<snip yards of quote. please trim quotations>

> Please find the code. The code is modified so that it has only
> important sections.
> Tha application has got a list which keeps updating. My original
> question how to find out which one is  changing.
> Hope this time I m on target.
> 
> use Tk;

AFAICS, Tk is irrelevant to your problem, so your postd example should
not have included it. You are expected to keep removing things from your
program until you can't reproduce your problem.

> use strict;

Where is
    use warnings;
?

> use Win32::GuiTest qw(:ALL);
> 
> # Create a new window
> my $mw = MainWindow->new;
> #create a canvas object on the window
> my $canvas = $mw->Canvas(-background,"white",-width,1024,-height,768);
> $canvas->pack(-expand => 1, -fill => 'both');
> $mw->repeat(5000,[\&updateScreen]);
> MainLoop;
> 
> 
> sub updateScreen()
                  ^^
Do you know what these parens do? I don't think you do. Don't put them
in.

> {
>         $nofModels=ReadScheduler();
> 
>     $canvas->delete('all');
> 
>      //code for display

This is not a Perl comment. Did you actually run this code before
posting it?

> }
> 
> sub  ReadScheduler
> {
>     open(DATA,">$SchedFile") or die "dead duck";

Don't use the DATA filehandle, Perl uses it for its own purposes. In
fact, don't use global bareword filehandles at all.

Use three-arg open, it's safer.

Include some helpful information in the error message.

    open( my $DATA, '>', $SchedFile )
        or die "can't write to '$SchedFile': $!";

>     my @whnds = FindWindowLike( undef, "xxxxxx" );
>     if( !@whnds )
>     {
>         die "Cannot find window with title/caption xxx\n";
>     }

This can be simplified to

    my @whnds = FindWindowLike( undef, "xxxxxx" )
        or die "...";

in exactly the same way as the 'open or die' above.

>     my   $mywndw= $whnds[ 0 ];
>     my ($listbox) = FindWindowLike($mywndw, "", "ListBox");
>     for (GetListContents($listbox))
>     {
>         print DATA $_ . "\n"   ;
>     }
>     close($SchedFile);
> 
>     $temp=0;

Global symbol "$temp" requires explicit package name at...

Did you actually run this code before you posted it?

>     open(DATA,$SchedFile) or die "dead duck";

Now, why on *EARTH* are you writing your data out to a file and then
reading it all back in again? I can see the point if you are expecting
more data than you can fit in memory, but that doesn't seem likely in
this case: indeed, the for loop above has already had the whole lot in
memory. Just put whatever you want to do inside the for loop.

>     while(<DATA>)
>     {
>         print $_;
>         if($_=~/(\d+)\s+(\d+)\s+(\d+)/)
>         {
>             $sched_1  [$temp]=$1;

Where are these $schen_n variables defined?

Variables named in a sequence are always a sign you should be using a
data structure; in this case, an array:

    $sched[1][$temp] = $1;

or you could probably use push and eliminate $temp altogether. I can't
tell without knowing what else you do with the contents of $sched_n, in
particular what it is initialized to before we get here.

>             $sched_2[$temp]=$2;
>             $sched_3[$temp]=$3;
>             $temp++;
>         }
>     }
>     close($SchedFile);
> 
>     return $temp;

I'm going to take a wild leap here, and guess that $sched_n are globals
used by '//code for display' above. It owuld be much better style to
return several values from ReadScheduler, so you would have

    my $sched;

at the top of the sub, 

    return ($temp, $sched);

at the end (or simply 

    return $sched;

if, as I suspect, you can find out how many items there are by, err,
counting them), and call it as

    my ($count, $sched) = ReadScheduler();

in updateScreen above.

Ben



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

Date: Tue, 04 Sep 2007 22:53:08 -0000
From:  jis <jismagic@gmail.com>
Subject: Re: Monitoring a list?
Message-Id: <1188946388.020071.240160@k79g2000hse.googlegroups.com>

On Sep 4, 4:17 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth jis <jisma...@gmail.com>:
>
> <snip yards of quote. please trim quotations>
>
> > Please find the code. The code is modified so that it has only
> > important sections.
> > Tha application has got a list which keeps updating. My original
> > question how to find out which one is  changing.
> > Hope this time I m on target.
>
> > use Tk;
>
> AFAICS, Tk is irrelevant to your problem, so your postd example should
> not have included it. You are expected to keep removing things from your
> program until you can't reproduce your problem.
>
> > use strict;
>
> Where is
>     use warnings;
> ?
>
> > use Win32::GuiTest qw(:ALL);
>
> > # Create a new window
> > my $mw = MainWindow->new;
> > #create a canvas object on the window
> > my $canvas = $mw->Canvas(-background,"white",-width,1024,-height,768);
> > $canvas->pack(-expand => 1, -fill => 'both');
> > $mw->repeat(5000,[\&updateScreen]);
> > MainLoop;
>
> > sub updateScreen()
>
>                   ^^
> Do you know what these parens do? I don't think you do. Don't put them
> in.
>
> > {
> >         $nofModels=ReadScheduler();
>
> >     $canvas->delete('all');
>
> >      //code for display
>
> This is not a Perl comment. Did you actually run this code before
> posting it?
>
> > }
>
> > sub  ReadScheduler
> > {
> >     open(DATA,">$SchedFile") or die "dead duck";
>
> Don't use the DATA filehandle, Perl uses it for its own purposes. In
> fact, don't use global bareword filehandles at all.
>
> Use three-arg open, it's safer.
>
> Include some helpful information in the error message.
>
>     open( my $DATA, '>', $SchedFile )
>         or die "can't write to '$SchedFile': $!";
>
> >     my @whnds = FindWindowLike( undef, "xxxxxx" );
> >     if( !@whnds )
> >     {
> >         die "Cannot find window with title/caption xxx\n";
> >     }
>
> This can be simplified to
>
>     my @whnds = FindWindowLike( undef, "xxxxxx" )
>         or die "...";
>
> in exactly the same way as the 'open or die' above.
>
> >     my   $mywndw= $whnds[ 0 ];
> >     my ($listbox) = FindWindowLike($mywndw, "", "ListBox");
> >     for (GetListContents($listbox))
> >     {
> >         print DATA $_ . "\n"   ;
> >     }
> >     close($SchedFile);
>
> >     $temp=0;
>
> Global symbol "$temp" requires explicit package name at...
>
> Did you actually run this code before you posted it?
>
> >     open(DATA,$SchedFile) or die "dead duck";
>
> Now, why on *EARTH* are you writing your data out to a file and then
> reading it all back in again? I can see the point if you are expecting
> more data than you can fit in memory, but that doesn't seem likely in
> this case: indeed, the for loop above has already had the whole lot in
> memory. Just put whatever you want to do inside the for loop.
>
> >     while(<DATA>)
> >     {
> >         print $_;
> >         if($_=~/(\d+)\s+(\d+)\s+(\d+)/)
> >         {
> >             $sched_1  [$temp]=$1;
>
> Where are these $schen_n variables defined?
>
> Variables named in a sequence are always a sign you should be using a
> data structure; in this case, an array:
>
>     $sched[1][$temp] = $1;
>
> or you could probably use push and eliminate $temp altogether. I can't
> tell without knowing what else you do with the contents of $sched_n, in
> particular what it is initialized to before we get here.
>
> >             $sched_2[$temp]=$2;
> >             $sched_3[$temp]=$3;
> >             $temp++;
> >         }
> >     }
> >     close($SchedFile);
>
> >     return $temp;
>
> I'm going to take a wild leap here, and guess that $sched_n are globals
> used by '//code for display' above. It owuld be much better style to
> return several values from ReadScheduler, so you would have
>
>     my $sched;
>
> at the top of the sub,
>
>     return ($temp, $sched);
>
> at the end (or simply
>
>     return $sched;
>
> if, as I suspect, you can find out how many items there are by, err,
> counting them), and call it as
>
>     my ($count, $sched) = ReadScheduler();
>
> in updateScreen above.
>
> Ben

That was really cool!!
Thanks for that....
here is

But i have got data very similiar to

A         10
B         20
A         5
C         20

sitting on a listbox in an application. The listbox data gets
decremented with time.Only one variable updates at a time. WHen it
reaches zero it disappears. A new one gets added up at some point of
time.

I  read the application listbox every 5 sec (as u see in my
program)and manipulates the data for a different purpose. But i want
to know which variable is decrementing( A or B or C).

What could be the easiest way to find which one is on action?

cheers.
jis




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

Date: Tue, 04 Sep 2007 21:55:19 -0000
From:  Rohit <rohit.makasana@gmail.com>
Subject: Perl variable to shell command...?
Message-Id: <1188942919.775130.169870@y42g2000hsy.googlegroups.com>

Hi, I am trying to use perl local variable with shell command call.

Example:

$filename=myFile.txt

@fileRec=`cat $filename`;

Here shell is not able to identify $filename variable. Any idea or
suggestions?
I am using array of filename so it is necessary for me to use cat with
variable.

Thanks in advance.

~Rohit



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

Date: Tue, 04 Sep 2007 22:25:38 -0000
From:  usenet@DavidFilmer.com
Subject: Re: Perl variable to shell command...?
Message-Id: <1188944738.261037.322660@w3g2000hsg.googlegroups.com>

On Sep 4, 2:55 pm, Rohit <rohit.makas...@gmail.com> wrote:
> Hi, I am trying to use perl local variable with shell command call.
> Example:
> $filename=myFile.txt

You should quote your string literals.  And scope your variable (and
'use strict;' at the top of your program).  And to make it really
bullet-proof, fully qualify the filename:

   my $filename = '/path/to/my/file.txt';

> @fileRec=`cat $filename`;
> Here shell is not able to identify $filename variable. Any idea or
> suggestions?

Your program is started from a directory other than the one your file
resides in.  You can do one of the following:
   - fully qualify the filenames
   - cd to the appropriate directory before running your program
   - chdir() to the appropriate directory within your program

FWIW, @fileRec=`cat $filename`; is of dubious quality.  If your file
is large your program will crash.  It would be safer to open the file
(in Perl) and process it one line at a time in a while{} loop.  And
you have better control over your exception handling for error
conditions.

At the very least you should fully qualify your cat command (ie, '/usr/
bin/cat' or whatever).  It is a potential security risk to call
unqualified system commands.


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)



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

Date: Tue, 04 Sep 2007 23:10:52 -0000
From:  Rohit <rohit.makasana@gmail.com>
Subject: Re: Perl variable to shell command...?
Message-Id: <1188947452.878279.56340@r29g2000hsg.googlegroups.com>

On Sep 4, 3:25 pm, use...@DavidFilmer.com wrote:
> On Sep 4, 2:55 pm, Rohit <rohit.makas...@gmail.com> wrote:
>
> > Hi, I am trying to use perl local variable with shell command call.
> > Example:
> > $filename=myFile.txt
>
> You should quote your string literals.  And scope your variable (and
> 'use strict;' at the top of your program).  And to make it really
> bullet-proof, fully qualify the filename:
>
>    my $filename = '/path/to/my/file.txt';
>
> > @fileRec=`cat $filename`;
> > Here shell is not able to identify $filename variable. Any idea or
> > suggestions?
>
> Your program is started from a directory other than the one your file
> resides in.  You can do one of the following:
>    - fully qualify the filenames
>    - cd to the appropriate directory before running your program
>    - chdir() to the appropriate directory within your program
>
> FWIW, @fileRec=`cat $filename`; is of dubious quality.  If your file
> is large your program will crash.  It would be safer to open the file
> (in Perl) and process it one line at a time in a while{} loop.  And
> you have better control over your exception handling for error
> conditions.
Yupe, you are right. My file size is 210KB, and it is failing while I
am piping its output for further processing.

 $symbolFile = "$symbolFile[$fileCount]";
 ...
 ...
        $var123="$symbolFile";
@dataVar = `/bin/cat $var123 | grep -i ^func`

If I remove piping here, it works great. Let me see now perl parsing.

>
> At the very least you should fully qualify your cat command (ie, '/usr/
> bin/cat' or whatever).  It is a potential security risk to call
> unqualified system commands.
>
> --
> The best way to get a good answer is to ask a good question.
> David Filmer (http://DavidFilmer.com)

Thanks for your comments.

~Rohit



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

Date: Tue, 04 Sep 2007 23:43:42 GMT
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Perl variable to shell command...?
Message-Id: <slrnfdrr7h.euq.tadmc@tadmc30.sbcglobal.net>

usenet@DavidFilmer.com <usenet@DavidFilmer.com> wrote:
> On Sep 4, 2:55 pm, Rohit <rohit.makas...@gmail.com> wrote:
>> Hi, I am trying to use perl local variable with shell command call.
>> Example:
>> $filename=myFile.txt
>
> You should quote your string literals.  And scope your variable (and
> 'use strict;' at the top of your program).


And use semicolons between statements.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Tue, 04 Sep 2007 19:13:29 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Perl variable to shell command...?
Message-Id: <46ddf4aa$0$509$815e3792@news.qwest.net>

Rohit wrote:
>> On Sep 4, 3:25 pm, use...@DavidFilmer.com wrote:
>>> On Sep 4, 2:55 pm, Rohit <rohit.makas...@gmail.com> wrote:
[...]
>> FWIW, @fileRec=`cat $filename`; is of dubious quality.  If your file
>> is large your program will crash.  It would be safer to open the file
>> (in Perl) and process it one line at a time in a while{} loop.  And
>> you have better control over your exception handling for error
>> conditions.
> Yupe, you are right. My file size is 210KB, and it is failing while I
> am piping its output for further processing.
> 
>  $symbolFile = "$symbolFile[$fileCount]";
> ...
> ...
>         $var123="$symbolFile";
> @dataVar = `/bin/cat $var123 | grep -i ^func`
> 
> If I remove piping here, it works great. Let me see now perl parsing.

If you remove the pipe, it doesn't "work" at all.

Why are you using cat at all?  The grep command takes filenames
as arguments.

man grep

If you want to use perl to read through the file:

perldoc perlintro

Look for "Files and I/O"


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

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 V11 Issue 820
**************************************


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