[19420] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1615 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 26 03:05:31 2001

Date: Sun, 26 Aug 2001 00:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <998809510-v10-i1615@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 26 Aug 2001     Volume: 10 Number: 1615

Today's topics:
    Re: $1 as subroutine parameter - problems <goldbb2@earthlink.net>
    Re: $r->mtime not working on Windows NT Apache 1.3.20 a <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Check subroutine data from other process <goldbb2@earthlink.net>
    Re: dynamic menu (efficiency) <pne-news-20010826@newton.digitalspace.net>
    Re: Extract the relative sorting of items from multiple (Steven Smolinski)
    Re: Help w/grep <goldbb2@earthlink.net>
        How to copy MID, GIF, JPEG files correctly? <satnic@home.com>
    Re: How to copy MID, GIF, JPEG files correctly? (Martien Verbruggen)
    Re: How to copy MID, GIF, JPEG files correctly? <pne-news-20010826@newton.digitalspace.net>
    Re: How to copy MID, GIF, JPEG files correctly? <satnic@home.com>
    Re: localtime() - returns the wrong year! <pne-news-20010826@newton.digitalspace.net>
    Re: one character at a time <goldbb2@earthlink.net>
    Re: Openning a file <pne-news-20010826@newton.digitalspace.net>
    Re: Openning a file <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Openning a file (Martien Verbruggen)
    Re: pl or not pl, that is the question <pne-news-20010826@newton.digitalspace.net>
    Re: Question about GD <barna@megapage.ch>
    Re: Question about GD (Martien Verbruggen)
        random link from web page (confused)
    Re: Read/write specific line of file <pne-news-20010826@newton.digitalspace.net>
        read <dscarlett@optushome.com.au>
    Re: read <godzilla@stomp.stomp.tokyo>
    Re: read <dscarlett@optushome.com.au>
    Re: read <dscarlett@optushome.com.au>
    Re: read <dscarlett@optushome.com.au>
    Re: read (Martien Verbruggen)
    Re: read <dscarlett@optushome.com.au>
    Re: Self-Searchable Perl documention - Extremely Useful <pne-news-20010826@newton.digitalspace.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 26 Aug 2001 02:01:44 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: $1 as subroutine parameter - problems
Message-Id: <3B8890C8.F3546883@earthlink.net>

Markus Laire wrote:
[snip]
> # print first 3 letters of given argument
> sub test($) {
>   $_[0] =~ /(...)/;
>   print "Begin: $1 of $_[0]\n";
> }

Solution:
sub test($) {
	print "Begin: ", substr($_[0], 0, 3), " of $_[0]\n";
}

-- 
I'm not a programmer but I play one on TV...


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

Date: Sun, 26 Aug 2001 08:13:07 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: $r->mtime not working on Windows NT Apache 1.3.20 and mod-perl 1.26
Message-Id: <3B889373.9070809@post.rwth-aachen.de>

Benjamin Goldberg wrote:

> What's in $r ?

In Mason, $r always is the mod_perl request object. You can retrieve 
most relevant information from that, such as $r->uri (URI of 
http-request) etc. Mason defines one other request object, namely its 
own one $m.

Tassilo
-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



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

Date: Sun, 26 Aug 2001 02:58:08 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Check subroutine data from other process
Message-Id: <3B889E00.7574BAA1@earthlink.net>

Mirek Rewak wrote:
> 
> Hi,
> At first: sorry for that stupid subject...
> 
> How to solve this problem: I've got a subrountine which loops a long
> time (exactly Mail::Bulkmail::bulkmail) and I want check from other
> process status of this operation (counter, to check how many posts
> have been sent so far) while it is executing.

Unless you're changing the source code of Mail/Bulkmail.pm, then you
can't do it.  What I *think* you want to do, is write your own
bulkmailer, based on Mail::Bulkmail::bulkmail(), which will provide it's
status to other processes.

First off, I'll assume you're *not* mimicing the use_envelope behavior
of bulkmail, simply because if you were, it would be so durned fast that
you wouldn't need to bother providing the status to other processes.  
Second, I'm going to assume you're using some kind of mail merge thing,
simply because if you're not merging, then there's no reason not to do
bulkmail with use_envelope.

Third, I'll assume that you're getting the names from a database, not
for any real reason except that it makes my code easier.

use DBI;
use Net::SMTP;
use Fcntl qw(:flock);

my @FAQ = do {
	open( my $faq, "<", "faq" ) or die ...;
	<$faq>;
};
my $dbi = DBI->connect( ..., {RaiseError=>1} );
my $sth = DBI->prepare( q[
	SELECT realname, email
	FROM users
	WHERE newuser = 1
] );

$sth->execute;

my $smtp = SMTP->new( ... ) or die ...;

open( my $lockfile, ">", "progress.$$" ) or die ...;
select( (select($lockfile), $|=1)[0] );

