[30028] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1271 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 12 03:09:45 2008

Date: Tue, 12 Feb 2008 00:09:06 -0800 (PST)
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, 12 Feb 2008     Volume: 11 Number: 1271

Today's topics:
    Re: ???? <bik.mido@tiscalinet.it>
        A Gtk2 IRC Chat Client <deadpickle@gmail.com>
    Re: A Gtk2 IRC Chat Client <deadpickle@gmail.com>
    Re: Converting milliseconds to seconds (David Combs)
    Re: Converting milliseconds to seconds <ben@morrow.me.uk>
    Re: Converting milliseconds to seconds <jurgenex@hotmail.com>
        LWP user agent grabs the intermediate wait page after P <amitava@gmail.com>
    Re: LWP user agent grabs the intermediate wait page aft <thepoet_nospam@arcor.de>
        new CPAN modules on Tue Feb 12 2008 (Randal Schwartz)
    Re: Using END and the die function <pgodfrin@gmail.com>
    Re: Using END and the die function <pgodfrin@gmail.com>
    Re: Using END and the die function <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 11 Feb 2008 22:06:17 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: ????
Message-Id: <95e1r3hktdg3t1lifdm3dd712ccmo67him@4ax.com>

On Mon, 11 Feb 2008 17:09:22 GMT, Jürgen Exner <jurgenex@hotmail.com>
wrote:

>>???n????????spss???p???R?? : 1.???z???p 2.T???w 3.ANOVA 4.???????R 5.?]?????R
>> 6.???]?l?????????R
>[...]
>
>What did you say?

Jingo![*]


[*] Someone may actually understand what I mean...


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: Mon, 11 Feb 2008 12:13:44 -0800 (PST)
From: deadpickle <deadpickle@gmail.com>
Subject: A Gtk2 IRC Chat Client
Message-Id: <0d0db824-9ae3-4826-b4d9-dbf1e98df06f@y5g2000hsf.googlegroups.com>

