[23434] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5651 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 13 09:07:41 2003

Date: Mon, 13 Oct 2003 06:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 13 Oct 2003     Volume: 10 Number: 5651

Today's topics:
    Re: [ Curses::UI ]  How to make application resize itse <minceme@start.no>
        Advise on drawing charts in Perl (Ahmad)
    Re: Advise on drawing charts in Perl <nospam@bigpond.com>
    Re: Advise on drawing charts in Perl <abigail@abigail.nl>
    Re: CGI.pm File Upload doesn't work (blocks) on my Serv news@roaima.freeserve.co.uk
    Re: CGI.pm upload() (Anno Siegel)
    Re: chmod files on ISP's server <kalinaubears@iinet.net.au>
    Re: chmod files on ISP's server (Philip)
    Re: chmod files on ISP's server <matthias.weckman@hotmail.com>
        Counting device reboots <dcasselano@nyc.rr.com>
    Re: Counting device reboots (Anno Siegel)
    Re: embedding Variable nobull@mail.com
    Re: embedding Variable nobull@mail.com
        Help: Install DBI-Oracle on cygwin with Perl 5.8.0 <jameshull@comcast.net>
    Re: How To activate command line history in debugger? <kurt.kronschnabl-nospam@ica-intercom-akademie.de>
        multiline regex <mjj@isorauta.ntc.nokia.com>
    Re: multiline regex (Anno Siegel)
    Re: Net::SSH::Perl : multiple connections fails (Helge Cramer)
    Re: Post radiobuttons (forms) using lwp-useragent (Anno Siegel)
    Re: Q: good time to buy the camel book? <abigail@abigail.nl>
    Re: Strange printf behavior <kalinaubears@iinet.net.au>
    Re: Strange printf behavior (Jay Tilton)
        unpack - strange behaviour (ifiaz)
    Re: unpack - strange behaviour (Anno Siegel)
    Re: Using map to assign var values from hash (Anno Siegel)
    Re: Why Is My Hash Assignment Taking So Long? (Anno Siegel)
    Re: Why Is My Hash Assignment Taking So Long? <kalinaubears@iinet.net.au>
        Wierdness with code to display file creation date <megapode@hotmail.com>
    Re: Wierdness with code to display file creation date (Anno Siegel)
    Re: Wierdness with code to display file creation date <megapode@hotmail.com>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 13 Oct 2003 09:11:22 +0000 (UTC)
From: Vlad Tepes <minceme@start.no>
Subject: Re: [ Curses::UI ]  How to make application resize itself to size of terminal?
Message-Id: <slrnbokn80.1bv.minceme@imap-a.start.no>

* Rocco Caputo <troc@pobox.com>        (CCLXXXVI'th day of year MMIII)

[ About resizing Curses::UI applications ]

> Have you contacted the author? 

Now I have been in contact with the maintainer of C::UI.  He says
terminal resizing isn't supported and will be hard to implement.  

Looks like I'm out of luck. <big> :-( </big>

> There's also bug-Curses-UI@rt.cpan.org, if you'd like your e-mail
> to be tracked in the CPAN bug tracker.

If a feature is not supported then it is not a bug, or is it?

-- 
                                                                \/L/\D


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

Date: 13 Oct 2003 00:34:38 -0700
From: eng_ak@link.net (Ahmad)
Subject: Advise on drawing charts in Perl
Message-Id: <3014031e.0310122334.c1c705c@posting.google.com>

Hi all,

  Can anyone advise me whether to use the Chart module or GD::Graph,
to draw graphs in perl??

Thnx


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

Date: Mon, 13 Oct 2003 17:49:06 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Advise on drawing charts in Perl
Message-Id: <1358827.75JpkFrJHm@gregs-web-hosting-and-pickle-farming>

It was a dark and stormy night, and Ahmad managed to scribble:

> Hi all,
> 
>   Can anyone advise me whether to use the Chart module or GD::Graph,
> to draw graphs in perl??
> 
> Thnx

I use GD, because I want to make my graphs exactly to my requirements.
But you end up doing all the scaling yourself.

gtoomey


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

Date: 13 Oct 2003 09:46:00 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Advise on drawing charts in Perl
Message-Id: <slrnbokt2o.u0c.abigail@alexandra.abigail.nl>

Ahmad (eng_ak@link.net) wrote on MMMDCXCV September MCMXCIII in
<URL:news:3014031e.0310122334.c1c705c@posting.google.com>:
[]  Hi all,
[]  
[]    Can anyone advise me whether to use the Chart module or GD::Graph,
[]  to draw graphs in perl??


I always open a pipe to gnuplot for my graphing.


Abigail
-- 
perl -swleprint -- -_=Just\ another\ Perl\ Hacker


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

Date: Mon, 13 Oct 2003 08:43:57 +0100
From: news@roaima.freeserve.co.uk
Subject: Re: CGI.pm File Upload doesn't work (blocks) on my Server (but works on my Desktop)
Message-Id: <tm1q51-o7h.ln1@news.roaima.co.uk>

Bjoern <bjoern_p1@gmx.net> wrote:
> What coud be wrong? I've checked that /temp can be written to by anyone, 

There is no /temp on a standard unix or gnu/linux distribution.

Chris
-- 
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}


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

