[19196] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1391 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 27 09:05:32 2001

Date: Fri, 27 Jul 2001 06:05:10 -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: <996239110-v10-i1391@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 27 Jul 2001     Volume: 10 Number: 1391

Today's topics:
    Re: Addressing WinNT Task Manager (Yves Orton)
    Re: All computers in world MUST sync with ATOMIC clock  mnd999@hotmail.com
    Re: CGI:standard <flavell@mail.cern.ch>
    Re: chess in perl <ubl@schaffhausen.de>
    Re: chess in perl (Sean Mintz)
        Creating .ram files on-the-fly <A.J.M.Rosendaal@let.rug.nl>
    Re: Creating .ram files on-the-fly (Jay)
        Emacs modules for Perl programming (Jari Aalto+mail.perl)
    Re: FAQ: How can I get "#!perl" to work on [MS-DOS,NT,. <gimi@psico.ch>
        FAQ: How do I find matching/nesting anything? <faq@denver.pm.org>
    Re: Help with Linux Programming slash@dot.c.o.m.org
    Re: Image Size <ubl@schaffhausen.de>
    Re: Image Size <johannes_be@gmx.de>
    Re: Image Size <johannes_be@gmx.de>
        local and tie (Anno Siegel)
    Re: Read Directory <iltzu@sci.invalid>
    Re: Regular Expression <osbornelee@hotmail.com>
    Re: sortlen -- filter to sort text by line length (Yves Orton)
    Re: Split Question (Anno Siegel)
    Re: Stripping extention from a filename in a string (Yves Orton)
    Re: Stripping extention from a filename in a string (Anno Siegel)
        Unlinking lockfiles safely  [was: Another flock questio <iltzu@sci.invalid>
    Re: Where are the values stored? (Yves Orton)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 27 Jul 2001 03:23:06 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Addressing WinNT Task Manager
Message-Id: <74f348f7.0107270223.44d1fbc5@posting.google.com>

"bowman" <bowman@montana.com> wrote in message news:<DW587.19504$qT1.4096@newsfeed.slurp.net>...
> "Me" <madewildeNOSPAM@hotmail.com> wrote in message
> news:3B5FDDAE.CBEF2A2B@hotmail.com...
> >
> > Or at any rate retrieving process id's from running windows programs (so
> > NOT the ones you create yourself - those I can find...)?
> 
> on NT/2000, you can get the pid's by accessing HKEY_PERFORMANCE_DATA in the
> Registry. This is actually an ephemeral hive that doesn't show up in
> regedit. If psapi.dll is on the machine, it may also be used to enumerate
> the processes.
> 
> A third alternative is using the WMI interface.

A fourth would be to check out http://www.sysinternals.com/ they have
an assortment of essential tools for working in a W9x/NT/W2k
enviornment.  pslist.exe from them could be parsed quite nicely by
perl, AND you can use it to see the process on a different machine.
IMHO, developers in Microsoft enviornment should have their tools and
cygwin installed always...

psexec \\othermachine cmd.exe

yves


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

Date: Fri, 27 Jul 2001 10:32:53 +0000 (UTC)
From: mnd999@hotmail.com
Subject: Re: All computers in world MUST sync with ATOMIC clock before 12:00 AM 21July 2001
Message-Id: <9jrg0k$pmi$1@sp15at20.hursley.ibm.com>

> Luke Webber <luke@webber.com.au> wrote in message
> news:mOo57.13943$Xr6.115149@news-server.bigpond.net.au...
> 
> <accent>
> No Cheese. No Burger. Chemicals.
> </accent>

Mmmm. Chemicals.

Mark


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

Date: Fri, 27 Jul 2001 13:05:50 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: CGI:standard
Message-Id: <Pine.LNX.4.30.0107271257140.9127-100000@lxplus023.cern.ch>

On Jul 26, Brian D. Green delicately tapped the keys:

> > > $netid = $ENV{'REMOTE_USER'};
> >
> > > open(SAVE, ">>$netid.out") || die("Can't open $netid.out for writing:
> > > $!\n");
> >
> > It's *not* a good idea to open a file for writing or appending when its
> > name comes from outside your program and you haven't checked the name to
> > make sure it's reasonable.
>
> Thanks for the reminder. The user id's in this situation are all limited
> to alphanumerics with a maximum of eight characters, so I think they're
> pretty safe.

Don't do that.  You're in a security-exposed situation here.  Apply a
defensive strategy, rather than trying to think of excuses for not
doing so.

Run with -T taint checks on, so that you'll be alerted to tainted
data.  Whenever you think you want to rely on tainted data conforming
to some pattern, don't just assume it - _untaint_ it to the pattern
you want. Accept only the characters you know are safe, and reject the
rest.  (That's as distinct to the more risky approach of tossing only
the characters that you can think are problematical, and accepting the
rest - I couldn't recommend doing that).

good luck



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

Date: Fri, 27 Jul 2001 12:43:43 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: chess in perl
Message-Id: <3B6153EF.715B7C6C@schaffhausen.de>

Sean Mintz schrieb:
> 
> Hi,
> Any ideas you may have to speeding this up in any area would be
> greatly appreciated. If you have any interest in actually working on
> this with me, that would be even better.

Well, 

you can probably find complete chess playing algorithms somewhere on
the internet. Just implement them in Perl and your done. Good techniques
to improve your algorithm performance are writenn down in "Mastering 
Algorithms in Perl".

If thats still too slow you might want to write the whole thing in C or
consider using Inline for the number crunching parts.

->malte


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

Date: 27 Jul 2001 06:03:41 -0700
From: stmintz@yahoo.com (Sean Mintz)
Subject: Re: chess in perl
Message-Id: <abf786a.0107270503.3c4354d7@posting.google.com>

Thanks!

I have the book "Mastering Algorithms in Perl". All the stuff in there
is helpful too. Only thing is the move generation code (which
mastering algorithms does not talk about) is too slow. Any ideas how I
might be able to speed it up?

- Sean

--------------------------------------------------------------------------
Malte Ubl <ubl@schaffhausen.de> wrote in message news:<3B6153EF.715B7C6C@schaffhausen.de>...

> Well, 
> 
> you can probably find complete chess playing algorithms somewhere on
> the internet. Just implement them in Perl and your done. Good techniques
> to improve your algorithm performance are writenn down in "Mastering 
> Algorithms in Perl".
> 
> If thats still too slow you might want to write the whole thing in C or
> consider using Inline for the number crunching parts.
> 
> ->malte


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

Date: Fri, 27 Jul 2001 12:21:36 +0200
From: "André Rosendaal" <A.J.M.Rosendaal@let.rug.nl>
Subject: Creating .ram files on-the-fly
Message-Id: <9jrfbg$3cb$1@syn.let.rug.nl>

Hello,

Can I use Perl to write a cgi script that creates a RealAudio .ram file
on-the-fly (or in fact any text file with an arbitrary extension) and
returns it to the client? Can this be done without actually creating the
file on disk? Thus, instead of returning an html-file, it should return a
file that opens the Real player.

Thanks,
André Rosendaal




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

Date: 27 Jul 2001 11:00:13 GMT
From: jay@castlelink.co.uk (Jay)
Subject: Re: Creating .ram files on-the-fly
Message-Id: <90EB7C69Ejabrealprogrammercom@195.129.110.133>

A.J.M.Rosendaal@let.rug.nl (André Rosendaal) wrote in
<9jrfbg$3cb$1@syn.let.rug.nl>: 

>Can I use Perl to write a cgi script that creates a RealAudio .ram
>file on-the-fly (or in fact any text file with an arbitrary
>extension) and returns it to the client? Can this be done without
>actually creating the file on disk? Thus, instead of returning an
>html-file, it should return a file that opens the Real player.
>

Not realy a perl question, but cos' I have it open, here is what I have 
(written in perl)...

#!/usr/bin/perl -Tw
use strict;

use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $q = new CGI;

my $fname = $q->param('fname') or '';
$fname =~ s!/!!g;

$fname =~ /\.([^\.]+)$/;
my $postfix = $1 || 'html';
my %content_types = (
  html  => 'text/html',
  csv   => 'text/csv',
  jpeg  => 'image/jpeg',
);


open FILE, "< $fname" or die "not open $fname : $!";

print "Content-disposition: file; filename=$fname\n";
print "Content-type: $content_types{$postfix}\n\n";

print while <FILE>;

close FILE or die "not close $fname : $!";

exit;

Jay


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

Date: 27 Jul 2001 10:11:21 GMT
From: <jari.aalto@poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_996228622@rtfm.mit.edu>

Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto <jari.aalto@poboxes.com>

Announcement: "What Emacs lisp modules can help with programming Perl"

    Preface

        Emacs is your friend if you have to do anything comcerning software
        development: It offers plug-in modules, written in Emacs lisp
        (elisp) language, that makes all your programmings wishes come
        true. Please introduce yourself to Emacs and your programming era
        will get a new light.

    Where to find Emacs/XEmacs

        o   Unix:
            http://www.gnu.org/software/emacs/emacs.html
            http://www.xemacs.org/

        o   Windows
            http://www.gnu.org/software/emacs/windows/ntemacs.html
	    ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe

	o   More Emacs resources at 
	    http://tiny-tools.sourceforge.net/emacs-elisp.html


Emacs Perl Modules

    Cperl -- Perl programming mode

        .ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
        .<olson@mcs.anl.gov>           Bob Olson (started 1991)
        .<ilya@math.ohio-state.edu>    Ilya Zakharevich

        Major mode for editing perl files. Forget the default
        `perl-mode' that comes with Emacs, this is much better. Comes
        standard in newest Emacs.

    TinyPerl -- Perl related utilities

	.http://tiny-tools.sourceforge.net/

        If you ever wonder how to deal with Perl POD pages or how to find
        documentation from all perl manpages, this package is for you.
        Couple of keystrokes and all the documentaion is in your hands.

        o   Instant function help: See documentation of `shift', `pop'...
        o   Show Perl manual pages in *pod* buffer
        o   Load source code into Emacs, like Devel::DProf.pm
        o   Grep through all Perl manpages (.pod)
        o   Follow POD manpage references to next pod page with TinyUrl
        o   Coloured pod pages with `font-lock'
        o   Separate `tiperl-pod-view-mode' for jumping topics and pages
            forward and backward in *pod* buffer.
        o   TinyUrl is used to jump to URLs (other pod pages, man pages etc)
            mentioned in POD pages. (It's a general URL minor mode)

    TinyIgrep -- Perl Code browsing and easy grepping

        [TinyIgrep is included in the Kit]

        To grep from all installed Perl modules, define database to
        TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
        how to set up datatbases for Perl5, Perl4 whatever you have
        installed

        TinyIgrep calls Igrep.el to run the find for you, You can adjust
        recursive grep options, ignored case, add user grep options.

        You can get `igrep.el' module from <kevinr@ihs.com>. Ask for copy.
	Check also ftp://ftp.ihs.com/pub/kevinr/

    TinyCompile -- Browsing grep results in Emacs *compile* buffer

        TinyCompile is minor mode for *compile* buffer from where
        you can collapse unwanted lines, shorten the file URLs

            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT

            -->
            cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
            file1:NNN: MATCHED TEXT
            file1:NNN: MATCHED TEXT

End



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

Date: Mon, 23 Jul 2001 21:08:54 +0200
From: gimi <gimi@psico.ch>
Subject: Re: FAQ: How can I get "#!perl" to work on [MS-DOS,NT,...]?
Message-Id: <3B5C7646.A2955E0@psico.ch>

hi,

PerlFAQ Server wrote:
> +
>   How can I get "#!perl" to work on [MS-DOS,NT,...]?

ah yes, good question. - i was looking
for exactly that - how does shebang work
with _ms-dos_ ?
 
>     For OS/2 just use
[snip]
>     The Win95/NT installation, when using the ActiveState port of Perl, will
[snip]
>     Macintosh Perl programs will have the appropriate Creator and Type, so
[snip]
> -
[snip]

uhh? - so, what about ms-dos??

- ah, i see, it's a faq, not the
answer...

never mind; just wanted to tell you.

:D

gimi

--
4. Life is a state of mind.




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

Date: Fri, 27 Jul 2001 12:17:41 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How do I find matching/nesting anything?
Message-Id: <FZc87.101$os9.211254784@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 find matching/nesting anything?

    This isn't something that can be done in one regular expression, no
    matter how complicated. To find something between two single characters,
    a pattern like "/x([^x]*)x/" will get the intervening bits in $1. For
    multiple ones, then something more like "/alpha(.*?)omega/" would be
    needed. But none of these deals with nested patterns, nor can they. For
    that you'll have to write a parser.

    If you are serious about writing a parser, there are a number of modules
    or oddities that will make your life a lot easier. There are the CPAN
    modules Parse::RecDescent, Parse::Yapp, and Text::Balanced; and the
    byacc program.

    One simple destructive, inside-out approach that you might try is to
    pull out the smallest nesting parts one at a time:

        while (s/BEGIN((?:(?!BEGIN)(?!END).)*)END//gs) {
            # do something with $1
        } 

    A more complicated and sneaky approach is to make Perl's regular
    expression engine do it for you. This is courtesy Dean Inada, and rather
    has the nature of an Obfuscated Perl Contest entry, but it really does
    work:

        # $_ contains the string to parse
        # BEGIN and END are the opening and closing markers for the
        # nested text.

        @( = ('(','');
        @) = (')','');
        ($re=$_)=~s/((BEGIN)|(END)|.)/$)[!$3]\Q$1\E$([!$2]/gs;
        @$ = (eval{/$re/},$@!~/unmatched/);
        print join("\n",@$[0..$#$]) if( $$[-1] );

- 

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.21
-- 
    This space intentionally left blank


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

Date: Fri, 27 Jul 2001 08:37:32 GMT
From: slash@dot.c.o.m.org
Subject: Re: Help with Linux Programming
Message-Id: <3b6127a0.51063828@news.freeserve.co.uk>

On Fri, 27 Jul 2001 03:59:13 GMT, "Ryan Gralinski" <ryan@bong.net> wrote:

>Can someone help me out with perl and linux, i'm trying to read raw data
>from a USB Device that is not supported
>this is the info dmesg gives me
>
>usb.c: USB device 2 (vend/prod 0x8e6/0x432) is not claimed by any active
>driver.
>
>
>How could i open this port and read the raw data? it is not a device in /dev

I think you may have to update your kernel. Low level access to the hardware is'nt
possible in a language like perl. If there's no kernel patch/option for the device,
you'll either need to write a driver in C/C++/ASM or try to find a pre-built driver
on the net somewhere.


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

Date: Fri, 27 Jul 2001 12:47:42 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Image Size
Message-Id: <3B6154DD.CCC3488E@schaffhausen.de>

"Johannes B." schrieb:
> 
> I already tried it. But it doesn't work.
> I can only login to the server via FTP.

You can do this nicer by maniipulating @INC but
this technique is probably the easiest.

Create a dir called Image in the dir where your script lives.
Copy Size.pm in there and thats it.

->malte


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

Date: Fri, 27 Jul 2001 13:05:18 +0200
From: "Johannes B." <johannes_be@gmx.de>
Subject: Re: Image Size
Message-Id: <9jrhtf$gaf$02$1@news.t-online.com>

I tried it. But it doesn't work. I think my provider doesn't support it. ;(
Is there another Module?




"Malte Ubl" <ubl@schaffhausen.de> wrote in message
news:3B6154DD.CCC3488E@schaffhausen.de...
> "Johannes B." schrieb:
> >
> > I already tried it. But it doesn't work.
> > I can only login to the server via FTP.
>
> You can do this nicer by maniipulating @INC but
> this technique is probably the easiest.
>
> Create a dir called Image in the dir where your script lives.
> Copy Size.pm in there and thats it.
>
> ->malte




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

Date: Fri, 27 Jul 2001 13:11:17 +0200
From: "Johannes B." <johannes_be@gmx.de>
Subject: Re: Image Size
Message-Id: <9jri8m$b7g$04$1@news.t-online.com>

I already have it.

> > Create a dir called Image in the dir where your script lives.
Directory must start with an upercase letter.

"Johannes B." <johannes_be@gmx.de> wrote in message
news:9jrhtf$gaf$02$1@news.t-online.com...
> I tried it. But it doesn't work. I think my provider doesn't support it.
;(
> Is there another Module?
>
>
>
>
> "Malte Ubl" <ubl@schaffhausen.de> wrote in message
> news:3B6154DD.CCC3488E@schaffhausen.de...
> > "Johannes B." schrieb:
> > >
> > > I already tried it. But it doesn't work.
> > > I can only login to the server via FTP.
> >
> > You can do this nicer by maniipulating @INC but
> > this technique is probably the easiest.
> >
> > Create a dir called Image in the dir where your script lives.
> > Copy Size.pm in there and thats it.
> >
> > ->malte
>
>




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

Date: 27 Jul 2001 10:44:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: local and tie
Message-Id: <9jrgn4$evj$1@mamenchi.zrz.TU-Berlin.DE>

Localizing a tied variable is quite possible, and local() uses
the FETCH and STORE methods, but the effect isn't always as intended.

Suppose you have a (package-) variable $x, tied in such a way that
storing to it saves the stored value in some secret place to be used
in the rest of the program, while reading $x always returns the value
1234. (This may look weird, but see below[1]) If you now say

    $x = 1;           # secret value is now 1
    {
        local $x = 2; # secret value now 2, local() has saved 1234
    }
    # Now the secret value is 1234, not back to 1 as it should be

Only the package $x is tied to can know how to restore a former
state in the spirit of local(), but to do so, it would have to
know when it is called by local().  So the question I have is:
Is there a way for a Perl sub to learn if it was called by local()?
Could an XS routine snoop around?  Does caller() return an
undocumented flag to that effect? (One can hope, no?).  Could
caller() reasonably be made to do so?

Anno

[1] I intend to tie $SIG{ __WARN__} and $SIG{ __DIE__} in such a
    way that, in addition to the coderef a user stores there,
    certain (logging-) activities also happen.  Storing to the
    tied location would squirrel away the handler in the tied
    object.  Reading would always return the same subref, a closure
    that does some logging and then calls the user's handler.
    In most cases, an unsuspecting program that uses one of these
    handlers would continue to work, but it would fail badly if
    a user tried (as they should) to make the change local.


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

Date: 27 Jul 2001 10:34:39 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Read Directory
Message-Id: <996229215.29585@itz.pp.sci.fi>

In article <t6F77.143721$qs5.23399687@news02.optonline.net>, Blnukem wrote:
>
>    I'm tying to read all of the files in a directory but with my script I
>get a dot "." and a double ".." listed as files. I'm guessing that this is
>the directory structure that it is reading is there a way to read just the
>file in the directory without the dots.
>
>opendir (DOC, "../test");
>@files = readdir (DOC);

If you really want just files, and not subdirectories, then Godzilla's
advice would appear to be correct for once.  The code, though, could be
made quite a bit simpler:

  opendir DOC, "../test";
  my @files = grep -f "../test/$_", readdir DOC;

If you want subdirectories too, but not the current or parent
directory, then the best you can do is indeed:

  opendir DOC, "../test";
  my @files = grep $_ ne "." && $_ ne "..", readdir DOC;

This will work on Unix and Windows, and shouldn't cause problems on most
other systems unless you have an actual subdirectory named "." or "..".

Unfortunately AFAIK Perl currently has no guaranteed cross-platform way
of excluding non-child entries from a directory listing.  I've mentioned
it a few times on p5p and elsewhere, but only time will tell if anything
will be done about that.

-- 
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: Fri, 27 Jul 2001 13:29:49 +0100
From: "Lee Osborne" <osbornelee@hotmail.com>
Subject: Re: Regular Expression
Message-Id: <996237059.10050.0.nnrp-14.c2de1f0e@news.demon.co.uk>

Hi all,



OK heres a solution!

$input = "12a3456";


$idLengthIn = length($input);

if ($input{'document_id'} =~ /\d{$idLengthIn}/) {

   print "Digits ONLY!";

}

else {

   print "Not just digits!";

}



Lee.



"Lee Osborne" <osbornelee@hotmail.com> wrote in message
news:996079173.11940.0.nnrp-01.c2de1f0e@news.demon.co.uk...
> Hi all,
>
> Sorry to bother you all but I can't find a solution to a simple problem. I
> assure you I have had a good look for the solution, but have had no
success.
>
> What is the regular expresssion to check whether a string contains ONLY
> numbers?
>
> It will be part of the code:
>
> if ($stringIn =~ /<THE RE SOLUTION>/) {
>
>   #  Numbers only in this string}
> else {
>
>   # There are characters other than number in the string.
> }
>
> Thanks in advance,
>
> Lee.
>
>




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

Date: 27 Jul 2001 03:08:12 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: sortlen -- filter to sort text by line length
Message-Id: <74f348f7.0107270208.13f50d49@posting.google.com>

Chris Stith <mischief@velma.motion.net> wrote in message news:<tm17t1gute4f8@corp.supernews.com>...
> Yves Orton <demerphq@hotmail.com> wrote:
> > Benjamin Goldberg <goldbb2@earthlink.net> wrote in message news:<3B54F150.7408211B@earthlink.net>...
> >> How does ST compare with GRT or with basic/custom sort?
>  
> > After reading the thread I did a bunch of benchmarks.  It looks like
> > ST is actually pretty bad.  I even tried using super long strings to
> > try to cause trouble for the GRT types substr() operation, but that
> > seemed to have a more profound effect on the ST than on the GRT, which
> > quite frankly suprised me.
> 
> That's why benchmarks are important. ;-)

Indeed.  :-)

<SNIP>

> > A minor question: What does GRT stand for?
> 
> That's a major question, IMHO. It stands for Guttman-Rosler Transform,
> as in Uri Guttman an Larry Rosler, coauthors of a work on efficient
> sorting in Perl. They codiyfied it clearly and popularized it, and
> although they did not think up the concept from scratch, I think the
> name is pretty fitting considering the amount of time and effort
> Rosler and Guttman put into demonstrating its use with mny different
> data types.

With different data types?  That sounds interesting.  Id like to
understand this technique a bit better, especially as to how it can be
used with multiple keys (or not) and with more complicated data types.
Can you point me to some references or should I just trawl usenet for
references to GRT?

Also, its interesting that the GRT is not mentioned in books like Perl
Cookbook or Algorithyms in Perl (or whatever its called, I left it at
home.)  The Cookbook covers the ST with quite a bit of depth, as does
Algorithyms... Seems like the GRT should at least have been mentioned.

Anyway, thanks for the info,
Yves


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

Date: 27 Jul 2001 12:28:13 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Split Question
Message-Id: <9jrmot$evj$3@mamenchi.zrz.TU-Berlin.DE>

According to Benjamin Goldberg  <goldbb2@earthlink.net>:

[...]

> use Text::CSV_XS;
> my $csv = Text::CSV_XS->new;
> while( <INPUT> ) {
> 	chomp;
> 	until( $csv->parse($_) or eof ) {
> 		$_ .= "\n" . <INPUT>;

You want to chomp again here.

> 	}
> 	if(!$csv->status) {
> 		die "Unexpected eof: partial line <" .
> 			$csv->error_input() . "> not valid.\n";
> 	}
> 	my @array = ($csv->fields)[0..9];
> 	# process here.
> }

 ...or you could delay the chomp() until a record is assembled.

Anno


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

Date: 27 Jul 2001 04:24:13 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Stripping extention from a filename in a string
Message-Id: <74f348f7.0107270324.36f68498@posting.google.com>

Jason LaPenta <lapenta_jm@yahoo.com> wrote in message news:<3B60B687.B08F6531@yahoo.com>...
> Hi,
> 
> I have a string var $filename = "filename.ext" and I want it to be
> turned into $filename = "filename" by removing the ".ext" How can I do
> this? I've been reading about pattern matching for an hour and can't
> find even the slightest reference the such and operation.

Its interesting to note that of the three replies that I have seen so
far to your problem only one appears to me to be correct.

Response 1:
Ron Savage (ron@savage.net.au) wrote:
>...
if ($file_name =~ /\\/)
{
 fileparse_set_fstype("MSDOS");
}
elsif ($file_name =~ /:/)
{
 fileparse_set_fstype("MacOS");
}
>...

This will parse the filename as if it was a MacOS for the valid
filename "D:filename.text".  What this means I cant say as I dont use
MacOS. (What _reasonable_ programmer would want to use one?  :-)  ) 
Although this aside using File::Basename as Ron suggested is probably
a good idea if you want reliable portable code.

Response 2:
Ala Qumsieh (qumsieh@sympatico.ca) wrote:
>...
>$filename =~ s/\.[^.]+$//;
>...

This one works, but may have problems on esoteric OS's such as MacOS.
(Hmm, i was about to say something snarky about caring and thought
better of it. Ooops... :-) )

Response 3:
Godzilla! (godzilla@stomp.stomp.tokyo) wrote:
>...
>substr ($filename, rindex ($filename, "."), 4, "");
>...

This one is a terrible solution.  If you insert the filename
"filename.text" into the filename list provided by godzilla you will
see the output (for this filename) is:'filenamet' which is definitely
wrong.  DONT use this one.


> BTW: I'm finding it very difficult to find out how to do the simplest
> things in perl. I go though the tutorials.. which seem to be written for
> people who already know the language. And I have the book Programming
> Perl by O'reilly, but it seems that I have to read like 2days each time
> I want to find out how to do the simplest thing... then I just wind up
> going to the newsgroups and asking. Is there some resource I'm missing?

For the first few months of using perl the ActiveState Web versions
and index of the perldocs was an absolute sanity saver.  No different
from using perldoc, but has an easy to use interface (the index for
instance).  My most used perldocs are: perlfunc,perlre (look here for
you problem), perlsub, perldata. perltoot and perltootc are good
places to learn some cool stuff as well.

The other thing quite frankly is READ other peoples code.  Have a look
through modules that come with the Standard Distro.  For instance I
learned a _lot_ from reading through Gurusamy Sarathy's Data::Dumper. 
Also attempting to figure out Abigail's JAPH signatures has proved to
be a good exercise (if sometimes a futile one :-) )

Cheers,
Yves
PS (Never, Never omit 'use warnings; use strict;' from your programs..
or at least not until you dont need to ask questions like these....)


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

Date: 27 Jul 2001 11:32:22 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Stripping extention from a filename in a string
Message-Id: <9jrjg6$evj$2@mamenchi.zrz.TU-Berlin.DE>

According to Jason LaPenta  <lapenta_jm@yahoo.com>:
> Hi,
> 
> I have a string var $filename = "filename.ext" and I want it to be
> turned into $filename = "filename" by removing the ".ext" How can I do
> this? I've been reading about pattern matching for an hour and can't
> find even the slightest reference the such and operation.

A number of ad-hoc solutions have been proposed.  There is also
the standard module File::Basename which does this in a portable
way.

[...]

Anno


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

Date: 27 Jul 2001 11:59:45 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Unlinking lockfiles safely  [was: Another flock question]
Message-Id: <996235054.3860@itz.pp.sci.fi>

In article <996105779.145627@hpvablab.cup.hp.com>, Richard J. Rauenzahn wrote:
>
>To synchronize correctly, I'd think you'd have to...
>
>start:
>open file (O_CREAT/O_EXCL)
>if creation failed 
>	open file
>	if success
>	   lock it
>	   remove (should usually fail with file not found)
>	   close 
>        endif
>	go back to start
>else
>	lock it
>	do stuff
>	unlink
>	close
>end
>
>This kind of puts you into a two stage lock scenario, but the flock
>attempt lets you detect and remove stale lock files.

You've still got race conditions.  In particular, a process might steal
a lockfile that has been created but not yet locked by another process.

I suppose you could check the inode numbers on the locked filehandle and
the file itself, and restart if they differ (or the file has vanished).

  do {
      open LOCK, ">$lock" or die "Can't open $lock: $!\n";
      flock LOCK, LOCK_EX or die "Can't lock $lock: $!\n";
  } until -e $lock and (stat _)[1] == (stat LOCK)[1];

  # do stuff

  unlink $lock;
  close LOCK;

There.  The first process comes along, opens and locks the file.  The
rest open it too, but will wait for a lock.  The first process unlinks
the file before unlocking it, so that the other processes, each getting
the lock in turn, notice that their filehandle is stale and rush to
reopen the file.

The odds are the processes will even get passes in FIFO order, but that
can't be guaranteed as Perl's implicit close-and-reopen isn't atomic.

Actually, *if* the untested code above passes review here, maybe it
should be added to perlfaq5?  That also means that if anyone sees any
potential problems with it, feel free to tear it apart.

-- 
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: 27 Jul 2001 03:15:10 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Where are the values stored?
Message-Id: <74f348f7.0107270215.cd1dbe8@posting.google.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<9jpegk$2u1$1@mamenchi.zrz.TU-Berlin.DE>...
> Always use strict.
> 
> Anno

Agreed.  I also always use warnings.  Ignoring either one for a
'quickie' has burned me enough times that I wrote (simple) and
proposed a 'use caution' to cover them both.  Idea lacked support for
some reason though... :-)  On the other hand I _still_ havent uploaded
it to CPAN.  Lazyness and overwork....

Yves


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

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


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