my $watchers;

my $count = 0;
do {
	seek( $lockfile, 0, 0 );
	flock( $lockfile, LOCK_EX ) or die ...;
	print $lockfile $count++ or die ...;
	flock( $lockfile, LOCK_UN ) or die ...;

	if( $watchers or open($watchers, "<+", "meetings.$$") ) {
		local $/;
		flock( $watchers, LOCK_SH ) or die ...;
		kill "USER1", unpack "i*", <$watchers>;
		flock( $watchers, LOCK_UN ) or die ...;
	}

	my $hash = $sth->fetchrow_hashref or last;
	$smtp->mail( ... ); # sender's address
	$smtp->to( $hash->{email} );
	$smtp->data( [<<HEADER,
To: "$hash->{realname}" <$hash->{email}>
From: "Mailinglist admin" <maillist-admin@example.com>
Subject: $something_from_ARGV

Hello $hash->{realname}, and welcome to our mailinglist.

Here's the rules:
HEADER
	@FAQ ] );
	$dbi->do( q[
		UPDATE users
		SET newuser = 0
		WHERE realname = ? AND email = ?
	], undef, @$hash{qw(realname email)} );
}

flock( $lockfile, LOCK_EX ) or die ...;
print $lockfile -1 or die ...;
close $lockfile or die ...;

if( $watchers or open($watchers, "<+", "meetings.$$") ) {
	local $/;
	flock( $watchers, LOCK_SH ) or die ...;
	kill "USER1", unpack "i*", <$watchers>;
	flock( $watchers, LOCK_UN ) or die ...;
}

__END__

The people who want to watch can learn when a message has been sent by
listening to SIGUSER1.

-- 
I'm not a programmer but I play one on TV...


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

Date: Sun, 26 Aug 2001 08:27:23 +0200
From: Philip Newton <pne-news-20010826@newton.digitalspace.net>
Subject: Re: dynamic menu (efficiency)
Message-Id: <c45hotc44qr1nvjnv7gmc2spa62q00nuo0@4ax.com>

On Thu, 23 Aug 2001 22:31:54 -0000, four12and8up@unspam-me.yahoo.com
wrote:

> I like how you layed out the stack; It would be easier to use/truncate:
> 
> @match = $match[0]..$match[n]; #truncate back to position n on the line.

I don't think that does what you think it does. If $match[0] is
'Michigan' and $match[n] is 'Missouri', then @match will end up with not
four elements ('Michigan', 'Minnesota', 'Mississippi', 'Missouri'), but
thousands of elements ('Michigan', 'Michigao', 'Michigap', ...,
'Michigaz', 'Michigba', ..., 'Missourh', 'Missouri').

You could use

    @match = @match[0..$n]

, but splice is probably better:

    splice @match, $n+1;

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Sun, 26 Aug 2001 04:33:54 GMT
From: steven.smolinski@sympatico.ca (Steven Smolinski)
Subject: Re: Extract the relative sorting of items from multiple lists
Message-Id: <S__h7.62610$wX5.4893352@news20.bellglobal.com>

Abigail <abigail@foad.org> wrote:
> David Combs (dkcombs@panix.com) wrote on MMCMXVI September MCMXCIII in
><URL:news:9m7oe0$h0v$1@news.panix.com>:
> ,, In article <3B76147C.1FBD0B8B@acm.org>, John W. Krahn <krahnj@acm.org> wrote:
> ,, >
> ,, >Get the first section of volume four here:
> ,, >
> ,, >http://Sunburn.Stanford.EDU/~knuth/fasc2a.ps.gz
> ,, >
> ,, 
> ,, THANK YOU!
> ,, 
> ,, How did you know this even existed -- unless
> ,, you are *at* Stanford?
> 
> 
> Knuth has been working at Stanford for decades. He has had a website
> for eons. He has announced his plans for Volume 4 and how he will make
> it available for at least 5 years on his website.

Plus, for those of us peripherally interested, there was a story on 
slashdot. ;-)

Steve
-- 
Steven Smolinski => http://arbiter.ca/


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

Date: Sun, 26 Aug 2001 01:56:11 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Help w/grep
Message-Id: <3B888F7B.5EF9F946@earthlink.net>

jlm wrote:
> 
> I wrote a search engine in perl/cgi for our web site that searches for
> files containing user supplied text string.
> @farr = `find $dir -type f -exec grep -il $text {} \\;`;
> I then proces the array constructing url's as I go & write out new web
> page. Works great.
> Now management wants the ability to optionally specify two strings and
> return results only if both strings appear in a file.
> I can't seem to figure out how to manipulate grep to do that.

Well, if you insist on using find, then either:
	@farr = qx[find $dir -type f \
		-exec grep -iq $texta {} \; \
		-exec grep -il $textb {} \; \
	];
[note the q instead of l] or:
	@farr = qx[find $dir -type f |
		xargs grep -il $texta {} |
		xargs grep -il $textb {}
	];