Date: 13 Oct 2003 12:32:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: CGI.pm upload()
Message-Id: <bme60k$lel$5@mamenchi.zrz.TU-Berlin.DE>

D Borland <nospampleasethankyouta@somewhereinthebluenowhere.com> wrote in comp.lang.perl.misc:
> Hi Folks,
> 
> Can anyone here tell me if there is a safe alternative to CGI.pm's upload
> function?
> 
> There main reason for needing this is that i am needing to upload multiple
> files, (eg. image1, image2, image3, image4), but you can only pass the
> upload function an actual param not a $scalar value, so this means i have to
> specify each upload i will need and that means 4 times as much code, but
> most of all is that when it fails to upload the files, it's impossible to
> see what it failed on and why.
> 
> Hope i explained that OK :)

It comes across a little breathless.  A period or two would have helped.

Anno


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

Date: Mon, 13 Oct 2003 14:10:20 +1000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: chmod files on ISP's server
Message-Id: <3f8a2660$0$23613$5a62ac22@freenews.iinet.net.au>

Bob Walton wrote:

> 
> 
> Well, if you were at a typical ftp client (like Windoze's ftp, for 
> example) all logged in and in the correct directory, you could type:
> 
>    quote site chmod 755 filename.pl
> 
> at the ftp> prompt to do that (assuming the remote web server is a 
> typical Unix-type system).  So I suspect the Perlish way would be to use 
> the ->quot() method in Net::FTP.  But I haven't tried it.
> 
> Good luck.

Yep - works nicely when I supply the command as 'site chmod 755 
filename.pl' rather than simply 'chmod 755 filename.pl' as I had been 
trying.

Of course the bloody script still won't run :-))

I'll eventually sort it out, no doubt. Thanks for the assistance.

Cheers,
Rob


-- 
To reply by email u have to take out the u in kalinaubears.



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

Date: 12 Oct 2003 23:10:39 -0700
From: drew@perlmad.com (Philip)
Subject: Re: chmod files on ISP's server
Message-Id: <9826ff94.0310122210.38ada226@posting.google.com>

try using the quot() method to execute a chmod command. for example:
$ftp->quot("site", "chmod", $mode, $file)


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

Date: Mon, 13 Oct 2003 14:29:29 +0200
From: Matthias Weckman <matthias.weckman@hotmail.com>
Subject: Re: chmod files on ISP's server
Message-Id: <3f8a9aaf$0$82194$e4fe514c@dreader9.news.xs4all.nl>

Sisyphus wrote:
> Hi,
> 
> Is there a general way, using perl, to change the permissions of my cgi 
> scripts once I've uploaded them to my ISP's server ?

That depends on which ftp server your ISP uses. Changing permissions of 
remote files is not part of the ftp protocol. However, the ftp protocol 
does offer the possibility to execute certain remote commands, but the 
implementation is server specific.

> I'm using Net::FTP to upload them, but they're arriving without the 
> necessary 'execute' permissions - and I don't see a way of fixing that 
> with either Net::FTP or Net::Cmd.

The Net::FTP module offers support for this through the 'site' method:
try
     $ftp->site( 'chmod 755 ' . $filename);

[snip]

> I can see the permissions (via ftp) in the browser - I just haven't yet 
> found a way to alter them using perl or any other means. (Should it be 
> achievable via the web browser ?? I would prefer to be doing it with perl.)

I don't think web browsers offer this possibility. Have you considered 
using an ftp client to access an ftp server?

> Cheers,
> Rob

HTH,
Matthias



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

Date: Mon, 13 Oct 2003 11:12:32 GMT
From: "Mista_Blista" <dcasselano@nyc.rr.com>
Subject: Counting device reboots
Message-Id: <AMvib.73443$lZ6.12003317@twister.nyc.rr.com>

Hello,

I know this must be amazingly easy but I am a perl amateur. I want to use
perl to analyze the log file info shown below, and count the number of times
each IP address appears. I also want it to show me the range of dates and
times of the first and last time the IP address appears in the log file.


Oct 6 17:15:38 172.16.21.101
Oct 7 14:49:17 172.16.21.101
Oct 7 17:35:22 172.16.21.101
Oct 3 15:26:57 172.16.21.102
Oct 5 11:28:24 172.16.21.102
Oct 5 14:09:52 172.16.21.102
Oct 5 23:34:39 172.16.21.102
Oct 6 00:26:09 172.16.21.102
Oct 7 04:11:32 172.16.21.102
Oct 3 00:03:58 172.16.21.103
Oct 3 22:45:57 172.16.21.103
Oct 4 12:55:10 172.16.21.103
Oct 4 13:34:11 172.16.21.103
Oct 5 02:20:49 172.16.21.103
Oct 6 03:46:05 172.16.21.103
Oct 6 13:22:40 172.16.21.103
Oct 6 13:43:14 172.16.21.103
Oct 6 15:24:55 172.16.21.103
Oct 6 16:17:43 172.16.21.103
Oct 8 00:35:24 172.16.21.103
Oct 2 16:43:13 172.16.21.104
Oct 2 21:29:22 172.16.21.104
Oct 3 15:17:24 172.16.21.104
Oct 4 00:12:18 172.16.21.104
Oct 6 00:42:07 172.16.21.104
Oct 6 14:10:25 172.16.21.104
Oct 6 16:25:00 172.16.21.104
Oct 6 16:32:35 172.16.21.104
Oct 6 17:51:06 172.16.21.104
Oct 6 18:09:04 172.16.21.104

