[29575] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 819 Volume: 11

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

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

Today's topics:
        <tns:Header> error at read line <gil.kovary@gmail.com>
    Re: <tns:Header> error at read line  usenet@DavidFilmer.com
    Re: FAQ 1.13 Is it a Perl program or a Perl script? <bik.mido@tiscalinet.it>
    Re: FAQ 1.13 Is it a Perl program or a Perl script?  usenet@DavidFilmer.com
    Re: How to generate http error in script <hjp-usenet2@hjp.at>
    Re: How to generate http error in script <stoupa@practisoft.cz>
    Re: How to generate http error in script <1usa@llenroc.ude.invalid>
        Monitoring a list? <jismagic@gmail.com>
    Re: Monitoring a list? <jurgenex@hotmail.com>
    Re: Monitoring a list? <ben@morrow.me.uk>
    Re: Monitoring a list? <jismagic@gmail.com>
        Warning about unused lexical variables <hjp-usenet2@hjp.at>
    Re: Warning about unused lexical variables <bik.mido@tiscalinet.it>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 04 Sep 2007 14:37:09 -0000
From:  gil <gil.kovary@gmail.com>
Subject: <tns:Header> error at read line
Message-Id: <1188916629.567972.322370@k79g2000hse.googlegroups.com>

I'am working on solaris 10, reding from a log file and get this
strange looking error: <tns:Header>
when trying to print some of the lines.