Note that the first runs two grep process es on each and every filename,
whereas the second groups the filenames as many as it can fit on a
commandline.

> Can someone solve this problem?
> Or maybe the perl grep function can do the job better?

Using perl to do the grep would likely be faster.

#!/usr/bin/perl -w
use File::Find;
use strict;

die "Usage: $0 pattern pattern [dirs]\n" unless @ARGV >= 2;

my ($pat1, $pat2) = map qr/$_/, splice(@ARGV, 0, 2);

@ARGV ||= (".");

find sub {
	-f && -r _ && open(my $fh, "<", $_) or return;
	my ($got1, $got2);
	while( <$fh> ) {
		$got1 ||= /$pat1/; $got2 ||= /$pat2/;
		return print $File::Find::name, "\n";
			if( $got1 && $got2 );
	}
}, @ARGV;

__END__

If you omit the list of directories, it will default to the current
directory.  You can't omit the two patterns.  Invoke it like:

myfind2patterns '(?i)foobaz' 'barqux' /home/me/mydir

Note that unless you include (?i) at the beginning, it's not going to be
case insensitive.  If you *want* it to be case insensitive by default,
add it as a flag to qr ... that is, replace qr/$_/ with qr/$_/i for case
insensitivity by default.

-- 
I'm not a programmer but I play one on TV...


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

Date: Sun, 26 Aug 2001 04:29:54 GMT
From: Zoom Zoom Zoom <satnic@home.com>
Subject: How to copy MID, GIF, JPEG files correctly?
Message-Id: <3B887B61.9050301@home.com>

Hi -

I am using following code to create a new copy of existing *.mp3, *.mid 
  or *.gif files. The files are created successfully with the size same 
as the original ones. However I can't play these  newly created copies 
using MusicMatch or Windows Media Player.  For image files, I can't open 
them in browser or any other graphic editor. All the images appear to be 
distorted.

However same thing works for *.WAV or plain ascii text files.

Do you know what I am missing? Is there some special processing that I 
have to do for mp3 or mid formats?

   open(OUTFILE,">>$output_file") || die "Can't open $output_file  file";
   while(read($filename,$buffer,1024)) {
        print OUTFILE $buffer;
   }
   close $output_file ;

PS: I am using ActiveState Perl 5.6.1 on Win2K server.

Thanks,

- Zoom



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

Date: Sun, 26 Aug 2001 16:03:34 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: How to copy MID, GIF, JPEG files correctly?
Message-Id: <slrn9oh49m.3ga.mgjv@martien.heliotrope.home>

On Sun, 26 Aug 2001 04:29:54 GMT,
	Zoom Zoom Zoom <satnic@home.com> wrote:
> Hi -
> 
> I am using following code to create a new copy of existing *.mp3, *.mid 
>   or *.gif files. The files are created successfully with the size same 
> as the original ones. However I can't play these  newly created copies 
> using MusicMatch or Windows Media Player.  For image files, I can't open 
> them in browser or any other graphic editor. All the images appear to be 
> distorted.
> 
> However same thing works for *.WAV or plain ascii text files.

If it works for Windows wave files, you've just been lucky, until now.
Just wait until you get one that contains a ctrl-Z or a sequence of
carriage return and linefeed.

> Do you know what I am missing? Is there some special processing that I 
> have to do for mp3 or mid formats?

No. There is something you need to do with the file handle for any
binary data, i.e. anything that is not just a text file.

>    open(OUTFILE,">>$output_file") || die "Can't open $output_file  file";

binmode(OUTFILE);
# And make sure the file handle you read from is also in binary mode!

>    while(read($filename,$buffer,1024)) {
>         print OUTFILE $buffer;
>    }
>    close $output_file ;
> 
> PS: I am using ActiveState Perl 5.6.1 on Win2K server.

And that is EXACTLY one of the platforms where binmode() is important. 

Please, read the documentation for binmode(), and memorise its
existence.

$ perldoc -f binmode

In short: ALWAYS use binmode when you're reading or writing binary data,
regardless of platform. NEVER use binmode when you're reading text,
regardless of platform.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | If at first you don't succeed, try
Commercial Dynamics Pty. Ltd.   | again. Then quit; there's no use
NSW, Australia                  | being a damn fool about it.


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

Date: Sun, 26 Aug 2001 08:29:34 +0200
From: Philip Newton <pne-news-20010826@newton.digitalspace.net>
Subject: Re: How to copy MID, GIF, JPEG files correctly?
Message-Id: <4n5hotko8i8t42nu28agd1e046ua2st0nf@4ax.com>

On Sun, 26 Aug 2001 04:29:54 GMT, Zoom Zoom Zoom <satnic@home.com>
wrote:

> Do you know what I am missing? Is there some special processing that I 
> have to do for mp3 or mid formats?