The output would be similar to this below

Date Range                   Device                        # of Reboots
Oct.2 - Oct. 6               172.16.21.104            10




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

Date: 13 Oct 2003 11:50:59 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Counting device reboots
Message-Id: <bme3j3$lel$2@mamenchi.zrz.TU-Berlin.DE>

Mista_Blista <dcasselano@nyc.rr.com> wrote in comp.lang.perl.misc:
> Hello,
> 
> I know this must be amazingly easy but I am a perl amateur. I want to use
> perl to analyze the log file info shown below, and count the number of times
> each IP address appears. I also want it to show me the range of dates and
> times of the first and last time the IP address appears in the log file.
>
> Oct 6 17:15:38 172.16.21.101
> Oct 7 14:49:17 172.16.21.101
> Oct 5 11:28:24 172.16.21.102

You will first have to collect all the dates that pertain to one
address in an array.  This code does that:

    my %coll;
    while ( <DATA> ) {
        chomp;
        my ( $date, $ip) = split /(?<=:\d\d) /;
        push @{ $coll{ $ip}}, $date;
    }

The number of reboots is the number of elements of each array.  Now find
a module on CPAN that can parse your date format into something easily
comparable (epoch seconds), and extract the maximum and minimum from each
list.

Anno


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

Date: 13 Oct 2003 04:55:53 -0700
From: nobull@mail.com
Subject: Re: embedding Variable
Message-Id: <4dafc536.0310130355.266381c7@posting.google.com>

Cognition Peon <cenxnfu@rpr.nevmban.rqh> wrote in upside down:
> 9:37pm, IP packets from Mike Solomon delivered:
> > my $test = "test";
> >
> > my $output "my test = $test\n";
> >
> > $test = "NEW TEST";
> >
> > print $output;
> >
> > then I will get : my test = test";
> >
> > is there any way of writing this so as I change $test , $output also changes

> #!/usr/bin/perl  -w
> 
> my $test = "test";
> my $output = output();
> print $output;
> $test = "NEW TEST";
> $output = output();
> print $output;
> 
> sub output {
> 
>         return "my test = $test\n";
> }

Usually one would simply use an _anon_ sub. 

my $test = "test";
my $output = sub { "my test = $test\n" };
print $output->();
$test = "NEW TEST";
print $output->();

But if you want $output to look like an ordinary scalar you could use
or a tied scalar or an object that overloads "" depending on when you
want the subtitution to occur...

use Tie::OneOff;
my $test = "test";
tie my $output, 'Tie::OneOff', sub { "my test = $test\n" };
print $output;
my $copy_output = $output; # substition occurs here
$test = "NEW TEST";
print $output;
print $copy_output; # prints "my test = test"