the code:
                                while ($line = <DATA>) {
                                                if ($i !~ /log$/) {  #
$i is the file name
                                                if  ($time_flag == 0 )
{
                                                        $dif = "_";
                                                        if  (($line
=~ /^\[\d\d/)  && ($line!~ /^<\?xml/)) {$dif = (get_dif($line));}
                                                        if ((defined
($dif) ) && ($dif  <= (60 * $min_num ))) {
 
$time_flag = 1;
                                                                if
($type eq "TYPE1") {print $i . "  " . $line . "\n";} # -here-
                                                                }
                                                        }
                                                }



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

Date: Tue, 04 Sep 2007 17:22:40 -0000
From:  usenet@DavidFilmer.com
Subject: Re: <tns:Header> error at read line
Message-Id: <1188926560.466042.119860@57g2000hsv.googlegroups.com>

On Sep 4, 7:37 am, gil <gil.kov...@gmail.com> wrote:
> I'am working on solaris 10, reding from a log file and get this
> strange looking error: <tns:Header>

That's not a Perl message.  I think it's one of the values in your
<DATA> block.

> the code:

This isn't code, it's a bizarre code fragment (you have not closed
your while loop or your first if block). The logic of it escapes me in
many regards.

>   while ($line = <DATA>) {
>      if ($i !~ /log$/) {      # $i is the file name

Why are you looping over <DATA> and checking $i each time?  $i is not
set within your while block, so it is either always true or always
false here.

>         if  ($time_flag == 0 ) {

For the first iteration of your while block this will always evaluate
as true.  Is this what you intended?

>            $dif = "_";
>            if  (($line =~ /^\[\d\d/)  && ($line!~ /^<\?xml/)) {

So you are checking this condition:  If the line begins with bracket
and two digits, and the line does NOT begin with an xml pragma...
huh?  If it begins with bracket-digit-digit it cannot possibly begin
with an xml pragma.  What's with the second condition?

>               $dif = (get_dif($line));
>            }
>            if ((defined ($dif) ) && ($dif  <= (60 * $min_num ))) {

Can get_dif return undef? (if not then it's silly to check for defined-
ness.)  $dif is given a value ('_') before the conditional.  If the
condition is not true (ie, if $line does not match the regexp) then
get_dif is never called, so when you get to this conditional then $dif
eq '_' which will always evaluate as <= any non-negative numeric value
(including zero).  I doubt this is your intent.

>               $time_flag = 1;
>               if ($type eq "TYPE1") {
>                  print $i . "  " . $line . "\n";} # -here-

Why all the concats?  Just print "$i  $line\n";

Are you sure the output you are seeing is actually coming from this
print statement and not some other?

>               }
>            }
>         }

Where are the final two closing curlys?

I strongly recommend that you use strict and properly scope your
variables.  Doing so will probably reveal your problem.



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




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

Date: Tue, 04 Sep 2007 19:17:21 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: FAQ 1.13 Is it a Perl program or a Perl script?
Message-Id: <ol4rd31kdre6e4i5v443upp9uvpq7upc74@4ax.com>

On Mon, 3 Sep 2007 12:03:02 -0700, PerlFAQ Server
<brian@stonehenge.com> wrote:

>1.13: Is it a Perl program or a Perl script?
>
>    Larry doesn't really care. He says (half in jest) that "a script is what
>    you give the actors. A program is what you give the audience."

Also see the next to last (hope this is the correct English way to say
that) entry at <http://perlmonks.org/?node_id=635444>. (In fact, I
suggested it.)


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Tue, 04 Sep 2007 17:32:13 -0000
From:  usenet@DavidFilmer.com
Subject: Re: FAQ 1.13 Is it a Perl program or a Perl script?
Message-Id: <1188927133.049406.212130@r29g2000hsg.googlegroups.com>

On Sep 4, 10:17 am, Michele Dondi <bik.m...@tiscalinet.it> wrote:
> Also see the next to last (hope this is the correct English way to say
> that)

You could say 'penultimate.'  But 'next to last' works fine.

FWIW, 'antepenultimate' means third from last (really).

--
David Filmer (http://DavidFilmer.com)



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

Date: Tue, 4 Sep 2007 12:09:52 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: How to generate http error in script
Message-Id: <slrnfdqbng.frn.hjp-usenet2@zeno.hjp.at>

On 2007-09-04 02:13, Petr Vileta <stoupa@practisoft.cz> wrote:
> Peter J. Holzer wrote:
>> On 2007-09-03 03:48, Petr Vileta <stoupa@practisoft.cz> wrote:
>>> Sherm Pendley wrote:
>>>> "Petr Vileta" <stoupa@practisoft.cz> writes:
>>> Because I do not use Apache authentication but by parameters on GET
>>> method only. If all parameters are passed right then script return
>>> XML file, in other case must return http 401 error.
>>
>> In this case 401 is probably wrong. 401 is intended to be used with
>> the WWW-Authenticate and Authorization headers:
>>
> Yes, right. But what other http error you suggest? I not want to
> return Status: 200 and human readable error message. I aspire to deter
> robots from trying to download ;-)

Others have already suggested 403. I am adding 404 as a possible
alternative. 

Rationale: You are passing username and password as part of the url. So 

/foo/bar?user=petr;pass=secret 

is acceptable, and

/foo/bar?user=hjp;pass=geheim 

is not, because no user "hjp" with password "geheim" was found in your
user database. This is conceptually not much different from 

/foo/doc/?id=1234

not being acceptable because you don't a document with id 1234 wasn't
found in your document store, or

/foo/bar/baz.html

not being acceptable because a file foo/bar/baz.html wasn't found below
your document root. In all these cases a lookup for the entity requested
for the browser failed.

	hp

-- 
   _  | Peter J. Holzer    | I know I'd be respectful of a pirate 
|_|_) | Sysadmin WSR       | with an emu on his shoulder.
| |   | hjp@hjp.at         |
__/   | http://www.hjp.at/ |	-- Sam in "Freefall"


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

Date: Tue, 4 Sep 2007 15:25:51 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: How to generate http error in script
Message-Id: <fbjmp7$8ma$1@ns.felk.cvut.cz>

Sherm Pendley wrote:
> "Petr Vileta" <stoupa@practisoft.cz> writes:
>
>> Peter J. Holzer wrote:
>>> On 2007-09-03 03:48, Petr Vileta <stoupa@practisoft.cz> wrote:
>>>> Because I do not use Apache authentication but by parameters on GET
>>>> method only. If all parameters are passed right then script return
>>>> XML file, in other case must return http 401 error.
>>>
>>> In this case 401 is probably wrong. 401 is intended to be used with
>>> the WWW-Authenticate and Authorization headers:
>
>> Yes, right. But what other http error you suggest?
>
> I think "403 Forbidden" would be appropriate. The W3C's description
> of it says "authorization will not help", but that simply means that
> the browser shouldn't bother prompting for standard HTTP auth info,
> like it would for a 401 response.
>
I'm used to see this error when I can go to directory (mean URL) where 
nobody can to go. Maybe by some RFC this is right response but by human 
logic not :-) My script is in directory where users can to go but must pass 
a right parameters or call other scripts. For example
http://www.domain.com/test/ is allowed and return some html code and status 
200
http://www.domain.com/test/mytest.cgi is the same, but return xml code
http://www.domain.com/test/othertest.cgi?user=John&pwd=mypwd is good script 
calling with right parameters and return status 200 and html code
http://www.domain.com/test/othertest.cgi?user=Joe&pwd=mypwd is good script 
calling but with wrong user passed and must return human readable error 
message and some appropriate HTTP error. 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 :-)
-- 

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail 
from another non-spammer site please.)