binmode -- but you should use that for all files on Win32 if you want an
exact copy.

But that wheel has already been invented, and it's called File::Copy.

>    open(OUTFILE,">>$output_file") || die "Can't open $output_file  file";

And why couldn't you open the file? $! would have told you, if you'd
printed it out in the error message.

>    while(read($filename,$buffer,1024)) {
>         print OUTFILE $buffer;
>    }
>    close $output_file ;

read and close work on file *handles*, not file *names*.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Sun, 26 Aug 2001 06:46:26 GMT
From: Zoom Zoom Zoom <satnic@home.com>
Subject: Re: How to copy MID, GIF, JPEG files correctly?
Message-Id: <3B889B61.9010101@home.com>

Philip and Martien -

You both are right. binmode did the trick. Thanks for letting me know. 
Also, yes, I should have closed OUTFILE; not the filename!!

Thanks again,

- Zoom

Zoom Zoom Zoom wrote:

> Hi -
> 
> I am using following code to create a new copy of existing *.mp3, *.mid 
>  or *.gif files. The files are created successfully with the size same 
> as the original ones. However I can't play these  newly created copies 
> using MusicMatch or Windows Media Player.  For image files, I can't open 
> them in browser or any other graphic editor. All the images appear to be 
> distorted.
> 
> However same thing works for *.WAV or plain ascii text files.
> 
> Do you know what I am missing? Is there some special processing that I 
> have to do for mp3 or mid formats?
> 
>   open(OUTFILE,">>$output_file") || die "Can't open $output_file  file";
>   while(read($filename,$buffer,1024)) {
>        print OUTFILE $buffer;
>   }
>   close $output_file ;
> 
> PS: I am using ActiveState Perl 5.6.1 on Win2K server.
> 
> Thanks,
> 
> - Zoom
> 



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

Date: Sun, 26 Aug 2001 07:35:29 +0200
From: Philip Newton <pne-news-20010826@newton.digitalspace.net>
Subject: Re: localtime() - returns the wrong year!
Message-Id: <ak2hotc8l01nblar61pvfr69nl0qkgb6lf@4ax.com>

On Sat, 25 Aug 2001 06:09:13 GMT, "Rob - Rock13.com" <rob_13@excite.com>
wrote:

> although this method won't pad the month or day with a zero.

Which is what sprintf is for.

You even get to pick between '%.2d' and '%02d'.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Sun, 26 Aug 2001 01:59:09 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: one character at a time
Message-Id: <3B88902D.8A13779B@earthlink.net>

Yves Orton wrote:
[snip]
> > Yves Orton wrote:
> >
> > > Benjamin Goldberg wrote:
> > > > Ken wrote:
> > > > my $string = "my little string";
> > > > while( /(.)/gs ) {
> > > >       print $1, "\n";
> > > > }
> > > print $1."\n" while ($string=~/(.)/gs );
[snip]
> BTW  I didnt post the code cause I thought it was efficient, I posted
> it cause it fixed a minor bug in Bens code...  Did you spot it?

D'oh!  I forgot to bind the pattern to $string.  Boy do I feel dumb :)

-- 
I'm not a programmer but I play one on TV...


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

Date: Sun, 26 Aug 2001 07:30:30 +0200
From: Philip Newton <pne-news-20010826@newton.digitalspace.net>
Subject: Re: Openning a file
Message-Id: <452hotkah4ug67q8s8dfm558hrkdtltjck@4ax.com>

On Sun, 26 Aug 2001 00:44:07 +0200, Tassilo von Parseval
<Tassilo.Parseval@post.rwth-aachen.de> wrote:

> [lists allegedly in scalar context]
> 
> Well, there was this qw() example. You can assign that to a scalar 
> variable. This eventually assigns the last element of this list to this 
> variable.

In newer Perls, yes. In 5.005_03, it assigns the number of elements in
the list, and gives a warning about implicit split to @_ being
deprecated under -w.

> But, alas, I am no longer so sure about it whether one could 
> call this scalar context after flicking through some perldocs and doing 
> some quick tests.

AIUI, newer Perls translate qw(a b c) to ('a', 'b', 'c') [1], so $a =
qw(a b c) is the same as $a = ('a', 'b', 'c'). Comma operator in scalar
context: L<perlop/Comma Operator>. But I supposed that's what you found
when you "flicked through some perldocs".

Cheers,
Philip

[1] older Perls translated it to something like split(' ', 'a b c')
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Sun, 26 Aug 2001 08:04:09 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Openning a file
Message-Id: <3B889159.4090504@post.rwth-aachen.de>

Philip Newton wrote:

> AIUI, newer Perls translate qw(a b c) to ('a', 'b', 'c') [1], so $a =
> qw(a b c) is the same as $a = ('a', 'b', 'c'). Comma operator in scalar
> context: L<perlop/Comma Operator>. But I supposed that's what you found
> when you "flicked through some perldocs".