# For reasons I don't understand the current release (0.1) of 
# String::Interpolate has stopped working - so don't use it!
use String::Interpolate;
my $test = "test";
my $output = String::Interpolate->new( { test => \$test}, 'my test =
$test\n' );
print $output;
my $copy_output = $output; # substition does not occur here
$test = "NEW TEST";
print $output;
print $copy_output; # prints "my test = NEW TEST"


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

Date: 13 Oct 2003 05:01:41 -0700
From: nobull@mail.com
Subject: Re: embedding Variable
Message-Id: <4dafc536.0310130401.698be3e8@posting.google.com>

tiltonj@erols.com (Jay Tilton) wrote in message news:<3f88c868.66279602@news.erols.com>...
>     package MyString;
>     sub TIESCALAR {
>         my $class = shift;
>         my($fmt, @srefs) = @_;
>         bless sub{ sprintf $fmt, map $$_, @srefs }, $class;
>     }
>     sub FETCH{ shift->() }
> 
>     package main;
>     tie my($output), 'MyString', "my test = %s", \(my $test);

I really think you shouldn't have to declare a new package just to
make one-off tied variable...

use Tie::OneOff;
my $test;
tie my $output, 'Tie::OneOff', sub {
   sprintf "my test = %s", $test;
};


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

Date: Mon, 13 Oct 2003 07:15:00 -0400
From: "James Hull" <jameshull@comcast.net>
Subject: Help: Install DBI-Oracle on cygwin with Perl 5.8.0
Message-Id: <EOednX5MUu3pFReiU-KYgg@comcast.com>

Hi All:

I am new in the Perl world. So far I have installed cygwin and Perl 5.8.0
along with Perl DBI and DBD::Oracle modules. NowI am trying to install Perl
Tk on my PC (Windows 2K). I have tried both Tk804.025 and Tk804.025_beta2.
However, both versions failed with following errors. It appeared that the
command "perl Makefile.PL" ran successfully, but the "make" command failed.
I also ran "perl -Mblib demos/widget". It was complaining it "Can't locate
Tk/Event.pm in @INC" (See following enclosed error message).

BTW, what is "@INC"?

Thanks in advance.

Jim


Error Messages from "make" and "perl -Mblib demos/widget":

$ make
cd pTk && make
make[1]: Entering directory `/Tk804.025_beta2/pTk'
make[1]: Leaving directory `/Tk804.025_beta2/pTk'
make[1]: Entering directory `/Tk804.025_beta2/pTk'
make[1]: Leaving directory `/Tk804.025_beta2/pTk'
make[1]: Entering directory `/Tk804.025_beta2/pod'
make[1]: Leaving directory `/Tk804.025_beta2/pod'
make[1]: Entering directory `/Tk804.025_beta2/demos'
cp widget ../blib/script/widget
/usr/bin/perl.exe "-MExtUtils::MY" -e "MY->fixin(shift)"
 ../blib/script/widget
make[1]: Leaving directory `/Tk804.025_beta2/demos'
make[1]: Entering directory `/Tk804.025_beta2/Xlib'
make[2]: Entering directory `/Tk804.025_beta2/Xlib/X'
Running Mkbootstrap for Tk::X ()
chmod 644 X.bs
rm -f ../../blib/arch/auto/Tk/X/X.dll
LD_RUN_PATH="" gcc -shared  -s -L/usr/local/lib X.o  -o
 ../../blib/arch/auto/Tk/X/X.dll  /usr/lib/pe
ti-64int/CORE/libperl.dll.a -L/lib/w32api -lcomdlg32 -lgdi32
chmod 755 ../../blib/arch/auto/Tk/X/X.dll
cp X.bs ../../blib/arch/auto/Tk/X/X.bs
chmod 644 ../../blib/arch/auto/Tk/X/X.bs
make[2]: Leaving directory `/Tk804.025_beta2/Xlib/X'
gcc -c  -I.. -I../pTk/mTk/xlib -DPERL_USE_SAFE_PUTENV -fno-strict-aliasing -
DUSEIMPORTLIB -O3   -DVE
XS_VERSION=\"804.025\"
"-I/usr/lib/perl5/5.8.0/cygwin-multi-64int/CORE"  -D__WIN32__ -D_WIN32 -Wall
Wno-comment -Wno-unused -D__USE_FIXED_PROTOTYPES__ Xlib.c
Xlib.xs:13: error: parse error before '*' token
Xlib.xs:13: warning: data definition has no type or storage class
Xlib.xs: In function `boot_Tk__Xlib':
Xlib.xs:383: warning: cast to pointer from integer of different size
Xlib.xs:383: warning: cast to pointer from integer of different size
Xlib.xs:383: warning: cast to pointer from integer of different size
Xlib.xs:383: warning: cast to pointer from integer of different size
Xlib.xs:383: warning: cast to pointer from integer of different size
Xlib.xs:383: warning: cast to pointer from integer of different size
Xlib.xs:383: warning: cast to pointer from integer of different size
Xlib.xs:383: warning: cast to pointer from integer of different size
Xlib.xs:383: warning: cast to pointer from integer of different size
Xlib.xs:383: error: `XlibVtab' undeclared (first use in this function)
Xlib.xs:383: error: (Each undeclared identifier is reported only once
Xlib.xs:383: error: for each function it appears in.)
Xlib.xs:383: error: parse error before ')' token
make[1]: *** [Xlib.o] Error 1
make[1]: Leaving directory `/Tk804.025_beta2/Xlib'
make: *** [subdirs] Error 2


$ perl -Mblib demos/widget
Can't locate Tk/Event.pm in @INC (@INC contains: /Tk804.025_beta2/blib/arch
/Tk804.025_beta2/blib/lib /usr/lib/perl5/5.8
 .0/cygwin-multi-64int /usr/lib/perl5/5.8.0
/usr/lib/perl5/site_perl/5.8.0/cygwin-multi-64int
/usr/lib/perl5/site_perl/5.
8.0 /usr/lib/perl5/site_perl .) at /Tk804.025_beta2/blib/lib/Tk.pm line 13.
BEGIN failed--compilation aborted at /Tk804.025_beta2/blib/lib/Tk.pm line
13.
Compilation failed in require at demos/widget line 4.
BEGIN failed--compilation aborted at demos/widget line 4.





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

Date: Mon, 13 Oct 2003 14:05:16 +0200
From: Kurt Kronschnabl <kurt.kronschnabl-nospam@ica-intercom-akademie.de>
Subject: Re: How To activate command line history in debugger?
Message-Id: <bme5uf$h3h$01$1@news.t-online.com>

Hello Peter,

Peter Scott wrote:

> 	tar zxf TermReadKey-2.21.tar.gz
> 	cd TermReadKey-2.21
> 	perl Makefile.PL
> 	make test
> 	make install
> 

I got the tar file (http://www.cpan.org/authors/id/J/JS/JSTOWE/ is a 
http source I found) and everthing ran without any error.