>> I not want to
>> return Status: 200 and human readable error message. I aspire to
>> deter robots from trying to download ;-)
>
> Note that your script can include content with a 403 response itself,
> or you can use Apache's ErrorDocument config directive to specify a
> document to return with 403 responses.
>
> sherm--

-- 
Petr

Skype: callto://fidokomik

Na mail uvedeny v headeru zpravy nema cenu nic posilat, konci to v PR*
:-) Odpovidejte na petr na practisoft cz



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

Date: Tue, 04 Sep 2007 18:02:25 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How to generate http error in script
Message-Id: <Xns99A18EC816A12asu1cornelledu@127.0.0.1>

"Petr Vileta" <stoupa@practisoft.cz> wrote in
news:fbjmp7$8ma$1@ns.felk.cvut.cz: 

> Sherm Pendley wrote:
>> "Petr Vileta" <stoupa@practisoft.cz> writes:
>>
>>> Peter J. Holzer wrote:
>>>> On 2007-09-03 03:48, Petr Vileta <stoupa@practisoft.cz> wrote:
>>>>> Because I do not use Apache authentication but by parameters on
>>>>> GET method only. If all parameters are passed right then script
>>>>> return XML file, in other case must return http 401 error.
>>>>
>>>> In this case 401 is probably wrong. 401 is intended to be used with
>>>> the WWW-Authenticate and Authorization headers:
>>
>>> Yes, right. But what other http error you suggest?
>>
>> I think "403 Forbidden" would be appropriate. The W3C's description
>> of it says "authorization will not help", but that simply means that
>> the browser shouldn't bother prompting for standard HTTP auth info,
>> like it would for a 401 response.
>>
> I'm used to see this error when I can go to directory (mean URL) where
> nobody can to go. Maybe by some RFC this is right response but by
> human logic not :-) 

By human logic, you discussing HTTP return codes here is also wrong. A 
few of us nicely suggested an alternative. You can us it or not but 
trying to discuss whether your desire to use HTTP status codes when you 
are not using HTTP authorization is sensible, the pros and the cons, 
those are all off-topic.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>



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

Date: Tue, 04 Sep 2007 14:21:11 -0000
From:  jis <jismagic@gmail.com>
Subject: Monitoring a list?
Message-Id: <1188915671.966331.274400@o80g2000hse.googlegroups.com>

 i have a list which update with time.

 A        -    10
 B        -    20
 A       -     10
C       -      300

i want to find which one is changing current. For eg if  B is running.
It decrements till it reaches 0. I want to catch B is running. All
variables go back to zero  and then disappears fromt he list.

I have very lengthy solutions. Can anybody suggest a clever solution
for this

Now I check the list every 5 seconds.

Cheers,
jis



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

Date: Tue, 04 Sep 2007 14:47:44 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Monitoring a list?
Message-Id: <keeDi.4181$es2.3488@trndny09>

jis wrote:
> i have a list which update with time.
>
> A        -    10
> B        -    20
> A       -     10
> C       -      300
>
> i want to find which one is changing current. For eg if  B is running.
> It decrements till it reaches 0. I want to catch B is running. All
> variables go back to zero  and then disappears fromt he list.