Yes, exactly. And Anno gave me an example where the first value is 
evaluated and then thrown away. Till Perl, I never considered  the comma 
an operator. For me it was just something to split arguments of 
function-calls in C.

Tassilo
-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



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

Date: Sun, 26 Aug 2001 16:16:10 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Openning a file
Message-Id: <slrn9oh51a.3ga.mgjv@martien.heliotrope.home>

On Sun, 26 Aug 2001 08:04:09 +0200,
	Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
> Philip Newton wrote:
> 
>> AIUI, newer Perls translate qw(a b c) to ('a', 'b', 'c') [1], so $a =
>> qw(a b c) is the same as $a = ('a', 'b', 'c'). Comma operator in scalar
>> context: L<perlop/Comma Operator>. But I supposed that's what you found
>> when you "flicked through some perldocs".
> 
> Yes, exactly. And Anno gave me an example where the first value is 
> evaluated and then thrown away. Till Perl, I never considered  the comma 
> an operator. For me it was just something to split arguments of 
> function-calls in C.

In C, the comma is firmly established as an operator as well.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Freudian slip: when you say one thing
Commercial Dynamics Pty. Ltd.   | but mean your mother.
NSW, Australia                  | 


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

Date: Sun, 26 Aug 2001 08:11:02 +0200
From: Philip Newton <pne-news-20010826@newton.digitalspace.net>
Subject: Re: pl or not pl, that is the question
Message-Id: <cl4hot8mvoucsbebho9trj2c5akidturdm@4ax.com>

On Sat, 25 Aug 2001 16:26:18 GMT, "--Rick" <no_trick@my-de(remove the
obvious)ja.com> wrote:

> Hmm...  I'm grinding my way through a book that suggests the extension
> (.plx).  ;)

I've seen that suggestion, too. For example, Tom Phoenix's Inside script
assumes that *.pl are Perl Library files of the type that used to be
used with Perl4 & require'd, and also suggests using *.plx for Perl
Executable files (stand-alone scripts) if you do use an extension.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Sun, 26 Aug 2001 06:47:23 +0200
From: Bernhard Schelling <barna@megapage.ch>
Subject: Re: Question about GD
Message-Id: <3B887F5B.D0F20E34@megapage.ch>

Here are some results from the benchmark:

With multiple PNG files:
1 wallclock secs ( 0.17 usr +  0.00 sys =  0.17 CPU)
0 wallclock secs ( 0.16 usr +  0.00 sys =  0.16 CPU)
0 wallclock secs ( 0.16 usr +  0.00 sys =  0.16 CPU)
0 wallclock secs ( 0.16 usr +  0.00 sys =  0.16 CPU)

With one GD2 file and newFromGd2Part:
1 wallclock secs ( 0.16 usr +  0.00 sys =  0.16 CPU)
0 wallclock secs ( 0.22 usr +  0.00 sys =  0.22 CPU)
1 wallclock secs ( 0.22 usr +  0.00 sys =  0.22 CPU)
0 wallclock secs ( 0.17 usr +  0.00 sys =  0.17 CPU)


There was a problem with newFromGd2Part. It just didn't load any palette data! I
had to create a palette.png which i loaded first, and then copy them together to
get colors. Maybe i should do colorAllocate 150 times... mmh maybe tomorrow, i
need sleep now :-)

About mod_perl, I played around with it last week. It just didn't like my code! I
checked the scripts with -w and use strict, but sometimes when I acessed a perl
script, it loaded the page correctly, and the next time I got old data, or even
data which retrieved another user!


Martien Verbruggen schrieb:

> On Sun, 26 Aug 2001 03:04:44 +0200,
>         Bernhard Schelling <barna@megapage.ch> wrote:
> > Thanks a lot for your answer, I will benchmark the GD2 version
> >
> > Some more information:
> > The big image is now 5896 x 5704, maybe it changes in some months or years,
> > but thats not important now...
> > The small clip can be anything from 50x50 to 300x300 and starts at any pixel
> > coordinate in the big image.
>
> Then I'd go with having one large file, and serving subsets dynamically,
> unless, of course, that turns out to be too slow. my gut feeling says
> that it'll perform ok on any decent hardware. prerendering all the
> possible images for that would be a bit much, I guess.
>
> When benchmarking, try to write the benchmarks in such a way so that you
> can see what takes long: the loading of the image or the cutting it up.
> If you use newFromGD2Part, I suspect that the loading time is going to be
> close to proportional to the number of pixels you need to load. For the
> other methods it'll be proportional to the number of pixels in the whole
> source image.
>
> > Now I have 16 files (each 1474x1426), and i load just the needed
> > files, so it loads 4 files in the worst case. Its faster than one
> > file, but I hope to get it faster. Maybe I should slice it up into
> > 300x300 pieces, so it still needs 4 files in the worst case...
>
> I don't believe that you would need to split the file up if you use
> newFromGd2Part(). I haven't actually looked at Boutell's code, but I
> doubt it would read anything in a file that it didn't need.
>
> One other alternative, which I didn't think of before, is to use some
> mechanism that allows you to only load the images once, and keep them in
> memory. mod_perl might be able to help you in a trivial way. I don't
> know that much about mod_perl, so I can't say for certain whether that
> would be a solution. A benchmark that shows how much time is taken by
> loading an image, and how much by using copy() to get a part from it
> would tell you how much you can gain by avoiding the load phase.
>
> Otherwise you could do something with a server process and shared
> memory, maybe. Overheads introduced here could be larger than gains, and
> the programming effort will most likely be quite substantial, although
> with some well-chosen modules from CPAN it may be ok.
>
> Martien
> --
> Martien Verbruggen              |
> Interactive Media Division      | That's funny, that plane's dustin'
> Commercial Dynamics Pty. Ltd.   | crops where there ain't no crops.
> NSW, Australia                  |



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