A simple test with a degbug session (perl -d)showed me unfortunaltely no 
success. It's still displaying the ESC-Sequence of Up-arrow.

Could I check or do something else?

If you would have a little bit of time ;=) it would be a way for you to 
boot a Knoppix CD to see the effect live.

Regards, Kurt



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

Date: Mon, 13 Oct 2003 10:53:29 GMT
From: Mike Jackson <mjj@isorauta.ntc.nokia.com>
Subject: multiline regex
Message-Id: <Juvib.127$g4.1913@news2.nokia.com>

Hi,
  I would like to convert this block of text:

(app "webserver"
	(ip "1.2.3.4")
	(name "foo")
	(host "somehost")
)


to this:

app.webserver.ip="1.2.3.4";
app.webserver.name="foo";
app.webserver.host="somehost";


and skip processing of the entire block if the top level contains a 
"no", for example:

(some_condition "no"
	(foo "")
	(bar "")
)


Is there already some method of doing this in perl, or is this a regex 
job? Any advice?

Thanks,
Mike



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

Date: 13 Oct 2003 11:54:35 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: multiline regex
Message-Id: <bme3pr$lel$3@mamenchi.zrz.TU-Berlin.DE>

Mike Jackson  <mjj@isorauta.ntc.nokia.com> wrote in comp.lang.perl.misc:
> Hi,
>   I would like to convert this block of text:
> 
> (app "webserver"
> 	(ip "1.2.3.4")
> 	(name "foo")
> 	(host "somehost")
> )
> 
> 
> to this:
> 
> app.webserver.ip="1.2.3.4";
> app.webserver.name="foo";
> app.webserver.host="somehost";
> 
> 
> and skip processing of the entire block if the top level contains a 
> "no", for example:
> 
> (some_condition "no"
> 	(foo "")
> 	(bar "")
> )
> 
> 
> Is there already some method of doing this in perl, or is this a regex 
> job? Any advice?

What have you tried so far?

We help writing scripts, but we're not in the business of delivering
to specification.  

You have nested parentheses to parse, so Text::Balanced will probably
figure in the solution.

Anno


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

Date: 13 Oct 2003 05:35:43 -0700
From: cramer@crpc.de (Helge Cramer)
Subject: Re: Net::SSH::Perl : multiple connections fails
Message-Id: <7c754dd5.0310130435.444f65d9@posting.google.com>

Yes, I do run the script as root, so Net::SSH::Perl should set
privileged=1 on its own (as described in the documentation).
Any further suggestions (perhaps how to make connection 2 after
connection 1)?

Helge Cramer


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

Date: 13 Oct 2003 12:02:53 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Post radiobuttons (forms) using lwp-useragent
Message-Id: <bme49d$lel$4@mamenchi.zrz.TU-Berlin.DE>

Rubel Kanubel <rubelkanubel@yahoo.no> wrote in comp.lang.perl.misc:
> <tea_spoon>
> 
> $req = POST 'http://www.acme.com/login.php', [ rad_query => 'alt_1' ];
> $res = $ua->request($req);
> 
> </tea_spoon>
> 
> 
> Please point out exactly what you mean by "I was about to point out
> that you wanted 'alt_1'". FYI, this is just an example of the code
> that I'm executing to post form elements. The above two statements
> illustrates my attempt (that fails) to post a radio button form
> element. I'm sorry for the mis-spellings, but you should be able to
> make out for yourself the problem without getting picky about it.

Picky?  You are the one wanting help, so it's your job to present
the problem in a comprehensible way.  So long...

Anno


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

Date: 13 Oct 2003 09:53:13 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Q: good time to buy the camel book?
Message-Id: <slrnboktg8.u0c.abigail@alexandra.abigail.nl>

David Petrou (dpetrou@ece.cmu.edu) wrote on MMMDCXCV September MCMXCIII
in <URL:news:bmcuuf$cam$1@nntp.ece.cmu.edu>:
%%  hi.  i was thinking of buying the 3rd ed. of the camel book.  i peruse
%%  my 2nd ed. copy with increasing regularity and would prefer reading
%%  the newer edition.
%%  
%%  however, the 3rd ed. is copyright 2000 and we're over half done with
%%  2003, which seems like a long time for something like perl.  how
%%  likely is it that a 4th ed. will come out in the next 6 months or so?


I'd say the chances of a 4th edition documenting Perl 5 are extremely
small. The next edition of the Camel will document Perl 6, and will
be released shortly before the next TPC after the release of Perl 6.

Note also that the third edition documents perl 5.6. After that, only one
major release occurred; and the new features of that wouldn't be discussed
extensively in the Camel anyway, because of their relative advanceness
(Unicode, threads, PerlIO) and the need to make a carryable book.



Abigail
-- 
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"


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

Date: Mon, 13 Oct 2003 14:50:16 +1000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: Strange printf behavior
Message-Id: <3f8a2fbd$0$23611$5a62ac22@freenews.iinet.net.au>