In Perl a list is a value. It has a fixed length and its members do not 
change, e.g.     ('foo', 'bar', 1, 2, 3, 'fuzz', $var)
is a list with 7 elements where the last element is the _current_ value of 
$var at the time of evaluation.

Obviously you must be talking about something different, but what?

jue 




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

Date: Tue, 4 Sep 2007 15:59:04 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Monitoring a list?
Message-Id: <oe80r4-5n1.ln1@osiris.mauzo.dyndns.org>


Quoth jis <jismagic@gmail.com>:
>  i have a list which update with time.
> 
>  A        -    10
>  B        -    20
>  A       -     10
> C       -      300
> 
> i want to find which one is changing current. For eg if  B is running.
> It decrements till it reaches 0. I want to catch B is running. All
> variables go back to zero  and then disappears fromt he list.
> 
> I have very lengthy solutions. Can anybody suggest a clever solution
> for this

Since you have provided no code, nor any indication of how you get hold
of this list, I can't provide much help. Have you seen the Posting
Guidelines?

However, in simple terms you need to get the list into some data
structure, say

    my $list = [
        ['A', 10],
        ['B', 20],
        ['A', 10],
        ['C', 300],
    ];

(if you don't understand this, read perldoc perllol and perldoc perldsc)
and then use something similar to (completely untested)

    my $list = check_the_list();
    my $lastlist;

    while (1) {
        $lastlist = $list;
        $list = check_the_list() or last;

        my @gone;
        for (0..$#{$list}) {
            # if this entry is still there, move onto the next
            $list->[$_][0] eq $lastlist->[$_][0] and next;

            # remove this entry from $lastlist and try again
            push @gone, $lastlist->[$_][0];
            splice @$lastlist, $_, 1;
            redo;
        }

        my @changed =
            # we want the names...
            map  { $list->[$_][0] }
            # ...of the entries that have changed
            grep { $list->[$_][1] != $lastlist->[$_][1] }
            0..$#{$list};
        
        # do something with @changed and @gone

        sleep 5;
    }

I used arrays above as your keys above don't seem to be unique... if
they *are* unique, or if you can make them so, using a hash would be
better, as the above is rather ugly (using array indices is always
ugly), and make several important assumptions:

    The order of entries in the list will never change.

    The list never acquires any new entries.

    An entry will never replace another with the same name; that is, the
    list will never go from

        B   1
        A   2
        A   3
        C   4

    to

        B   1
        A   2
        C   4

    as you now cannot tell which 'A' it is has vanished.

> Now I check the list every 5 seconds.

And what difference does that make to anything?

Ben



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

Date: Tue, 04 Sep 2007 15:34:34 -0000
From:  jis <jismagic@gmail.com>
Subject: Re: Monitoring a list?
Message-Id: <1188920074.901534.168710@r29g2000hsg.googlegroups.com>

On Sep 4, 9:59 am, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth jis <jisma...@gmail.com>:
>
> >  i have a list which update with time.
>
> >  A        -    10
> >  B        -    20
> >  A       -     10
> > C       -      300
>
> > i want to find which one is changing current. For eg if  B is running.
> > It decrements till it reaches 0. I want to catch B is running. All
> > variables go back to zero  and then disappears fromt he list.
>
> > I have very lengthy solutions. Can anybody suggest a clever solution
> > for this
>
> Since you have provided no code, nor any indication of how you get hold
> of this list, I can't provide much help. Have you seen the Posting
> Guidelines?
>
> However, in simple terms you need to get the list into some data
> structure, say
>
>     my $list = [
>         ['A', 10],
>         ['B', 20],
>         ['A', 10],
>         ['C', 300],
>     ];
>
> (if you don't understand this, read perldoc perllol and perldoc perldsc)
> and then use something similar to (completely untested)
>
>     my $list = check_the_list();
>     my $lastlist;
>
>     while (1) {
>         $lastlist = $list;
>         $list = check_the_list() or last;
>
>         my @gone;
>         for (0..$#{$list}) {
>             # if this entry is still there, move onto the next
>             $list->[$_][0] eq $lastlist->[$_][0] and next;
>
>             # remove this entry from $lastlist and try again
>             push @gone, $lastlist->[$_][0];
>             splice @$lastlist, $_, 1;
>             redo;
>         }
>
>         my @changed =
>             # we want the names...
>             map  { $list->[$_][0] }
>             # ...of the entries that have changed
>             grep { $list->[$_][1] != $lastlist->[$_][1] }
>             0..$#{$list};
>
>         # do something with @changed and @gone
>
>         sleep 5;
>     }
>
> I used arrays above as your keys above don't seem to be unique... if
> they *are* unique, or if you can make them so, using a hash would be
> better, as the above is rather ugly (using array indices is always
> ugly), and make several important assumptions:
>
>     The order of entries in the list will never change.
>
>     The list never acquires any new entries.
>
>     An entry will never replace another with the same name; that is, the
>     list will never go from
>
>         B   1
>         A   2
>         A   3
>         C   4
>
>     to
>
>         B   1
>         A   2
>         C   4
>
>     as you now cannot tell which 'A' it is has vanished.
>
> > Now I check the list every 5 seconds.
>
> And what difference does that make to anything?
>
> Ben

I think the way I framed the question was terrible.Let me  put it in a
way others understand :)
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;
use strict;
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()
{
        $nofModels=ReadScheduler();

    $canvas->delete('all');

     //code for display
}

sub  ReadScheduler
{
    open(DATA,">$SchedFile") or die "dead duck";
    my @whnds = FindWindowLike( undef, "xxxxxx" );
    if( !@whnds )
    {
        die "Cannot find window with title/caption xxx\n";
    }
    my   $mywndw= $whnds[ 0 ];
    my ($listbox) = FindWindowLike($mywndw, "", "ListBox");
    for (GetListContents($listbox))
    {
        print DATA $_ . "\n"   ;
    }
    close($SchedFile);

    $temp=0;

    open(DATA,$SchedFile) or die "dead duck";
    while(<DATA>)
    {
        print $_;
        if($_=~/(\d+)\s+(\d+)\s+(\d+)/)
        {
            $sched_1  [$temp]=$1;
            $sched_2[$temp]=$2;
            $sched_3[$temp]=$3;
            $temp++;
        }
    }
    close($SchedFile);

    return $temp;
}





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

Date: Tue, 4 Sep 2007 12:25:30 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Warning about unused lexical variables
Message-Id: <slrnfdqckr.frn.hjp-usenet2@zeno.hjp.at>

Occasionally I notice a lexical variable sticking around which isn't
used any more and can/should be deleted, like in this (stupid) example:

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

my $x;
my $y;

$y = 42;
print "$y\n";
__END__

This can be made slightly more complex by changing "my $x" to

my $x = compute_some_value();

where $x is assigned a value which is subsequently never used.

It would be nice if perl could warn about lexical variables which are
never used in their scope after their initialization. Does anybody else
find this useful, and if so, is there a reason (besides "life is short")
why it hasn't been implemented?

	hp

-- 
   _  | Peter J. Holzer    | I know I'd be respectful of a pirate 
|_|_) | Sysadmin WSR       | with an emu on his shoulder.
| |   | hjp@hjp.at         |
__/   | http://www.hjp.at/ |	-- Sam in "Freefall"


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

Date: Tue, 04 Sep 2007 19:48:05 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Warning about unused lexical variables
Message-Id: <2e6rd3h5vahed4rd300j9vjljepsdthj72@4ax.com>

On Tue, 4 Sep 2007 12:25:30 +0200, "Peter J. Holzer"
<hjp-usenet2@hjp.at> wrote:

>It would be nice if perl could warn about lexical variables which are
>never used in their scope after their initialization. Does anybody else
>find this useful, and if so, is there a reason (besides "life is short")
>why it hasn't been implemented?

I don't have the slightest idea about how to answer your question, but
I duplicated at <http://perlmonks.org/?node_id=636990>. I'll update
this thread as replies get posted there.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

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


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