Date: Sun, 26 Aug 2001 15:57:34 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Question about GD
Message-Id: <slrn9oh3ue.3ga.mgjv@martien.heliotrope.home>

[Please, in the future, put your comments _after_ the suitably trimmed
text you reply to. It's the generally accepted quoting convention on
this newsgroup, and Usenet in general.]

On Sun, 26 Aug 2001 06:47:23 +0200,
	Bernhard Schelling <barna@megapage.ch> wrote:

[Post re-ordered, rewrapped and trimmed]

> Martien Verbruggen schrieb:
> 
>> On Sun, 26 Aug 2001 03:04:44 +0200,
>>         Bernhard Schelling <barna@megapage.ch> wrote:
>> > Thanks a lot for your answer, I will benchmark the GD2 version

[snip]

>> One other alternative, which I didn't think of before, is to use some
>> mechanism that allows you to only load the images once, and keep them in
>> memory. mod_perl might be able to help you in a trivial way. I don't
>> know that much about mod_perl, so I can't say for certain whether that
>> would be a solution. A benchmark that shows how much time is taken by
>> loading an image, and how much by using copy() to get a part from it
>> would tell you how much you can gain by avoiding the load phase.
>
> Here are some results from the benchmark:
> 
> With multiple PNG files:
> 1 wallclock secs ( 0.17 usr +  0.00 sys =  0.17 CPU)
> 0 wallclock secs ( 0.16 usr +  0.00 sys =  0.16 CPU)
> 0 wallclock secs ( 0.16 usr +  0.00 sys =  0.16 CPU)
> 0 wallclock secs ( 0.16 usr +  0.00 sys =  0.16 CPU)
> 
> With one GD2 file and newFromGd2Part:
> 1 wallclock secs ( 0.16 usr +  0.00 sys =  0.16 CPU)
> 0 wallclock secs ( 0.22 usr +  0.00 sys =  0.22 CPU)
> 1 wallclock secs ( 0.22 usr +  0.00 sys =  0.22 CPU)
> 0 wallclock secs ( 0.17 usr +  0.00 sys =  0.17 CPU)

Benchmarks don't mean much without the code that generated the
statistics. They also are less reliable if run for too short a time. All
of the examples above suffer from both deficiencies :)

> There was a problem with newFromGd2Part. It just didn't load any
> palette data! I had to create a palette.png which i loaded first, and
> then copy them together to get colors. Maybe i should do colorAllocate
> 150 times... mmh maybe tomorrow, i need sleep now :-)

You're right. I've never noticed this before. if you load a GD or GD2
format image file, the colour palette is uninitialised, or rather,
initialised incorrectly. Saving the image as an indexed PNG will result
in a (rather low level) error. However, savaing it as a JPEG image works
fine. The colorsTotal method returns 0, even though the palette has
obviously been populated. Looks like a bug to me. (GD 1.33 and libgd
1.8.3 [1]). I seem to recall that this used to work fine, a long time
ago, so I suspect it got introduced with all the PNG changes..

It's most likely a bug in the underlying libgd.

Martien

[1] because I can't be bothered to investigate why 1.8.4 cannot be
decently used to link together GD 1.33.
-- 
Martien Verbruggen              | 
Interactive Media Division      | 
Commercial Dynamics Pty. Ltd.   | Curiouser and curiouser, said Alice.
NSW, Australia                  | 


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

Date: 25 Aug 2001 23:07:08 -0700
From: thing2b@yahoo.com (confused)
Subject: random link from web page
Message-Id: <53a7a4f1.0108252207.3a716812@posting.google.com>

ok, i am using the code at the bottom of this message to get links
from a web page. How do i get it to return only 1 random link from the
page so every time you goto the cgi page, it will show a different
link ?

#!/usr/bin/perl -w

use strict;
use HTML::LinkExtor;
use LWP::Simple;