Bob Walton wrote:
> Perl:  Activestate build 806 (5.8.0)
> OS:  Windows 98SE
> 
> I note that:
> 
>    perl -e "printf '%0d %0d',1,2;"
> 
> gives:  1 2
> 
> but that:
> 
>    perl -e "printf '%d %d',1,2;"
> 
> gives:  d
> 
> and that:
> 
>    perl -e "printf '%d %0d',1,2;"
> 
> gives:  0d
> 
> and that:
> 
> perl -e "printf '%d %garbage',1,2;"
> 
> gives:  garbage
> 
> Does anyone else observe this behavior and, if so, have an explanation?
> 

Not getting that with build 802 on Win2k - it seems to be quite ok (in 
both command.com and cmd.exe shells).

Also nothing strange with AS build 626 (perl 5.6.1).

Cheers,
Rob

-- 
To reply by email u have to take out the u in kalinaubears.



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

Date: Mon, 13 Oct 2003 05:03:01 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Strange printf behavior
Message-Id: <3f8a300a.64718866@news.erols.com>

Bob Walton <invalid-email@rochester.rr.com> wrote:

: Perl:  Activestate build 806 (5.8.0)
: OS:  Windows 98SE
: 
: I note that:
: 
:     perl -e "printf '%0d %0d',1,2;"
: 
: gives:  1 2
: 
: but that:
: 
:     perl -e "printf '%d %d',1,2;"
: 
: gives:  d
: 
: and that:
: 
:     perl -e "printf '%d %0d',1,2;"
: 
: gives:  0d
: 
: and that:
: 
: perl -e "printf '%d %garbage',1,2;"
: 
: gives:  garbage
: 
: Does anyone else observe this behavior and, if so, have an explanation?

The '%' character is meaningful to the command interpreter.  It is used
to interpolate environment variables.

Double up a '%' character to ensure the shell doesn't try to do any
interpolation, e.g.

    perl -e "printf '%%d %%d',1,2;"



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

Date: 13 Oct 2003 03:01:53 -0700
From: ifiaz@hotmail.com (ifiaz)
Subject: unpack - strange behaviour
Message-Id: <93c1947c.0310130201.8c19b18@posting.google.com>

The following program run:

