[19252] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1447 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 5 18:05:30 2001

Date: Sun, 5 Aug 2001 15:05:06 -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: <997049106-v10-i1447@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 5 Aug 2001     Volume: 10 Number: 1447

Today's topics:
    Re: ActiveState Perl <-> Cygwin perl and newlines... <bcaligari@fireforged.com>
    Re: Baiting Gozilla to obtain quality code for nothing! <Dave.Stafford@globis.net>
        Bijeenkomst Amsterdam Perl Mongers, Dinsdag 7 augustus  (Johan Vromans)
    Re: calling a perl script from perl (Kate T. Porter)
    Re: Can you read email on an Exchange server with perl  <beyondcontrol@runbox.com>
    Re: Can you read email on an Exchange server with perl  <bcaligari@fireforged.com>
    Re: CGI.pm file upload problem - Please Help! <krahnj@acm.org>
        FAQ: How do I sort a hash (optionally by value instead  <faq@denver.pm.org>
        File::Find : cannot figure it out. <Koen@invalidmiddle-earth.be>
    Re: File::Find : cannot figure it out. (Logan Shaw)
    Re: File::Find : cannot figure it out. (Tad McClellan)
    Re: File::Find : short example and notes <dan@nospam_dtbakerprojects.com>
    Re: Having some trouble with map <iltzu@sci.invalid>
    Re: How to print a binary string as picture to web page <goldbb2@earthlink.net>
    Re: negative lookahead <goldbb2@earthlink.net>
    Re: perl regular expression grammar <iltzu@sci.invalid>
    Re: prompting and redirection with ssh (David Efflandt)
    Re: string extraction (Eric Bohlman)
    Re: two questions <goldbb2@earthlink.net>
    Re: using eval (Ken)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 5 Aug 2001 17:32:07 -0000
From: "B. Caligari" <bcaligari@fireforged.com>
Subject: Re: ActiveState Perl <-> Cygwin perl and newlines...
Message-Id: <9kjok6010is@enews1.newsguy.com>


"nobody" <nobody@nobody.com> wrote in message
news:31db7.12265$Xf2.325959@amsnews03.chello.com...

> >> Is there a simple setting that makes cygwin behave like
> >> activeperl, without doing many changes in the code?
> >>
> >
> > are you running perl under cygwin from a cygwin shell or straight from a
> > console window?
> >
> > B.
> >
> >
> >
>
> Straigt from a console window.
>

I'm pretty sure your script will work as expected if you run from
a cygwin shell.

As in unix, the cygwin shell recognises a character '0A' as end of
line, whereas in the the windows console the end of line marker
is '0D 0A'.

I guess you could try using "\015\012" instead of "\n" in your print
strings (or just use the ActiveState build, or upgrade to unix :-).

B





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

Date: Sun, 05 Aug 2001 12:53:04 GMT
From: "Dave Stafford" <Dave.Stafford@globis.net>
Subject: Re: Baiting Gozilla to obtain quality code for nothing!!
Message-Id: <Qkbb7.344055$XL1.5838870@nlnews00.chello.com>

"Walnut" <walnut@froggy.com.au> wrote in message

> 3. Deliberately make such huge errors that, lo and behold, Gozilla!
> will feel a deep urge and burning obligation to spend oodles of time
> going through his/her personal library and O'Reilly books to provide
> the exact code you require - at the drop of a hat.

Only if his mum allows him to before dinner and homework. Still you can see
why he's a bit screwed up, I mean imagine calling your kid Godzilla!

Oh, and let's face it: he's a he, no woman is that sad.

However, whilst his social skills are somewhat lacking, I do enjoy his
sentence constructions which are most amusing (albeit accidentally so).
Perhaps we can start a "my favourite Godzilla-isms" list. My recent fav is:

"your repeated attempts at censorious censure"

I imagine him saying it as Biggus Dickus would in the Life of Brian. (Say it
to yourself with a bigger lisp than Daffy duck and you're pretty much
there:-)

Dave





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

Date: 05 Aug 2001 12:16:27 +0200
From: JVromans@Squirrel.nl (Johan Vromans)
Subject: Bijeenkomst Amsterdam Perl Mongers, Dinsdag 7 augustus 2001
Message-Id: <m2snf6err8.fsf@phoenix.squirrel.nl>

[English version follows the dutch text]

Amsterdam.pm staat voor de "Amsterdamse Perl Mongers", een groep van
gebruikers van Perl. In tegenstelling tot wat de naam suggereert is
Amsterdam.pm niet beperkt tot alleen Amsterdam, maar functioneert, tot
er meer gebruikersgroepen in Nederland zijn, als Nederlandse
gebruikersgroep.

Amsterdam.pm organiseert informele bijeenkomsten waar Perl gebruikers
kunnen samenkomen en informatie en gebruikservaringen met betrekking
tot Perl kunnen uitwisselen. Deze bijeenkomsten vinden normaliter
plaats op elke eerste dinsdag van de maand. De voertaal binnen
Amsterdam.pm is in pricipe Nederlands, maar indien nodig zal Engels
worden gebruikt, b.v. om te communiceren met niet-Nederlandssprekende
aanwezigen.

De eerstvolgende bijeenkomst vindt plaats op dinsdag 7 augustus 2001 van
20:00 tot 22:00 uur op het (nieuwe!) kantoor van XS4All, Eekholt 42,
Diemen. Deze bijeenkomst onder meer:

 - napraten over de uiterst geslaagde YAPC::Europe-2.0.01

Voor meer details, waaronder een routebeschrijving, zie
http://www.amsterdam.pm.org/Meetings/next_meeting.html

Liefhebbers van een etentje vooraf kunnen tussen 17:45 en 18:15
verzamelen. Om 18:15 (écht om 18:15!) zoeken we een restaurantje in de
buurt om een hapje te eten.

Bezoek onze Web site http://www.Amsterdam.pm.org voor meer details.

[English version]

Amsterdam.pm stands for the Amsterdam Perl Mongers. We're basically a
Perl user group. Despite its name, it is not local to the Amsterdam
environment, but it welcomes Perl mongers from all over the
Netherlands.

Amsterdam.pm organises informal meetings where Perl users can meet,
and exchange information and experiences with regard to using Perl.
The meetings are normally held every first Tuesday of the month.
Although the preferred language for communication is Dutch, English
will be spoken if necessary.

Our next meeting is Tuesday August 7th, from 20:00 till 22:00
at the (new!) office of XS4All, Eekholt 42, Diemen. This meeting
will have:

 - the very successful YAPC::Europe-2.0.01

See http://www.amsterdam.pm.org/Meetings/next_meeting.html for
more detail and the directions to get there.

Should you want to join some of us for dinner, please gather between
17:45 and 18:15. At 18:15 sharp we'll leave for a restaurant somewhere
nearby for dinner.

See http://www.Amsterdam.pm.org for more details.










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

Date: 5 Aug 2001 20:44:57 GMT
From: katetal@ugcs.caltech.edu (Kate T. Porter)
Subject: Re: calling a perl script from perl
Message-Id: <9kkb89$8jl@gap.cco.caltech.edu>


>A probably stupid question: Can someone inform me on how to call a 
>perl script from a current perl script while terminating the later 
>(removing it from the stack) at the same time? 
<also somehwere you say something about being within Apache context>

Not stupid at all -- if what you want to do is call a regular script from
inside the CGI program.  I.e. process.cgi does a bunch of stuff, and then calls
 ./moreprocess.pl somewhere on the server while letting the browser thing it's
done.  Right?

The only good way I have found to do this is fork.

Usually you'd do something like
my $pid=fork;
print redirect ("continue.html");

unless ($pid){
	./moreprocess.pl
}


Cheers,
Kate


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

Date: Sun, 5 Aug 2001 18:50:56 +0200
From: "BeyondContol Inc." <beyondcontrol@runbox.com>
Subject: Re: Can you read email on an Exchange server with perl ??
Message-Id: <9kjq9p$egb$1@news.netvision.net.il>

check out Win32::MAPI  ...

Scott <thechile@ntlworld.com> wrote in message
news:EKza7.3561$tQ5.1403053@news2-win.server.ntlworld.com...
> Just wondering if its possible to write a email client in perl or if there
> is a module that allows you to access and read/send email using a
microsoft
> Exchange server??
>
> I have seen many that do smtp/pop but i am prety sure exchange runs
> diffrently.
>
> Thanks,
> [ Scott ]
>
>




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

Date: Sun, 5 Aug 2001 22:44:24 -0000
From: "B. Caligari" <bcaligari@fireforged.com>
Subject: Re: Can you read email on an Exchange server with perl ??
Message-Id: <9kkatm01pvn@enews1.newsguy.com>

"Scott" <thechile@ntlworld.com> wrote in message
news:EKza7.3561$tQ5.1403053@news2-win.server.ntlworld.com...
> Just wondering if its possible to write a email client in perl or if there
> is a module that allows you to access and read/send email using a
microsoft
> Exchange server??
>
> I have seen many that do smtp/pop but i am prety sure exchange runs
> diffrently.
>

Exchange handles pop3, imap4 and smtp quite well.

And in the process it eats up all your memory, hangs system at 100 %
processor occupancy, etc....

B






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

Date: Sun, 05 Aug 2001 21:30:50 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: CGI.pm file upload problem - Please Help!
Message-Id: <3B6DBAFD.26DBD7C5@acm.org>

Dan Baker wrote:
> 
>         #! /usr/bin/perl -w

use strict;

>         use CGI qw( param uploadInfo );
>         $CGI::POST_MAX=1024 * 100 ;                     # set maximum
> size of post to 100k
>         $TempFile::TMPDIRECTORY = './tmp_images' ;      # force temp
> file location
> 
> [snip]
> 
>         # figure out filename to save it as, and make sure it is "legal"
>         # -----
>         $UploadedImage =~ s/.*[\\|\/](.+)$/$1/ ; # grab end of path passed in
                                 ^^^^^
You're looking a '\' or a '|' or a '/' in the file path. What would
happen with the file '/home/dan/html/foo|bar.jpg'?


>         $UploadedImage =~ s/\s/_/g ; # convert spaces to _
> 
>         # build relative path to new image target
>         # -----
>         my $ImagePath = $cAdminCgi2Gallery ;
>         if ( $TargetFolder ) { $ImagePath = "$ImagePath\/$TargetFolder" }

Will fail if $TargetFolder eq "0" (a single zero.)

>         $ImagePath = "$ImagePath\/$UploadedImage" ;

No need to back-wack slashes, they are not special in quoted strings.

> [snip]
> 
> sub WriteUploadFile { my ( $FromFH , $ToPath ) = @_ ;
>         # we are using this sub because we dont trust CGI:: to check size
> 
>         # local vars
>         my $bytesread ;
>         my $buffer = "";
>         my $flen = 0 ;
> 
>         open ( TARGETFILE , ">$ToPath" ) ;

What if open() fails? _Always_ check the return value of open().

          open ( TARGETFILE , ">$ToPath" ) or die "Cannot write to
$ToPath: $!";

>         binmode( TARGETFILE );
>         binmode( $FromFH  );
>         $flen = 0 ;
>         while ( $bytesread = read( $FromFH , $buffer , 1024 ) ) {
>                 print TARGETFILE $buffer ;
>                 $flen += 1024 ;

Shouldn't this be:
                  $flen += $bytesread;


>                 if ( $flen > $CGI::POST_MAX ) { # check size here since
>                                                 # we cant count on CGI
> to do it
>                         print "Content-type: text/plain \n\n".
>                         "FATAL ERROR - \n\n".
>                         "The file $FromFH \nthat you attempted to upload
> ".
>                         "is too big. \nOnly $CGI::POST_MAX kbytes are ".
>                         "allowed.  \n\n".
>                         "Please use your browser \"Back\" button and ".
>                         "resample, crop, or select a smaller file...\n";
> 
>                         close $FromFH ;
>                         close TARGETFILE ;
>                         unlink $ToPath or die "could not delete working
> file because $!" ;
>                         exit;
>                 }
>         }
>         close $FromFH ;
>         close TARGETFILE ;
>         chmod 0666, "$ToPath" ;

        chmod 0666, $ToPath or die "Cannot chmod $ToPath: $!";


>         unless (-f $ToPath ) { # something might have gone wrong during
> the
> save
>                 die "FATAL ERROR - could not upload >$FromFH< to
> >$ToPath< because $!
> \n";
>         }
> 1;}




John
-- 
use Perl;
program
fulfillment


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

Date: Sun, 05 Aug 2001 18:17:01 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How do I sort a hash (optionally by value instead of key)?
Message-Id: <x4gb7.41$T3.171364864@news.frii.net>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.

+
  How do I sort a hash (optionally by value instead of key)?

    Internally, hashes are stored in a way that prevents you from imposing
    an order on key-value pairs. Instead, you have to sort a list of the
    keys or values:

        @keys = sort keys %hash;    # sorted by key
        @keys = sort {
                        $hash{$a} cmp $hash{$b}
                } keys %hash;       # and by value

    Here we'll do a reverse numeric sort by value, and if two keys are
    identical, sort by length of key, or if that fails, by straight ASCII
    comparison of the keys (well, possibly modified by your locale--see the
    perllocale manpage).

        @keys = sort {
                    $hash{$b} <=> $hash{$a}
                              ||
                    length($b) <=> length($a)
                              ||
                          $a cmp $b
        } keys %hash;

- 

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to

    news:news.answers

or to the many thousands of other useful Usenet news groups.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-1999 Tom Christiansen and Nathan
    Torkington.  All rights reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.

                                                           04.57
-- 
    This space intentionally left blank


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

Date: Sun, 05 Aug 2001 15:06:48 GMT
From: Koen Verbeke <Koen@invalidmiddle-earth.be>
Subject: File::Find : cannot figure it out.
Message-Id: <Pine.LNX.4.33.0108051704400.1647-100000@anfalas>

Hi

I'm trying to write a script as an exercise that takes all wav-files in
the directories specified on the command line (or in the pwd) recursively
and converts them to mp3 using lame.

This is what I've come up with so far:

<quote>

use File::Find;
use Term::ANSIColor qw(:constants);
use strict;

### lame and options ###
my $LAME = "/usr/bin/lame -h -V 0";

### command line arguments ###
@ARGV = qw(.) unless @ARGV;

### how many files are to be processed in how many directories? ###
my $amount_wavs = 0;
my $amount_dirs = 0;
find sub { $amount_dirs++ if -d }, @ARGV;
find sub { $amount_wavs++ if -f, /\.wav\b/ }, @ARGV;

print BLUE, "The total amount of wav's to be processed is $amount_wavs in
$amount_dirs directories.\n", RESET;

### start processing ###
print RED, "Converting started.\n", RESET;

my $wav_file = find sub { $_ if -f, /\.wav\b/ }, @ARGV;
my $mp3_file = ("$wav_file"."lame+.mp3");

system ("$LAME $wav_file $mp3_file");

</quote>

The problem is the start processing part. I get the following error:

<quote>

koen@anfalas:~$ ./lame+.pl test/
The total amount of wav's to be processed is 3 in 2 directories.
Converting started.
Could not find "0".
Converting done.
koen@anfalas:~$

</quote>

I'm starting to think File::Find isn't the way to go. But then what is?

TIA!!!
	- Koen



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

Date: 5 Aug 2001 10:34:44 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: File::Find : cannot figure it out.
Message-Id: <9kjp2k$71h$1@charity.cs.utexas.edu>

In article <Pine.LNX.4.33.0108051704400.1647-100000@anfalas>,
Koen Verbeke  <Koen@invalidmiddle-earth.be> wrote:
>my $wav_file = find sub { $_ if -f, /\.wav\b/ }, @ARGV;
>my $mp3_file = ("$wav_file"."lame+.mp3");
>
>system ("$LAME $wav_file $mp3_file");

I'm not sure what you're trying to do there, but it seems like maybe
you're trying to pass the filenames back from your anonymous sub, have
"find" collect them, and then put the first one into "$wav_file".

After looking at the documentation for File::Find, I can't see where it
says that "find" will do anything in particular with the return value
of your code.

So, why not have the sub do the converting, like this?

	sub convert_it
	{
	    return unless -f;
	    return unless /\.wav$/;

	    my $mp3_file = $_;
	    $mp3_file =~ s/\.wav$/.mp3/;

	    print "Converting $_.\n";
	    system ("$LAME $wav_file $mp3_file");
	}

	find \convert_it, @ARGV;

Hope that helps.

  - Logan
-- 
"Our grandkids love that we get Roadrunner and digital cable."
(Advertisement for Time Warner cable TV and internet access, July 2001)


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

Date: Sun, 5 Aug 2001 11:03:32 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: File::Find : cannot figure it out.
Message-Id: <slrn9mqo23.alt.tadmc@tadmc26.august.net>

Koen Verbeke <Koen@invalidmiddle-earth.be> wrote:
>
>I'm trying to write a script as an exercise that takes all wav-files in
>the directories specified on the command line (or in the pwd) recursively
>and converts them to mp3 using lame.
>
>This is what I've come up with so far:
>
><quote>
>
>use File::Find;

[snip]

>### how many files are to be processed in how many directories? ###
>my $amount_wavs = 0;
>my $amount_dirs = 0;
>find sub { $amount_dirs++ if -d }, @ARGV;
>find sub { $amount_wavs++ if -f, /\.wav\b/ }, @ARGV;
                              ^^
                              ^^ the results of this file test are ignored.
                              ^^ code will work identically without it...


Note that you do not use find()'s return value here, you only make
use of the side effects of calling the anon sub. Below, you (attempt to)
use the return value (when you shouldn't be using it).

Also, since you are going to be processing the filenames that you
are find()ing, you should save the names here rather than repeat
the whole darn dir search again later:

   my @wav_files;
   find sub { push @wav_files, $File::Find::name if -f && /\.wav$/ }, @ARGV;
                                                       ^^
                                                       ^^ use AND
   my $wav_file = @wav_files;   # count the .wav files



/\.wav\b/ would match if    $_ = '.wav.'     or
                            $_ = 'this is a .wav file'

Is that what you want to happen?


>my $wav_file = find sub { $_ if -f, /\.wav\b/ }, @ARGV;


You want to process three .wav files, right?

You are only saving one thing in $wav_file.

Things are not adding up here...


You are saving the return value from find(), not the value(s) from
the anon sub.

And even if that worked, and you had somehow gotten the filename
into a variable, you still have the problem that you know only
the name of the file ($_), not the path to that file!


>my $mp3_file = ("$wav_file"."lame+.mp3");
>
>system ("$LAME $wav_file $mp3_file");


What if 'lame' fails? Would you want to know so that you could
exit gracefully?

You should check the return value from system:

   ! system "$LAME $wav_file $mp3_file" or die "problem running lame...";

or

     system "$LAME $wav_file $mp3_file" and die "problem running lame...";


Now that you have the paths to the .wav files in an array, you can
just loop over the array:

   foreach my $wav_file ( @wav_files ) {
      print   "$LAME $wav_file ${wav_file}lame+.mp3", "\n";
      !system "$LAME $wav_file ${wav_file}lame+.mp3" or die ...
   }


>The problem is the start processing part. I get the following error:

>Could not find "0".


You are using find()'s return value as if it was a filename. It
is not a filename.


>I'm starting to think File::Find isn't the way to go. But then what is?


File::Find works fine. Your use of File::Find is what is broken  :-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sun, 05 Aug 2001 18:36:41 GMT
From: Dan Baker <dan@nospam_dtbakerprojects.com>
Subject: Re: File::Find : short example and notes
Message-Id: <3B6D9286.41186931@nospam_dtbakerprojects.com>



Koen Verbeke wrote:
> 
> Hi
> 
> I'm trying to write a script as an exercise that takes all wav-files in
> the directories specified on the command line (or in the pwd) recursively
> and converts them to mp3 using lame.
#!/usr/bin/perl -w

use File::Find;

my (@TOP) =                     # top level directories to search
  qw( ./ );

# --------------- executable --------------------------------
my $ExitFlag = 0 ;

find (
   sub { # this sub is executed for each dir listing traversed

        print " $File::Find::name last modified
".localtime((stat($_))[9])." \n";

	# or whatever other processing you want goes here...
	# you can check for matches on filename, process, prune, etc

   }, 
@TOP);

print "--- done --- " ;
sleep 30;
# -----------------------------------------------------------

=head1 function documentation summary

        Overview:
        the find() routine basically traverses a dir tree beginning at
defined
        start dirs, and loops thru all listings. You write a sub{} to
process
each 
        list item. You can build hashes or arrays to use after the
traversel is
complete,
        or "do stuff" in-line.

        Usage:
        find( sub{ # do stuff for each listing }, @TopDirPaths );

        Info available within sub during loop thru Dir listings:
        -------------------------------------------------------
        # $File::Find::dir contains the current directory path.
        # $File::Find::name contains the current full pathname.
        # $_ is the basename of the current listing.

        How to control the looping:
        --------------------------
        # you can test $_ , $File::Find::name , $File::Find::dir 
        with patternmatching, expressions, or whatever...
        
        # skipping the remainder of the sub(), and moving to the next in
the
list:
                return;

        # processing the current dir may be pruned from the loop so that
no
more
          of the listings within the dir get processed with:
                $File::Find::prune = 1 ; return;

        # note that there is no direct way to blow out of the find() 
        gracefully in the middle because it is chdir()ing, but if
        you set a flag and prune everything afterwards, you get out 
        pretty quickly. This may be useful when you were looking for a
        specific file,and dont need to look further once it has been
found.
        

=cut

1;


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

Date: 5 Aug 2001 21:00:28 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Having some trouble with map
Message-Id: <997044397.16903@itz.pp.sci.fi>

In article <slrn9mmav3.iik.abigail@alexandra.xs4all.nl>, Abigail wrote:
>
>Please, explain to me in simple words, why is:
>
>    foreach (@list) {$sum += $} 
>
>ok, and why isn't
>
>    map {$sum += $_} @list;
>
>? And I bet you find (and if not you, some people who don't like side
>effects in map don't mind the following):
>
>    $sum += $_ foreach @list;
>
>Could you give me one sane reason my "KEYWORD LIST CODE" and "CODE
>KEYWORD LIST" are ok, and "KEYWORD CODE LIST" is a sin?

It's not the order of the keywords.  It's the choice of keyword.

  * "for"/"foreach" evaluates a statement or block for each element of a
    list.  The side effects are all that matters, since it has no return
    value.

  * "map" evaluates an expression or block for each element of a list
    and returns a list consisting of the values of those expressions.
    The expressions _may_ also have side effects, but this can be easy
    to overlook when browsing code, unless explicitly noted.

I know you still disagree.  I'd just prefer if you disagreed on the
issue being discussed rather than a slightly different one.

(It's not really even about side effects in map being evil.  It's more
about externally noticeable side effects in map being more obfuscated
than foreach or side-effectless map, and about obfuscation being bad in
many, though by no means all, situations.)

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post something,
we discuss its implications.  If the discussion happens to answer a question
you've asked, that's incidental."           -- nobull in comp.lang.perl.misc



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

Date: Sun, 05 Aug 2001 15:25:56 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: How to print a binary string as picture to web page
Message-Id: <3B6D9DC4.C0DBF790@earthlink.net>

Kin wrote:
> 
> Dear all,
>     I store jpeg pictures into Sybase as BLOB type and extract it to a
> variable in the CGI program. It is a binary string. How can I print it
> as a picture inside a web page directly without saving it to a
> temporary file first ? Is there any module that can help me to finish
> this task ?

If your CGI is creating html, you can't do it all in one pass (ie, you
can't have it print the html, followed by the image, and expect it to
work).  What you can do is have the html have the image locations be of
the form <IMG SRC="/cgi-bin/getimage_from_sysbase.cgi/foo=bar/baz.jpg">,
which will call the cgi program getimage_from_sysbase.cgi with the
environment variable PATH_INFO set to "foo=bar/baz.jpg", which you would
then parse into a sysbase query.

To decrease overhead, you may want to do caching.  For server-side
caching, use CGI::Cache; this will allow you do not re-query sysbase for
identical requests.

It doesn't cut down any on data transmission, though.

For that, you have to do something to enable client-side and proxy
caching:  Check if there's an "If-Modified-Since" http header (which
will be in the environment variable "HTTP_IF_MODIFIED_SINCE") first, and
act appropriately if so (avoiding a retransmission), and when you do
need to send the actual file, include a "Last-Modified" and
"Content-Length" header (otherwise the browser or proxy won't cache).

If images don't get changed once they go into sysbase, you probably
don't need to know the change date of the image, but can instead use the
change date of the cgi script.  This can be gotten with something like
(stat(DATA))[9].

Note that you probably don't have to parse the date into a number, just
compare whether the datestring is equal to the datestring of the actual
last modified date (after all, it's not going to get younger, and if
it's not younger, nor equal, then it must be newer).

If you're using CGI::Cache, make sure you *don't* get the "Status: 304
not modified" responses in the cache, that would be bad :)  Likewise for
"Status: 404 No such image in database" if it's not in your sysbase db.

-- 
I need more taglines. This one is getting old.


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

Date: Sun, 05 Aug 2001 17:42:42 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: negative lookahead
Message-Id: <3B6DBDD2.9ACE0E36@earthlink.net>

Ilya Martynov wrote:
> 
> BL> mike wrote:
> >> I want to match a string that starts with "aaa" and ends with "bbb"
> >> as long as the is no "zzz" between aaa and bbb.
> >>
> >> My attempt:
> >>
> >> $mystring =~ m/aaa.*?(?!zzz)bbb/si;
> >>
> >> Result:
> >>
> >> Still matches even if the string contains zzz.
> 
> BL> I think this will work:
> 
> BL>     m/aaa(?:(?!zzz).)*?bbb/si;
> 
> BL> but it probably won't be the fastest scheme imaginable.
> 
> Correct pattern is
> 
> m/^aaa(?:(?<!zzz).)*bbb$/si;

The above re incorrectly matches "aaazzzbbb".

Bart Latuer's is correct (though you may want to add ^$ anchors).

Yours would be fixed as:
	m/^aaa(?:.(?<!zzz))*bbb$/s; # me

If you're going to anchor it, it would likely be faster to do:
	m/^aaa/ && !m/zzz/ && m/bbb$/; # me :)
or:
	m/^aaa(?!.*zzz).*bbb$/; # Craig Berry
or even:
	substr($_,0,3) eq "aaa" &&
		index($_,"zzz")==-1 && substr($_,-3) == "bbb"; # me :)

Note that with my two, checking for aaa and bbb first, before zzz, may
be faster.

If what you want is to capture, then something like:
        m/(aaa(?:(?!zzz).)*?bbb)/s; # Bart Latuer, Randal Schwartz
or:
	m/(aaa(?:.(?<!zzz))*?bbb)/s; # me
or:
	m/(aaa(?:[^z]|(?!zzz)z)*?bbb)/; # Bart Latuer
or:
	m/(aaa(?:(?>[^z]+)|(?!zzz)z)*?bbb)/; # Ilya Zakharevich
or try some non-re code (by me) :
	my $start, $end;
	for( $start = 0; -1 != ($start=index($_,"aaa",$start); ) {
		last if -1 == ($end = index($_,"bbb",$start+=3));
		my $zzz = index($_,"zzz",$start);
		next if $zzz > -1 && $zzz < $end;
	}
	# start is just after aaa, end is just before bbb.
	# if one or both are -1, then no match was found.

-- 
I need more taglines. This one is getting old.


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

Date: 5 Aug 2001 20:33:28 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: perl regular expression grammar
Message-Id: <997043077.16428@itz.pp.sci.fi>

[Removed comp.compilers from newsgroup list.]

In article <01-08-007@comp.compilers>, Mark Jason Dominus wrote:
>Ilmari Karonen  <usenet11522@itz.pp.sci.fi> wrote:
>>I may be remembering the exact dirty details wrong.  I suggest you see
>>the code in toke.c
>
>I think you will find it in regcomp.c, not toke.c.

Actually, it *is* in toke.c.  In particular, I was referring to this
code in S_scan_const():

        /* check for embedded scalars.  only stop if we're sure it's a
           variable.
        */
        else if (*s == '$') {
            if (!PL_lex_inpat)  /* not a regexp, so $ must be var */
                break;
            if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
                break;          /* in regexp, $ might be tail anchor */
        }

(The fact that we're indeed discussing the parsing of "$" in Perl
regexes should be apparent from the code, but not from the quoted
discussion above, which has been somewhat excessively trimmed.)

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post something,
we discuss its implications.  If the discussion happens to answer a question
you've asked, that's incidental."           -- nobull in comp.lang.perl.misc



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

Date: Sun, 5 Aug 2001 18:44:27 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: prompting and redirection with ssh
Message-Id: <slrn9mr50b.r6h.see-sig@typhoon.xnet.com>

On Sun, 05 Aug 2001, Billy \"Bob\" Bob <billy_dont_try@verizon.net> wrote:
> *** start doh ***
> It looks like I goofed with the original post.  It doesn't look like
> the attachment made it.
> Sigh, if only the newbies (like myself) would use alt.test
> *** end doh ***
> 
> Hi,
> 
> I am trying to figure out how to "intelligently" prompt the user from
> perl.  I have read a great deal from this newsgroup (via
> groups.google.com), the perl cookbook, and other resources.  Attached
> is the script that I have written based off of these readings.
> 
> It appears to work in every scenario I throw at it from the console.
> Below are some examples usages:
> 	./input.pl . file -
> 	echo input | ./input.pl - file
> 	echo input | ./input.pl - file /dev/tty
> 	echo input | ./input.pl - file /dev/tty > a
> 	./input_pl file - /dev/tty > a
> 
> However, when I try and run this last one via ssh the prompt does not
> appear on the screen.  It is re-directed to the file 'a'.  That is,
> when I:
> 	ssh -t host input.pl file - /dev/tty > a
> 
> It does not work like I exepct.  I am using ssh version:
> 	OpenSSH_2.5.2p2, SSH protocols 1.5/2.0, OpenSSL 0x0090601f
> 
> Do you have any ideas on how I can get it to work with ssh?

Maybe your psuedo tty is not /dev/tty.  For example:

efflandt@compaq:~ > ssh -t mainpc tty
/dev/pts/0

Also you were attempting to read FH opened write only.
Try this:

#!/usr/bin/perl -w
use strict;
my ($tty, $oldfh, $reply);
chomp($tty = `tty`) || die "no tty";
open (FH, "+< $tty") || die "can't open $tty: $!";  # read/write
$oldfh = select(FH); $| = 1; select($oldfh);	# unbuffer FH
print FH "Prompt on $tty\nFeed me: ";
if (defined($reply = <FH>)) { chomp $reply; }	# single line
# while (defined($_ = <FH>)) { $reply .= $_; }	# multiline  
if ($reply) {
    print FH "You entered: $reply\n";
} else {
    print FH "no input received\n";
}
close FH;


efflandt@compaq:~ > ssh -t mainpc ./input.pl
Prompt on /dev/pts/1
Feed me: It works!
You entered: It works!
Connection to mainpc.localdomain closed.

-- 
David Efflandt  (Reply-To is valid)  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: 5 Aug 2001 16:41:09 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: string extraction
Message-Id: <9kjsv5$m7p$1@bob.news.rcn.net>

shaz <ssa1701@yahoo.co.uk> wrote:
> There is a problem with the tags as I have found out that they will
> not be of the form <NN> and <VBZ>. They should be like /NN and /VBZ. I
> have tried to make the change but the program stops reading the file.

[slightly rearranging things to make the explanation easier to read]

> The data is now

> This is part of Sol05a.txt and also the final exam/NN. This is used
> for eegggtgg the book/NN.


>> my @tags = ('<NN>', '<VBZ>', '<DET>');

I presume you've changed this in your actual code.

>> my $search = join('|',@tags);
>> my %taglist;
>> 
>> while (<DATA>) {
>>         while (/(\w+)\s($search)/og) {

> The program does not reach this point (due to the $search variable)

I doubt it's the variable doing it; more like that '\s' in the regex, 
since in your sample data there's no space separating the tags from the 
words.


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

Date: Sun, 05 Aug 2001 18:08:50 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: two questions
Message-Id: <3B6DC3F2.286903B4@earthlink.net>

Stephen Corwin wrote:
> 
> Salaam, Gurus!
> 
> My first question is for someone who understands Perl garbage
> collection much better than I do.  What's the quickest way to destroy
> a tree in which each node is a Perl object?  I'd like to simply
> destroy all references to the root, but I'm not sure exactly what that
> will accomplish.

Destroying all references to root is needed for *some* types of trees,
because those root-refs are circular references.

Other common circular structures are when each node has a reference to
it's parent.  This also has to be destroyed for everything to clean up
ok.

We need some more details about your tree to help you.

>  The books I have don't explain gc in detail; they
> just say that items are deleted when all references to them have been
> deleted. Depending on how this is done, if I just delete all
> references to the root, gc may take as many passes as there are plies
> in the tree to delete all nodes.  Would I be better off traversing the
> tree and destroying references from the leaves up?

What's best depends on your data structure.  I'll assume (since this is
usually the most recommented way to do it), that you have a Tree class
and a Node class, and the Tree contains a reference to the node which is
the root of the tree, and the other nodes nodes may or may not contain
references to that root node (and *none* to the Tree object).

When your Tree object goes out of scope in the places it's used (when
it's refcount goes to 0), Tree::DESTROY will be called.  From here, you
should break any circular references among nodes (pointers to parents or
to root), so that after Tree::DESTROY returns, the gc will be able to
clean up the nodes, too.

An alternative is for any 'upward' references (pointers to parts higher
in the tree, such as the root or parent) to be "weak references", which
should be done with the Weakref class available from CPAN.  If you do
this, then you might not even need to write a DESTORY method.

> A second question is about just how much overhead objects take.  On a
> machine with 128Mb RAM (and nothing else running except for Win98) I
> built a tree with 80,000 nodes.  Each node held about 250 bytes of
> data, for about 20Mb total.  There are instance methods, but those
> shouldn't add much to the total.

Actually, methods shouldn't add any to the total.

> Yet stuff was swapped out to disk; I could hear
> the disk being hit repeatedly, and everything was very slow.  What
> does it actually cost to use objects?

The difference (memorywise) between using an "object" and using just the
hashref or arrayref should be nothing -- bless just sticks a pointer to
the class name into part of the SV.

The difference between using lots of small hashrefs or arrayrefs and
using one biiig array[ref] is... umm, I dunno.

>  And is there anything to be done?

Replace your hashes with psuedohashes (ie, "use fields"), or write the
tree in C.

> Must I implement the tree using arrays?

This may not give you an improvement.

Just offhand, what kind of tree structure is this, and why won't a
simple hash work as well or better?

-- 
I need more taglines. This one is getting old.


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

Date: 5 Aug 2001 10:10:37 -0700
From: kenphilbrick@mindspring.com (Ken)
Subject: Re: using eval
Message-Id: <f8b445c0.0108050910.607802d9@posting.google.com>

logan@cs.utexas.edu (Logan Shaw) wrote in message news:<9kiql3$5ad$1@charity.cs.utexas.edu>...
> In article <pt2b7.9752$K6.3948128@news2>,
> Clinton A. Pierce <clintp@geeksalad.org> wrote:
> >In article <f8b445c0.0108041720.2cbbee7a@posting.google.com>,
> >	kenphilbrick@mindspring.com (Ken) writes:
> >> I'm trying to use eval to execute all the code contained in a separate
> >> file.  I've tried the following:
> >
> >eval {
> >	require "file.pl";
> >};
> >
> > or
> >
> > open(F, "file.pl") || die;  
> > { 
> >	local $/;
> >	$a=<F>;
> > }
> > eval "$a";
> >
> > or, if you don't really need eval...
> >
> >do "file.pl";
> 
> "do" may be better than "require" anyway, since they have another
> important difference: "do" runs the code every time, and "require" runs
> it only a single time.  So usually "do" is useful if you need to
> actually run code, whereas "require" is useful if you want to do things
> like define subroutines.
> 
>   - Logan

Thanks, that helps.

--
Ken


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

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


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