my %seen;
my $url =
"http://www.yahoo.com";
my $parser = HTML::LinkExtor->new(undef, $url);
$parser->parse(get($url))->eof;
my @links = $parser->links;
foreach my $linkarray (@links) {
    my @element = @$linkarray;
    my $elt_type = shift @element;
    while (@element) {
	my ($attr_name, $attr_value) = splice(@element, 0, 2);
	$seen{$attr_value}++;
    }
}

 print "Content-type: text/html\n\n";
for (sort keys %seen) { print $_, "\n" };


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

Date: Sun, 26 Aug 2001 08:15:49 +0200
From: Philip Newton <pne-news-20010826@newton.digitalspace.net>
Subject: Re: Read/write specific line of file
Message-Id: <0r4hots35m3cohcp6rttl9aej86c1m2d8m@4ax.com>

On 25 Aug 2001 10:37:43 -0700, mariorizzuti@yahoo.com (Mario Rizzuti)
wrote:

> Mantaining an index file has just a problem: when the length of a
> record changes, all the offsets of the records following need to be
> updated. This can be an huge task if the records are a lot.

Ah. I hadn't seen the "write an arbitrary line" bit, which is difficult
anyway if your lines are of variable length: you'd need to shift all the
lines following the one you wrote, which will take a long time anyway if
you have a large file and insert near the beginning.

Indexes are best for read-only files.

> What I miss is the "read until a \n".

    $line = <FH>;

should do so, and update the current position as well.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Sun, 26 Aug 2001 04:22:13 GMT
From: "David Scarlett" <dscarlett@optushome.com.au>
Subject: read
Message-Id: <VP_h7.22778$A5.69857@news1.eburwd1.vic.optushome.com.au>

Can anyone tell me if the read function affects the file pointer at all?

ie. Will the following code return the same thing three times, or 3
consecutive sections of the file?

seek(FILE,0,0);
read(FILE,$a,10);
read(FILE,$a,10);
read(FILE,$a,10);

 .... or would you read consecutive sections like this?:

seek(FILE,0,0);
read(FILE,$a,10);
seek(FILE,10,1);
read(FILE,$b,10);
seek(FILE,10,1);
read(FILE,$c,10);


TiA,
--
David Scarlett
dscarlett@optushome.com.au
http://www.listen.to/artifice/
http://members.optushome.com.au/dscarlett/

"...please, do not inflict Perl and BASIC upon innocent children."
        -'raj', comp.lang.functional, 05/05/2001




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

Date: Sat, 25 Aug 2001 21:32:24 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: read
Message-Id: <3B887BD8.8538222C@stomp.stomp.tokyo>

David Scarlett wrote:
 
> Can anyone tell me if the read function affects the file pointer at all?
 
> ie. Will the following code return the same thing three times, or 3
> consecutive sections of the file?
 
> seek(FILE,0,0);
> read(FILE,$a,10);
> read(FILE,$a,10);
> read(FILE,$a,10);
 
> .... or would you read consecutive sections like this?:
 
> seek(FILE,0,0);
> read(FILE,$a,10);
> seek(FILE,10,1);
> read(FILE,$b,10);
> seek(FILE,10,1);
> read(FILE,$c,10);


I am personally more curious what is your valid reason
for not simply testing this to discover an answer. You
are familiar with writing test scripts, yes?


Godzilla!


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

Date: Sun, 26 Aug 2001 04:59:01 GMT
From: "David Scarlett" <dscarlett@optushome.com.au>
Subject: Re: read
Message-Id: <pm%h7.22792$A5.69934@news1.eburwd1.vic.optushome.com.au>

"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message
news:3B887BD8.8538222C@stomp.stomp.tokyo...
>
> I am personally more curious what is your valid reason
> for not simply testing this to discover an answer.

The first of the three principal virtues of a programmer.


 ....but I suppose I could test it.... ;-)

--
David Scarlett
dscarlett@optushome.com.au
http://www.listen.to/artifice/
http://members.optushome.com.au/dscarlett/

"Look, coupons. I can get 2 oil changes for the price of 1! Now if I could
only afford the one......... and a car."
        -Dr Zoidberg, Futurama




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

Date: Sun, 26 Aug 2001 05:34:10 GMT
From: "David Scarlett" <dscarlett@optushome.com.au>
Subject: Re: read
Message-Id: <mT%h7.22802$A5.69994@news1.eburwd1.vic.optushome.com.au>

Ok, now I've tried testing it, and I have no idea what's going on.

Here's the test script:
---------------
#!/usr/bin/perl

use strict;

open(FILE,"+>test.dat");

my($i);
my($size) = length(pack("i"));

for ($i=0; $i<100; $i++) {
    print FILE pack("i",$i);
}

seek(FILE,0,0);

my($buf);
my($a) = read(FILE,$buf,$size);