($field1, $field2, $field3, $field4, $field5) = unpack("A4 A1 A3 A1
A*", "this is v strange");

print "|$field1|\n";
print "|$field2|\n";
print "|$field3|\n";
print "|$field4|\n";
print "|$field5|\n";

and the result is this:

|this|
||
|is|
|v|
| strange|

But, I expect a space for $field2 i.e. | |

Why $field4 can print with a single character and
$field2 can't. Am I missing something?


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

Date: 13 Oct 2003 10:15:48 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: unpack - strange behaviour
Message-Id: <bmdu0k$gji$2@mamenchi.zrz.TU-Berlin.DE>

ifiaz <ifiaz@hotmail.com> wrote in comp.lang.perl.misc:
> The following program run:
> 
> ($field1, $field2, $field3, $field4, $field5) = unpack("A4 A1 A3 A1
> A*", "this is v strange");
> 
> print "|$field1|\n";
> print "|$field2|\n";
> print "|$field3|\n";
> print "|$field4|\n";
> print "|$field5|\n";
> 
> and the result is this:
> 
> |this|
> ||
> |is|
> |v|
> | strange|
> 
> But, I expect a space for $field2 i.e. | |
> 
> Why $field4 can print with a single character and
> $field2 can't. Am I missing something?

Yes.  Perldoc -f pack:

    as necessary.  When unpacking, "A" strips
    trailing spaces and nulls, "Z" strips

Use "a" instead.

Anno


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

Date: 13 Oct 2003 10:23:27 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Using map to assign var values from hash
Message-Id: <bmduev$gji$3@mamenchi.zrz.TU-Berlin.DE>

Malcolm Dew-Jones <yf110@vtn1.victoria.tc.ca> wrote in comp.lang.perl.misc:
> Eric J. Roode (REMOVEsdnCAPS@comcast.net) wrote:
> : Wolfgang Fischer <Wolfgang_.fischer@lycos.de> wrote in
> 
> : > you can't use variables like $$_; You have to specify the variable
> : > name at compile time, not at run time.
> 
> : Please do not post answers to questions unless you know what you're talking 
> : about. 
> 
> I think we can safely assume that he thought he knew what he was talking 
> about, so your advice wouldn't have made any difference.

Wouldn't have, in the past.  It may make a difference in the future.

Anno


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

Date: 13 Oct 2003 09:35:17 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Why Is My Hash Assignment Taking So Long?
Message-Id: <bmdrkl$gji$1@mamenchi.zrz.TU-Berlin.DE>

James E Keenan <nospam_for_jkeen@concentric.net> wrote in comp.lang.perl.misc:
> I need to build a hash whose elements represent characteristics of each of
> 9600 files in a single directory.  I am trying to figure out why this hash
> assignment is taking so long.  Here is my code:

That's a lot of files to keep in a single directory.  That is the
reason why it's slow.

There are a few obvious inefficiencies in your code, but these have
no measurable effect.

>     my %threads_chars = (
>         dir => "~/Threads",
>         pattern => "\.thr\.txt",

You have a quoting problem here.  Backslashing the dots in a *string*
has no effect.  After the string is built, the backslashes are gone.
Use qr// to quote patterns:

        pattern => qr/\.thr\.txt/,

>     );
> 
>     $threadsref = analyze_dir(\%threads_chars);
> 
>     sub analyze_dir {
>         my $hashref = shift;
>         my $dir = ${$hashref}{'dir'};
>         my $pattern = ${$hashref}{'pattern'};
>         my (%filechars, $count);
>         chdir $dir or die "Couldn't change to $dir: $!";
>         opendir DIR, $dir or die "Couldn't open $dir: $!";
> 
>         #1: get files in $dir which match pattern
>         my @files = grep { m|$pattern$|o } readdir DIR;

Why do you build a list of all files just to process them once?  Walk
through the directory and skip what you don't want.  You'll save
the list (space efficiency) and you'll only have to apply the regex
once (time efficiency).

You should also take care to de-select anything that isn't a plain file.

>         print '@files established for ', "$dir\n";
> 
>         #2:  build a hash where each element is keyed by the core of the
> file name
>         #    and the value is a ref to an array holding the file name, full
> path, atime, mtime.
>         #    Set a counter so I know how fast it's going
>         foreach (@files) {
>             $_ =~ m|^(.*)$pattern$|;
>             my $core = $1;
>             $filechars{$core} = [ $_, "$dir/$_", (stat($_))[8..9] ];
>             $count++;
>             if ($count % 100 == 0) { print 'count:  ', "$count\n";}
>         }
>         closedir DIR or die "Couldn't close $dir:  $!";
>         print "$dir HAS BEEN ANALYZED\n";
>         return \%filechars;
>     }
> 
> The counter prints to screen in 100-file increments.  The first couple of
> hundred files zip right by, but then the process slows to a crawl.  This
> occurred despite there being no other significant activity happening on this
> disk.  Why?

The stat() operation takes longer for files that are "late" in the
directory, in the sense that readdir() produces them late.  Since
your directory is oversized, the difference is significant.  Since
you process the files in the order in which they were found, the process
seems to slow down progressively.  To test the hypothesis, just change

    my @files = grep { m|$pattern$|o } readdir DIR;

in your code to

    my @files = reverse grep { m|$pattern$|o } readdir DIR;

and watch it start out slow and grow faster as it goes.  To gain speed,
spread the files out over more smaller directories.

Below is a cleaned-up version of analyze_dir().  It isn't any faster.

    sub analyze_dir {
        my ( $dir, $pattern) = @{ shift()}{ qw( dir pattern)};
        opendir my $d, $dir or die "Can't open dir $dir: $!";
        chdir $dir or die "Can't cd to $dir: $!";
        my (%filechars, $count);
        while ( defined( $_ = readdir $d) ) {
            die "boo" unless defined $_;
            next unless -f;
            next unless /($pattern)/;
            $filechars{ $1} = [ $_, "$dir/$_", (stat $_)[ 8 .. 9]];
            print "count: $count\n" if ++$count % 100 == 0;
        }

Anno


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

Date: Mon, 13 Oct 2003 19:38:10 +1000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: Why Is My Hash Assignment Taking So Long?
Message-Id: <3f8a7337$0$23595$5a62ac22@freenews.iinet.net.au>

James E Keenan wrote:

>         foreach (@files) {
>             $_ =~ m|^(.*)$pattern$|;
>             my $core = $1;
>             $filechars{$core} = [ $_, "$dir/$_", (stat($_))[8..9] ];
>             $count++;
>             if ($count % 100 == 0) { print 'count:  ', "$count\n";}
>         }

Can't really see the answer to your question, but it seems to me that 
you could readily play around with that loop in order to find out just 
which part of it is killing the show.

I would start by assigning to $filechars{$count} instead of 
$filechars{$core}. If that makes no difference comment out 'my $core = 
$1;' - then comment out the regex - then remove the stat() results from 
the array reference. Hopefully by then you will have found out where the 
time is going, and we can start pondering "why?" :-)

Hth.

Cheers,
Rob


-- 
To reply by email u have to take out the u in kalinaubears.



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

Date: Mon, 13 Oct 2003 11:09:40 GMT
From: "Bob Dubery" <megapode@hotmail.com>
Subject: Wierdness with code to display file creation date
Message-Id: <3f8a87f3.18f4.16838@opus.randori.com>

Hi,

Environment is SuSE, apache 2.0, Perl 5.008

My code looks like this

# get and print date last modified for the required file...
# get date/time modified in epoch seconds...
$lastModified = (stat($fname))[9];

# convert to GMT...
@arr = gmtime($lastModified);

# day of week...
@temp = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
$theday = $temp[$arr[6]];

# date within month...
$thedate = $arr[3];
$lastModified = length($thedate);
if($lastModified eq 1){
	$thedate = '0'.$thedate;
}

# month...
@temp =
('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct'
,'Nov','Dec');
$themonth = $temp[$arr[4]];

# year
$theyear = $arr[5] + 1900;

$output = 'Last-Modified: '.$theday.', '.$thedate.',
'.$themonth;
$output = $output.' '.$theyear.' ';

The idea is to get the file creation date and use that to
generate the Last-Modified header.

When I test the script the output is
Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT
Irrespective of the actual date and time of creation.

But if I put print statements in my code to aid debugging...
# get and print date last modified for the required file...
# get date/time modified in epoch seconds...
$lastModified = (stat($fname))[9];

# convert to GMT...
@arr = gmtime($lastModified);
print "\n...@arr...\n";
THEN the lastModified header starts displaying correctly.

What's going on here. Why does displaying that array before
I start processing it's individual elements to build up the
RFC format date actually make a difference to the
calculation of the date?


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

Date: 13 Oct 2003 11:38:47 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Wierdness with code to display file creation date
Message-Id: <bme2s7$lel$1@mamenchi.zrz.TU-Berlin.DE>

Bob Dubery <megapode@hotmail.com> wrote in comp.lang.perl.misc:
> Hi,
> 
> Environment is SuSE, apache 2.0, Perl 5.008
> 
> My code looks like this

No strict and no warnings.  Switch them on.  At least when your code
is giving you trouble, its time to activate warnings and strictures.
Do that *before* you post to the group.  It may clear things up,
it very likely would have in this case.

> # get and print date last modified for the required file...
> # get date/time modified in epoch seconds...
> $lastModified = (stat($fname))[9];

Always check system calls for success.  I believe the stat() call failed
when you saw your strange results.

> # convert to GMT...
> @arr = gmtime($lastModified);

Don't convert the date manually (and clumsily).  There are modules to
do that.  Practically every module with "date" or "time" in its name
does.

> # day of week...
> @temp = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
> $theday = $temp[$arr[6]];
> 
> # date within month...
> $thedate = $arr[3];
> $lastModified = length($thedate);

Haphazard re-use of a variable.  If you need to keep the length somewhere
(you don't) use a dedicated variable for that, not a variable that was
meant for an entirely different purpose.

> if($lastModified eq 1){
> 	$thedate = '0'.$thedate;
> }

Use sprintf to format numbers.

> # month...
> @temp =
> ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct'
> ,'Nov','Dec');
> $themonth = $temp[$arr[4]];
> 
> # year
> $theyear = $arr[5] + 1900;
> 
> $output = 'Last-Modified: '.$theday.', '.$thedate.',
> '.$themonth;
> $output = $output.' '.$theyear.' ';
> 
> The idea is to get the file creation date and use that to
> generate the Last-Modified header.
> 
> When I test the script the output is
> Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT
> Irrespective of the actual date and time of creation.

That is consistent with a failed call to stat().  That would give
you an undefined value in 

> But if I put print statements in my code to aid debugging...
> # get and print date last modified for the required file...
> # get date/time modified in epoch seconds...
> $lastModified = (stat($fname))[9];
> 
> # convert to GMT...
> @arr = gmtime($lastModified);
> print "\n...@arr...\n";
> THEN the lastModified header starts displaying correctly.

I suppose the file you wanted to stat existed in one case and didn't
in the other.

> What's going on here. Why does displaying that array before
> I start processing it's individual elements to build up the
> RFC format date actually make a difference to the
> calculation of the date?

It doesn't.  You must be mis-interpreting your results.

Oh, and Unix doesn't keep a creation date for files.  It is always
the last-modified date you are working with.

Anno


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

Date: Mon, 13 Oct 2003 12:41:37 GMT
From: "Bob Dubery" <megapode@hotmail.com>
Subject: Re: Wierdness with code to display file creation date
Message-Id: <3f8a9d80.309f.16838@opus.randori.com>

> Bob Dubery <megapode@hotmail.com> wrote in
> > comp.lang.perl.misc: Hi,
> >
> > Environment is SuSE, apache 2.0, Perl 5.008
> >
> > My code looks like this
>
> No strict and no warnings.  Switch them on.  At least when
> your code is giving you trouble, its time to activate
> warnings and strictures. Do that *before* you post to the
> group.  It may clear things up, it very likely would have
> in this case.
Well it certainly just highlighted a LOT of problems. Lesson
learned.

<snip>
> > But if I put print statements in my code to aid
> > debugging... # get and print date last modified for the
> > required file... # get date/time modified in epoch
> > seconds... $lastModified = (stat($fname))[9];
> >
> > # convert to GMT...
> > @arr = gmtime($lastModified);
> > print "\n...@arr...\n";
> > THEN the lastModified header starts displaying
> correctly.
> I suppose the file you wanted to stat existed in one case
> and didn't in the other.
No. It was the same file. I tried this several times with
that extra line in use or commented out. As soon as the line
is executed everything else starts behaving itself. It's
almost as if there's some wierd kind of buffering thing
going on so that program jumps straight past the gmtime and
proceeds to work with an empty hash.

Funnily enough this all works, I was told and have
confirmed, under SCO and Cern.

But I'll work through the messages that strict provided and
see if that sheds some light on something.

Thanks


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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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.  

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


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