I am trying to build a chat client that uses IRC and is built in the
framework of Gtk2. So far it works well but not great. Right now the
client connects to a server and joins a channel. Also, the client can
send messages to the channel and amazingly they are received on the
channel. The problem I am encountering is that the chat client is not
receiving all the raw lines sent by the IRC server (for an example of
what I mean try this script: http://www.oreilly.com/pub/h/1964). If it
is not receiving all the lines then it can only send messages not
receive them. So I am looking for help on how I can get the program to
receive messages so that they can be displayed in the window.

#!/usr/local/bin/perl -w
use strict;
use Gtk2 '-init';
use Glib qw/TRUE FALSE/;
use IO::Socket;

#-------------------Shared Variables-------------------
my $server = "irc.freenode.net";
my $nick = "simple";
my $login = "simple";
my $channel = "#GRRUVI";
my $sock;

#-------------------Main Loop-------------------
my $window = Gtk2::Window->new('toplevel');
$window->signal_connect( delete_event => sub {
    close($sock);
    Gtk2->main_quit;
});

$window->set_default_size( 300, 200 );

my $table = Gtk2::Table->new(2, 1, FALSE);
my $scroller = Gtk2::ScrolledWindow->new;
my $textview = Gtk2::TextView->new;
my $entry = Gtk2::Entry->new;

$scroller->add($textview);

$table->attach_defaults($scroller, 0, 1, 0, 1);
$table->attach_defaults($entry, 0, 1, 1, 2);

$window->add($table);

# allows for sending each line with an enter keypress
my $send_sig = $entry->signal_connect ('key-press-event' => sub {
        my ($widget,$event)= @_;
        if( $event->keyval() == 65293){  # a return key press
                my $text = $entry->get_text;
                if(defined $sock){ print $sock "PRIVMSG $channel :$text
\r\n";}
                $entry->set_text('');
                $entry->set_position(0);
        }
});

$entry->signal_handler_block($send_sig); #not connected yet
$entry->set_editable(0);

$window->show_all;

connecting();

Glib::IO->add_watch( fileno $sock, [qw/in hup err/], \&incoming_data,
$sock );

Gtk2->main;

#-------------------Connect to Server-------------------
sub connecting {
    # Connect to the IRC server.
    $sock = new IO::Socket::INET(
        PeerAddr => $server,
        PeerPort => 6667,
        Proto => 'tcp'
    ) or die "Can't connect\n";

    # Log on to the server.
    print $sock "NICK $nick\r\n";
    print $sock "USER $login 8 * :Perl IRC Hacks Robot\r\n";

    # Read lines from the server until it tells us we have connected.
    while (my $input = <$sock>) {
        # Check the numerical responses from the server.
        if ($input =~ /004/) {
            # We are now logged in.
            last;
        }
        elsif ($input =~ /433/) {
            die "Nickname is already in use.";
        }
    }
    # Join the channel.
    print $sock "JOIN $channel\r\n";

    $entry->set_editable(1);
    $entry->grab_focus;
    $entry->signal_handler_unblock ($send_sig);

    Gtk2->main_iteration while Gtk2->events_pending;
}

#-------------------Incoming data-------------------
sub incoming_data {

    my ( $fd, $condition, $fh ) = @_;

    if ( $condition eq 'in' ) {
        my $input = scalar <$fh>;
        chop $input;
#          if ( defined $data ) {
#                  # do something useful with the text.
#                  my $buffer = $textview->get_buffer;
#                  $buffer->insert( $buffer->get_end_iter, $data );
#          }

        if ($input =~ /^PING(.*)$/i) {
            # We must respond to PINGs to avoid being disconnected.
            print $sock "PONG $1\r\n";
        }
        else {
            # Print the raw line received by the bot.
            print "$input\n";
        }
    }
return TRUE;
}


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

Date: Mon, 11 Feb 2008 21:25:25 -0800 (PST)
From: deadpickle <deadpickle@gmail.com>
Subject: Re: A Gtk2 IRC Chat Client
Message-Id: <8e404fed-4229-4b29-8bc8-bff0518ac88d@b2g2000hsg.googlegroups.com>

I noticed a few things:
I tested the program using mIRC. I logged into the channel with the
client and under another name with mIRC. Logging in works fine, I can
see the clients nickname in the channel. What the problem seems to be
is when the MOTD is displayed. It seems that only a few lines of the
MOTD are displayed before the 'in' condition is stopped and the
message stops displaying in the terminal window. When I type in mIRC,
a line of the MOTD is displayed in terminal window. The $input
variable seems to be behind the real-time sending of the messages. I'm
not sure how to remove this lag and I'm looking for ideas.

#!/usr/local/bin/perl -w
use strict;
use Gtk2 '-init';
use Glib qw/TRUE FALSE/;
use IO::Socket;

#-------------------Shared Variables-------------------
my $server = "irc.freenode.net";
my $nick = "simple";
my $login = "simple";
my $channel = "#GRRUVI";
my $sock;

#-------------------Main Loop-------------------
my $window = Gtk2::Window->new('toplevel');
$window->signal_connect( delete_event => sub {
    close($sock);
    Gtk2->main_quit;
});

$window->set_default_size( 300, 200 );

my $table = Gtk2::Table->new(2, 1, FALSE);
my $scroller = Gtk2::ScrolledWindow->new;
my $textview = Gtk2::TextView->new;
my $entry = Gtk2::Entry->new;

$scroller->add($textview);

$table->attach_defaults($scroller, 0, 1, 0, 1);
$table->attach_defaults($entry, 0, 1, 1, 2);

$window->add($table);

# allows for sending each line with an enter keypress
my $send_sig = $entry->signal_connect ('key-press-event' => sub {
        my ($widget,$event)= @_;
        if( $event->keyval() == 65293){  # a return key press
                my $text = $entry->get_text;
                if(defined $sock){ print $sock "PRIVMSG $channel :$text
\r\n";}
                $entry->set_text('');
                $entry->set_position(0);
        }
});

$entry->signal_handler_block($send_sig); #not connected yet
$entry->set_editable(0);

$window->show_all;

connecting();

Glib::IO->add_watch( fileno $sock, [qw/in hup err/], \&incoming_data,
$sock );

Gtk2->main;

#-------------------Connect to Server-------------------
sub connecting {
    # Connect to the IRC server.
    $sock = new IO::Socket::INET(
        PeerAddr => $server,
        PeerPort => 6667,
        Proto => 'tcp'
    ) or die "Can't connect\n";

    # Log on to the server.
    print $sock "NICK $nick\r\n";
    print $sock "USER $login 8 * :Perl IRC Hacks Robot\r\n";

    # Read lines from the server until it tells us we have connected.
    while (my $input = <$sock>) {
        # Check the numerical responses from the server.
        if ($input =~ /004/) {
            # We are now logged in.
            last;
        }
        elsif ($input =~ /433/) {
            die "Nickname is already in use.";
        }
    }
    # Join the channel.
    print $sock "JOIN $channel\r\n";

    $entry->set_editable(1);
    $entry->grab_focus;
    $entry->signal_handler_unblock ($send_sig);

    Gtk2->main_iteration while Gtk2->events_pending;
}

#-------------------Incoming data-------------------
sub incoming_data {

    my ( $fd, $condition, $fh ) = @_;

    if ( $condition eq 'in' ) {
        my $input = scalar <$fh>;
        chop $input;
#          if ( defined $data ) {
#                  # do something useful with the text.
#                  my $buffer = $textview->get_buffer;
#                  $buffer->insert( $buffer->get_end_iter, $data );
#          }

        if ($input =~ /^PING(.*)$/i) {
            # We must respond to PINGs to avoid being disconnected.
            print $sock "PONG $1\r\n";
        }
        else {
            # Print the raw line received by the bot.
            print "$input\n";
        }
    }
    return TRUE;
}


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

Date: Tue, 12 Feb 2008 00:19:07 +0000 (UTC)
From: dkcombs@panix.com (David Combs)
Subject: Re: Converting milliseconds to seconds
Message-Id: <foqolr$h8$1@reader2.panix.com>

In article <fmekgp$e4t$1@agate.berkeley.edu>,
Ilya Zakharevich  <nospam-abuse@ilyaz.org> wrote:
>[A complimentary Cc of this posting was NOT [per weedlist] sent to
>Ilya Zakharevich 
><nospam-abuse@ilyaz.org>], who wrote in article <fmciie$2svu$1@agate.berkeley.edu>:
>> > As I said: you are greatly mistaken about the intended semantic of int(). 
>> > You may want to read the documentation for clarification.
>
>> As I said, the existing state of documentation of Perl is, at most,
>> pitiful.  (If you still do not realize this, I wrote some
>> [significant?] part of implementation of Perl's int().  *This* is why
>> I feel so hurt by this bug of mine.  ;-)
>
>Thinking about it more, this illusion of grandeur may be a piece of my
>imagination ;-).  I remember a lot of struggle to make int() and "%"
>conformant to `perldoc perlnumber'; I definitely implemented at least
>one of these - but I do not remember which.
>
>Sorry,
>Ilya

Am a bit confused about (1) the vocabulary being used
here and (2) about just what this bug you say you created is.

"Round down" (that was the term used earlier in the thread, yes?)
I always thought that had to do relative to a .5 or nearby.  Clearly,
I'm wrong, but can someone explain it a bit more fully?

Int for positives meant truncation, I thought.

For negatives, hmmm, what you *want* for int(-3.999)?

Or would some people *reasonably* want one thing and others the other?



And now, for something completely different:  Mod on negatives.

I think I recall that some languages and Knuth did it one way,
and other languages another. 


And did different fields do it different ways?

(Sorry for asking such totally idiotically "basic" stuff! :-)

Thanks,

David




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

Date: Tue, 12 Feb 2008 02:15:27 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Converting milliseconds to seconds
Message-Id: <v2c785-e581.ln1@osiris.mauzo.dyndns.org>


Quoth dkcombs@panix.com (David Combs):
> 
> Am a bit confused about (1) the vocabulary being used
> here and (2) about just what this bug you say you created is.
> 
> "Round down" (that was the term used earlier in the thread, yes?)
> I always thought that had to do relative to a .5 or nearby.  Clearly,
> I'm wrong, but can someone explain it a bit more fully?

'Round' is a vague term. The only thing it definitely means is 'convert
a float into an int'; the details of the conversion are left
unspecified. Most people unfamiliar with computer numerics want (or
think they want) 'round to nearest, i+0.5 -> i+1 for all integers i', as
they were taught in school. The most useful general-purpose form is
'round to even', that is 1.4->1, 1.5->2, 2.5->2, as with this form
round(a) + round(b) == round(a + b), which is useful.

> Int for positives meant truncation, I thought.
> 
> For negatives, hmmm, what you *want* for int(-3.999)?

In C and C-derived languages int means 'round to zero', or truncation,
so int(-3.99) == 3. If people want 'round (strictly) downwards', so
3.5->3 but -3.5->-4, that's POSIX::floor.

> Or would some people *reasonably* want one thing and others the other?

Depending on exactly what you're doing, you may want a different answer;
Perl lets you choose the answer you want.

> And now, for something completely different:  Mod on negatives.
> 
> I think I recall that some languages and Knuth did it one way,
> and other languages another. 

Does $a % $b mean int( int($a) / int($b) ) or does it mean '$r such that
$r is between 0 (inclusive) and $b (exclusive) with $b * $i + $r == $a
for some integer $i'? Perl chooses the latter, so -7 % 2 == 1, not -1.

Ben



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

Date: Tue, 12 Feb 2008 03:22:59 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Converting milliseconds to seconds
Message-Id: <m342r3d4tqi6n5otaib4ulmmvmsvq145rl@4ax.com>

Ben Morrow <ben@morrow.me.uk> wrote:
>'Round' is a vague term. The only thing it definitely means is 'convert
>a float into an int'; 

Actually 'convert a float to a specific number of decimals' which may be
zero decimals, but could just as well be any other number of decimals.

jue


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

Date: Mon, 11 Feb 2008 21:50:59 -0800 (PST)
From: bhabs <amitava@gmail.com>
Subject: LWP user agent grabs the intermediate wait page after POST intead of  the actual result page
Message-Id: <b1644679-735e-48e2-bb36-1eee67c88408@s37g2000prg.googlegroups.com>

Hi,

I wrote a small LWP based perl program to search the air fare from a
travel website using POST.

#!/usr/bin/perl
use strict;
use CGI;
use LWP;

my $web_browser = LWP::UserAgent->new();
push @{ $web_browser->requests_redirectable }, 'POST';
$web_browser->timeout(300);
my $web_response = ();

$web_response = $web_browser->post('http://blabla.com/travel/
InitialSearch.do',
                                                        [
                                                        'fromCity' =>
'SFO',
                                                        'toCIty'
=>  'CVG'
                                                        .... #the rest
of the fields occur here
                                                        ],
                                                        );

die "Error: ", $web_response->status_line()
  unless $web_response->is_success;

my @content = $web_response->content;
print "@content";

When I print the content, I see the "intermediate" wait page (where it
displays the progress bar using javascript.... =>  I matched the
content with the "view source" from IExplorer)
I am unable to capture the final air fare page. It takes time for the
website to do the search and then display the air fare result page.
How do I make my program wait for the actual result and not grab the
intermediate response.

Could anyone please help me on this?

Regards,
bhabs


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

Date: Tue, 12 Feb 2008 07:15:24 +0100
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: LWP user agent grabs the intermediate wait page after POST intead of  the actual result page
Message-Id: <47b1386f$0$2298$9b4e6d93@newsspool4.arcor-online.net>

bhabs wrote:
> I wrote a small LWP based perl program to search the air fare from a
> travel website using POST.
> 
[...code snipped]
> 
> When I print the content, I see the "intermediate" wait page (where it
> displays the progress bar using javascript.... =>  I matched the
> content with the "view source" from IExplorer)
> I am unable to capture the final air fare page. It takes time for the
> website to do the search and then display the air fare result page.
> How do I make my program wait for the actual result and not grab the
> intermediate response.

You have to simulate what the browser does, and from your
description, this is most likely a repeated ajax request
to the server. Analyze the behaviour of the javascript
and see how it fetches the progress state and what it
does once the result is calculated, then craft those
actions yourself. You best chances to see exactly what is going
on in the background is with a network sniffer like wireshark,
or a browser plugin like Firefox' Live HTTP Headers.

-Chris


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

Date: Tue, 12 Feb 2008 05:42:16 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Tue Feb 12 2008
Message-Id: <Jw42IG.nH6@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

Acme-Note-0.6
http://search.cpan.org/~ferreira/Acme-Note-0.6/
Make a mental note for programming style 
----
Algorithm-VectorClocks-0.0.1
http://search.cpan.org/~takeru/Algorithm-VectorClocks-0.0.1/
Generating a partial ordering of events in a distributed system 
----
App-Bondage-0.2.4
http://search.cpan.org/~hinrik/App-Bondage-0.2.4/
A featureful IRC bouncer based on POE::Component::IRC 
----
BSD-Getfsent-0.17
http://search.cpan.org/~schubiger/BSD-Getfsent-0.17/
Get file system descriptor file entry 
----
Catalyst-Model-DBIDM-0.03
http://search.cpan.org/~cbouvi/Catalyst-Model-DBIDM-0.03/
DBIx::DataModel model class 
----
Class-DBI-Pageset-0.10
http://search.cpan.org/~mgrimes/Class-DBI-Pageset-0.10/
A flexible pager utility for Class::DBI using Data::Pageset 
----
Class-Inflate-0.07
http://search.cpan.org/~kolibrie/Class-Inflate-0.07/
Inflate HASH Object from Values in Database 
----
Class-Inspector-1.20
http://search.cpan.org/~adamk/Class-Inspector-1.20/
Get information about a class and its structure 
----
Class-Inspector-1.21_01
http://search.cpan.org/~adamk/Class-Inspector-1.21_01/
Get information about a class and its structure 
----
Class-Simple-0.19
http://search.cpan.org/~sullivan/Class-Simple-0.19/
Simple Object-Oriented Base Class 
----
Config-Model-Xorg-0.509
http://search.cpan.org/~ddumont/Config-Model-Xorg-0.509/
Xorg configuration model for Config::Model 
----
Data-Table-1.54
http://search.cpan.org/~ezdb/Data-Table-1.54/
Data type related to database tables, spreadsheets, CSV/TSV files, HTML table displays, etc. 
----
File-chdir-0.1002
http://search.cpan.org/~dagolden/File-chdir-0.1002/
a more sensible way to change directories 
----
GD-Map-Mercator-1.01
http://search.cpan.org/~darnold/GD-Map-Mercator-1.01/
Create Mercator projected map images using GD 
----
Gaim-Log-Mailer-0.01
http://search.cpan.org/~mschilli/Gaim-Log-Mailer-0.01/
Have your Gaim/Pidgin logs mailed to you 
----
Gaim-Log-Parser-0.10
http://search.cpan.org/~mschilli/Gaim-Log-Parser-0.10/
Parse Gaim's Log Files 
----
Geo-Query-0.03
http://search.cpan.org/~retoh/Geo-Query-0.03/
Perl extension for querying geo related data from different sources. 
----
GraphViz-DBI-FromSchema-0.01
http://search.cpan.org/~smylers/GraphViz-DBI-FromSchema-0.01/
Create a diagram of database tables, using the foreign key information in the schema 
----
HTTP-Daemon-SSL-1.04
http://search.cpan.org/~aufflick/HTTP-Daemon-SSL-1.04/
a simple http server class with SSL support 
----
IO-Async-0.13
http://search.cpan.org/~pevans/IO-Async-0.13/
a collection of modules that implement asynchronous filehandle IO 
----
Kephra-0.3.6_6
http://search.cpan.org/~lichtkind/Kephra-0.3.6_6/
crossplatform, CPAN-installable GUI-Texteditor for Programmers, UI designed along Perl's Paradigms 
----
Kephra0.3.6_4
http://search.cpan.org/~lichtkind/Kephra0.3.6_4/
----
Keystone-Resolver-1.18
http://search.cpan.org/~mirk/Keystone-Resolver-1.18/
an OpenURL resolver 
----
List-Maker-v0.0.4
http://search.cpan.org/~dconway/List-Maker-v0.0.4/
Generate more sophisticated lists than just $a..$b 
----
Locale-Maketext-TieHash-L10N-0.07
http://search.cpan.org/~steffenw/Locale-Maketext-TieHash-L10N-0.07/
Tying language handle to a hash 
----
Mac-iTunes-Library-XML-0.01_05
http://search.cpan.org/~dinomite/Mac-iTunes-Library-XML-0.01_05/
Perl extension for parsing an iTunes XML library 
----
Math-Complex-1.52
http://search.cpan.org/~jhi/Math-Complex-1.52/
complex numbers and associated mathematical functions 
----
PDF-API2-Simple-1.1.4u
http://search.cpan.org/~redtree/PDF-API2-Simple-1.1.4u/
Simplistic wrapper for the excellent PDF::API2 modules 
----
POE-Component-IRC-Plugin-Validator-CSS-0.01
http://search.cpan.org/~zoffix/POE-Component-IRC-Plugin-Validator-CSS-0.01/
non-blocking CSS validator for IRC bots. 
----
POE-Component-WebService-Validator-CSS-W3C-0.02
http://search.cpan.org/~zoffix/POE-Component-WebService-Validator-CSS-W3C-0.02/
non-blocking access to CSS validator. 
----
PathTools-3.2701
http://search.cpan.org/~kwilliams/PathTools-3.2701/
----
Text-TermExtract-0.01
http://search.cpan.org/~mschilli/Text-TermExtract-0.01/
Extract terms from text 
----
Video-Dumper-QuickTime-1.0001
http://search.cpan.org/~grandpa/Video-Dumper-QuickTime-1.0001/
Dump QuickTime movie file structure 
----
YAML-YuyuPress-0.07
http://search.cpan.org/~jmerelo/YAML-YuyuPress-0.07/
Tool for making presentations out of YAML files. 
----
YAML-YuyuPress-0.07_1
http://search.cpan.org/~jmerelo/YAML-YuyuPress-0.07_1/
Tool for making presentations out of YAML files. 
----
re-engine-TRE-0.02
http://search.cpan.org/~avar/re-engine-TRE-0.02/
TRE regular expression engine 


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Mon, 11 Feb 2008 11:34:25 -0800 (PST)
From: pgodfrin <pgodfrin@gmail.com>
Subject: Re: Using END and the die function
Message-Id: <c9c8c89e-00ec-4b07-b45f-bd2da5bb371e@e25g2000prg.googlegroups.com>

On Feb 11, 11:42 am, Graham Drabble <usene...@drabble.me.uk> wrote:
> On 11 Feb 2008 Ben Morrow <b...@morrow.me.uk> wrote innews:66m485-cr1.ln1@osiris.mauzo.dyndns.org:
>
>
>
> > Quoth Gunnar Hjalmarsson <nore...@gunnar.cc>:
> >> Graham Drabble wrote:
> >> > On 08 Feb 2008 Tad J McClellan <ta...@seesig.invalid> wrote in
> >> >news:slrnfqpr0o.96t.tadmc@tadmc30.sbcglobal.net:
>
> >> >>    mkdir($tgt_dir) or warn "Mkdir ($tgt_dir) command
> >> >>    failed.\n" and exit 42;
>
> >> > Can warn() ever return false?
>
> >> Not AFAIK.
>
> > Make that 'no' :). The warn op unconditionally returns true.
>
> Good. Can't see any mention of that in the manual though. Any chance of
> an addition to the man page?
>
> --
> Graham Drabblehttp://www.drabble.me.uk/

A man after my own heart. In fact, why is it often guesswork in seeing
what the arguments are to a function and what the possible return
values are?

btw - this works effectively but not elegantly:

    mkdir($tgt_bkp) or warn aud_dt, "Mkdir ($tgt_bkp) command failed.
\n" and $return_code=99 and exit;

Funny - all I'm trying to do is make this program communicate with the
outside world that something failed, but I wonder if using and END
block is messing me up hmmm...
pg


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

Date: Mon, 11 Feb 2008 12:20:52 -0800 (PST)
From: pgodfrin <pgodfrin@gmail.com>
Subject: Re: Using END and the die function
Message-Id: <e89c13c0-5c9b-4f49-a1c6-f5be797b3201@e25g2000prg.googlegroups.com>

Well - over twenty years in this business and I still find ways to be
an idiot. What I did not include in my previous posts was that in my
END subroutine I had an extra call - I didn't think it was important
(duh!). Of course it is. So by 'trapping' the $? before processing my
END code, things actually work as intended:

   mkdir($tgt_dir) or die "Mkdir ($tgt_dir) command failed.\n";
   END
   {
   $rc=$? ; # trap $? 'child error'
   print `date`,"Script ended. RC=$rc \n";
   $?=$rc;
   }

The `date` was setting the $? variable, so the the die function worked
but I was self-immolating in my END routine...
pg


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

Date: Mon, 11 Feb 2008 21:47:11 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Using END and the die function
Message-Id: <vbs685-pl61.ln1@osiris.mauzo.dyndns.org>


Quoth pgodfrin <pgodfrin@gmail.com>:
> Well - over twenty years in this business and I still find ways to be
> an idiot. What I did not include in my previous posts was that in my
> END subroutine I had an extra call - I didn't think it was important
> (duh!). Of course it is. So by 'trapping' the $? before processing my
> END code, things actually work as intended:
> 
>    mkdir($tgt_dir) or die "Mkdir ($tgt_dir) command failed.\n";
>    END
>    {
>    $rc=$? ; # trap $? 'child error'
>    print `date`,"Script ended. RC=$rc \n";
>    $?=$rc;
>    }

A better way to do this is

    END {
        my $rc = $?;
        local $?;
        print `date`, "Script ended. RC=$rc\n";
    }

as then perl will restore $? for you. Also, you *really* don't need to
call date(1) just to print the date. If you just want the default
ctime(3) output, you can use

    print scalar localtime, "...";

otherwise, use POSIX::strftime to format the date as you like.

Ben



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

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


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