while ($a == $size) {
    print unpack("i",$buf);
    print "\n";
    seek(FILE,$size,1);
    $a = read(FILE,$buf,$size);
}

close(FILE);
----------------

This outputs:
0
19456
19968
20480
20992
21504
22016
22528
23040
23552
24064
24576
25088

However, the test.dat file contains what was expected.........




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

Date: Sun, 26 Aug 2001 06:15:40 GMT
From: "David Scarlett" <dscarlett@optushome.com.au>
Subject: Re: read
Message-Id: <gu0i7.22814$A5.70073@news1.eburwd1.vic.optushome.com.au>

"David Scarlett" <dscarlett@optushome.com.au> wrote in message
news:mT%h7.22802$A5.69994@news1.eburwd1.vic.optushome.com.au...
> 0
> 19456
> 19968
> 20480
> 20992
> 21504
> 22016
> 22528
> 23040
> 23552
> 24064
> 24576
> 25088

I just read the next newest thread ("How to copy MID, GIF, JPEG files
correctly?") and I tried adding a binmode(FILE) line, now it works!

And it seems that read _does_ skip forwards through the file.


--
David Scarlett
dscarlett@optushome.com.au
http://www.listen.to/artifice/
http://members.optushome.com.au/dscarlett/

"Damn it, Kif, where's the little umbrella? That's what makes it a scotch on
the rocks!"
        -Capt. Zapp Brannigann, Futurama




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

Date: Sun, 26 Aug 2001 16:14:42 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: read
Message-Id: <slrn9oh4uh.3ga.mgjv@martien.heliotrope.home>

On Sun, 26 Aug 2001 05:34:10 GMT,
	David Scarlett <dscarlett@optushome.com.au> wrote:
> Ok, now I've tried testing it, and I have no idea what's going on.
> 
> Here's the test script:
> ---------------
> #!/usr/bin/perl

No -w?

What if Perl had been trying to tell you something? You would have just
missed it. In this case that's not the case, but still....

> use strict;

# To make your code more readable:

use Fcntl qw(:seek);

> open(FILE,"+>test.dat");

You should check for success. You should also follow this with a
binmode(), since you're not working with textual data.

binmode(FILE);

> my($i);
> my($size) = length(pack("i"));
> 
> for ($i=0; $i<100; $i++) {
>     print FILE pack("i",$i);
> }

no need for all those parens.

my $size = length pack "i";

for (my $i....

> seek(FILE,0,0);

You really should use SEEK_SET here (see the Fcntl import).

> my($buf);
> my($a) = read(FILE,$buf,$size);

see above.

> while ($a == $size) {
>     print unpack("i",$buf);
>     print "\n";
>     seek(FILE,$size,1);

And SEEK_CUR here.

>     $a = read(FILE,$buf,$size);
> }
> 
> close(FILE);
> ----------------
> 
> This outputs:

[snip output]

Not for me. For me it prints the even integers from 0 to 98, inclusive,
which is what I'd expect, and it does that even before fixing the stuff
I talked about above. 

> However, the test.dat file contains what was expected.........

Are you, by any chance, on a platform that has its origins in DOS or
VMS? 

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Freudian slip: when you say one thing
Commercial Dynamics Pty. Ltd.   | but mean your mother.
NSW, Australia                  | 


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

Date: Sun, 26 Aug 2001 06:29:08 GMT
From: "David Scarlett" <dscarlett@optushome.com.au>
Subject: Re: read
Message-Id: <UG0i7.22818$A5.70103@news1.eburwd1.vic.optushome.com.au>

"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn9oh4uh.3ga.mgjv@martien.heliotrope.home...
>
> Are you, by any chance, on a platform that has its origins in DOS or
> VMS?

Yep, Win2K ;-)

I'd be using IRIX, but I can't telnet into uni ATM......

Thanks for the answer.. :-)


--
David Scarlett
dscarlett@optushome.com.au
http://www.listen.to/artifice/
http://members.optushome.com.au/dscarlett/

"Damn it, Kif, where's the little umbrella? That's what makes it a scotch on
the rocks!"
        -Capt. Zapp Brannigann, Futurama




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

Date: Sun, 26 Aug 2001 07:22:05 +0200
From: Philip Newton <pne-news-20010826@newton.digitalspace.net>
Subject: Re: Self-Searchable Perl documention - Extremely Useful!
Message-Id: <qq1hot08j36l7374fo1ggam7g3fmfa9cb2@4ax.com>

On 25 Aug 2001 08:43:46 -0700, demerphq@hotmail.com (Yves Orton) wrote:

> dkcombs@panix.com (David Combs) wrote in message news:<9ll790$fvi$2@news.panix.com>...
> >
> > How about posting it here so everyone can see it too.
> 
> im not sure the usenet is the place to post a 600line script.

So put it on the web and post the URL. That's what people usually do for
longer things -- even for, say, long code samples.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

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


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