[25099] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7349 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 1 18:05:54 2004

Date: Mon, 1 Nov 2004 15:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 1 Nov 2004     Volume: 10 Number: 7349

Today's topics:
    Re: A Reg-exp compendium of frequently occuring matches <soundz@techie.com>
    Re: Code review request: a better radix sort <none@nowhere.invalid>
    Re: Convert String Containing Hex Values <cpryce@nospam.pryce.net>
        FAQ 3.30: I've read perlembed, perlguts, etc., but I ca <comdog@panix.com>
        FAQ 3.6: How do I profile my Perl programs? <comdog@panix.com>
    Re: How to handle large variable ctcgag@hotmail.com
    Re: How to handle large variable <uguttman@athenahealth.com>
        parsing output of 'lspci -t' on Linux <emschwar@pobox.com>
    Re: parsing output of 'lspci -t' on Linux (Peter Corlett)
    Re: parsing output of 'lspci -t' on Linux <emschwar@pobox.com>
        PERL 64bit Question <tyates@newsguy.com>
        Perl is awsome! <bs@research.att.com>
        perl self generating program (Yahav Bar yosef)
    Re: perl self generating program <1usa@llenroc.ude.invalid>
    Re: perl self generating program <tadmc@augustmail.com>
    Re: perl self generating program <uguttman@athenahealth.com>
    Re: perl self generating program <rwxr-xr-x@gmx.de>
        Proper quitting <nospam@nospam.com>
    Re: Proper quitting <nospam@bigpond.com>
    Re: Proper quitting <nospam@nospam.com>
        Question about Javascript and Perl form <medaugh@bellsouth.net>
    Re: Question about Javascript and Perl form <usa1@llenroc.ude.invalid>
    Re: Question: need to parse web pages to extract data (dan baker)
    Re: web hoster won't secure CGI ctcgag@hotmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 01 Nov 2004 12:16:00 -0800
From: Mark Day <soundz@techie.com>
Subject: Re: A Reg-exp compendium of frequently occuring matches?
Message-Id: <41869980.80009@techie.com>



Abigail wrote:
> Mark Day (soundz@techie.com) wrote on MMMMLXXX September MCMXCIII in
> <URL:news:4185D9A8.4030807@techie.com>:
> `'  
> `'  
> `'  Simon Taylor wrote:
> `' > Mark Day wrote:
> `' > 
> `' >> I was wondering if anyone out there had compiled a list
> `' >> of regular expressions for tasks that occur frequently such as
> `' >> stripping out HTML tags, validating IP addresses, etc.
> `' >> Is there anything like this around? If there's a link for something 
> `' >> like that, it would be very handy and helpful, thanks in advance.
> `' >>
> `' > 
> `' > Search for regexp at http://search.cpan.org and you'll see plenty
> `' > of examples under the Regexp::Common namespace.
> `' > 
> `' > Probably the best starting point is here:
> `' > 
> `' > http://search.cpan.org/~abigail/Regexp-Common-2.117/lib/Regexp/Common.pm
> `' > 
> `' > 
> `' > Regards,
> `'  
> `'  
> `'  That's great, thanks.
> `'  Looks like there are many such common tasks that could be added here.
> `'  
> 
> 
> Patches welcome.


As soon as my skills are that far along, I'd be happy to.



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

Date: Mon, 01 Nov 2004 20:22:39 GMT
From: none <none@nowhere.invalid>
Subject: Re: Code review request: a better radix sort
Message-Id: <jWwhd.1305$Ak2.45@trndny02>

Uri Guttman wrote:
 > but
> why do you want to do a radix sort on floats? unless this is just an
> exercise for you.

It's mainly just for the hell of it. Also, I finished a bunch of other 
sorts, and this is the only one I haven't done yet.


> defined() should be fine then. it uses $_ as its default argument.

That worked! Thanks!


> i would rename @nums to something else as they aren't really numbers
> anymore but the byte string that represents the (ieee) float format.

Goot point.


> ok, i see what the algorithm is. using unpack with a rotated mask is
> more work than is needed. since you are just grabbing bytes, you can use
> substr and ord to get each byte. something like this (untested):
>  			my $radix = substr( $num, $byte_num, 1);

ord substr( $num, $byte_num, 1) worked, but I don't understand why. How 
is it possible to get the numeric value directly from "pack," which is 
the number binary encoded in some obscure format?


> but maybe doing separate bins would be the best answer.

Maybe that would make more sense.

Thanks,
-Mike


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

Date: Mon, 01 Nov 2004 13:52:13 -0600
From: cp <cpryce@nospam.pryce.net>
Subject: Re: Convert String Containing Hex Values
Message-Id: <011120041352135913%cpryce@nospam.pryce.net>

In article <9dCgd.82$vB.73@trnddc03>, Jürgen Exner
<jurgenex@hotmail.com> wrote:

> > If I have a string that looks like this:
> >
> > Job_x0020_Number
> >
> > How do I turn that into:
> >
> > Job Number
> 
> What about
>     s/_.*_/ /;

My fault for not explaining the whole problem. 

MS Word allows custom datafields in their Word XML files. My users are
typically creative with them, and insert fields like:

Client ID Number
Job Number(s) 

while some would know not to include not to include non-alphnumerics,
and would write the fields as: 

client_id_or_job_number
etc. 

Word, when it saves the file as XML, translates illegal characters so
in the above example, I would get: 
        <o:Client_x0020_ID_x0020_Number dt:dt="string">
            12345
        </o:Client_x0020_ID_x0020_Number>

        <o:Job_x0020_Number_x0028_s_x0029_ dt:dt="string">
            5 and 6
        </o:Job_x0020_Number_x0028_s_x0029_>

The regex Abigail provided fits the bill nicely, as I would like to
spit out a text file with the custom data fields as: 

Client ID Number: 12345
Job Number(s): 5 and 6


Thanks to all who helped

-- 
cp


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

Date: Mon, 1 Nov 2004 17:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 3.30: I've read perlembed, perlguts, etc., but I can't embed perl in
Message-Id: <cm5q84$mta$1@reader1.panix.com>

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 Perl.

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

3.30: I've read perlembed, perlguts, etc., but I can't embed perl in

my C program; what am I doing wrong?
    Download the ExtUtils::Embed kit from CPAN and run `make test'. If the
    tests pass, read the pods again and again and again. If they fail, see
    perlbug and send a bug report with the output of "make test
    TEST_VERBOSE=1" along with "perl -V".



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

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.

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-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. 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.


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

Date: Mon, 1 Nov 2004 23:03:03 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 3.6: How do I profile my Perl programs?
Message-Id: <cm6fb7$42l$1@reader1.panix.com>

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 Perl.

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

3.6: How do I profile my Perl programs?

    You should get the Devel::DProf module from the standard distribution
    (or separately on CPAN) and also use Benchmark.pm from the standard
    distribution. The Benchmark module lets you time specific portions of
    your code, while Devel::DProf gives detailed breakdowns of where your
    code spends its time.

    Here's a sample use of Benchmark:

      use Benchmark;

      @junk = `cat /etc/motd`;
      $count = 10_000;

      timethese($count, {
                'map' => sub { my @a = @junk;
                               map { s/a/b/ } @a;
                               return @a },
                'for' => sub { my @a = @junk;
                               for (@a) { s/a/b/ };
                               return @a },
               });

    This is what it prints (on one machine--your results will be dependent
    on your hardware, operating system, and the load on your machine):

      Benchmark: timing 10000 iterations of for, map...
             for:  4 secs ( 3.97 usr  0.01 sys =  3.98 cpu)
             map:  6 secs ( 4.97 usr  0.00 sys =  4.97 cpu)

    Be aware that a good benchmark is very hard to write. It only tests the
    data you give it and proves little about the differing complexities of
    contrasting algorithms.



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

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.

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-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. 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.


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

Date: 01 Nov 2004 19:23:00 GMT
From: ctcgag@hotmail.com
Subject: Re: How to handle large variable
Message-Id: <20041101142300.608$Wa@newsreader.com>

Uri Guttman <uguttman@athenahealth.com> wrote:
> >>>>> "c" == ctcgag  <ctcgag@hotmail.com> writes:
>
>   >> What is so great about this File::Slurp module anyway?
>
>   c> In my hands, not much.  I found it marginally slower than the old
>   c> fashioned way.
>
> care to show some benchmarks?

Sorry, I can't.  I cleaned them out a few weeks ago when I get tired of
trying to guess which filename, test1.pl, test2.pl, test3.pl, etc. was
currently available for overwriting.  Anyway, I had a program which read
and processed 50,000 files.  I just commented out the processing step, then
ran it with and without the File::Slurp code, alternating a few times.
Slurp was consistently slower by a negligible amount.

> have you looked at the benchmark script
> that comes in the tarball?

Not until just now.  I just use-d it and perldoc-ed, I usually don't dig
into tarballs except in extreme circumstances.  I looked it now, though,
and it looked OK but not great, except for list slurp of Long file, which
looked aweful:

List Slurp of LONG file
                                                new_array_ref
41.3/s new                     44.0/s
new_in_anon_array       44.4/s
cpan_read_file           253/s
cpan_slurp_to_array      257/s
cpan_slurp_to_array_ref  383/s
read_file                383/s
sysread_file             387/s

But that doesn't seem right, because me benchmark would have definitley not
been as close as it was if "new" was that much worse than the old fashioned
way.

> and was that for line/record mode or scalar
> mode? return by ref or by value?

It must have been line/record to match the program I threw it into.
Also, I guess it must have been value, because I just copied the code
out whatever post it was that prompted me to do the test, and all the
posts I can find just use the value way.

> just saying it is slower is like newbies saying it doesn't work :)

Well, if you need to invoke some special option to get a performance
advantage, I'd think gushing posts would give example code with that
option already invoked.  :)

I'm not saying no one should use it or anything, but it just didn't blow my
hair back, as the saying goes.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Mon, 01 Nov 2004 14:50:25 -0500
From: Uri Guttman <uguttman@athenahealth.com>
Subject: Re: How to handle large variable
Message-Id: <m3brehnybi.fsf@lap.athenahealth.com>

>>>>> "c" == ctcgag  <ctcgag@hotmail.com> writes:

  c> looked aweful:

  c> List Slurp of LONG file
  c>                                                 new_array_ref
  c> 41.3/s new                     44.0/s
  c> new_in_anon_array       44.4/s
  c> cpan_read_file           253/s
  c> cpan_slurp_to_array      257/s
  c> cpan_slurp_to_array_ref  383/s
  c> read_file                383/s
  c> sysread_file             387/s

  c> But that doesn't seem right, because me benchmark would have
  c> definitley not been as close as it was if "new" was that much worse
  c> than the old fashioned way.

i will have to take a look at that. also the latest version has a change
to allow paragraph mode and it uses a m// instead of a split so the
benchmarks have possibly changed.

  >> and was that for line/record mode or scalar
  >> mode? return by ref or by value?

  c> It must have been line/record to match the program I threw it into.
  c> Also, I guess it must have been value, because I just copied the code
  c> out whatever post it was that prompted me to do the test, and all the
  c> posts I can find just use the value way.

when slurping a list of lines, most of the time is spent splitting up
the lines vs reading in the file. so file::slurp gains the least in that
mode. but IMO it does have a cleaner api than the normal open/list
slurp/close methods.

  >> just saying it is slower is like newbies saying it doesn't work :)

  c> Well, if you need to invoke some special option to get a
  c> performance advantage, I'd think gushing posts would give example
  c> code with that option already invoked.  :)

not much to gush over here. it is faster in almost all cases, it has a
cleaner and easier to use api and it has many options to control i/o and
error handling.

  c> I'm not saying no one should use it or anything, but it just didn't
  c> blow my hair back, as the saying goes.

well, as i said, list slurping is slower in all solutions. use it for
the better api then.

uri


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

Date: Mon, 01 Nov 2004 13:01:18 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: parsing output of 'lspci -t' on Linux
Message-Id: <eto7jp5cp9t.fsf@wilson.emschwar>

I'm trying to parse the output of 'lspci -t' on a Linux system.  This
output looks something like:

-+-[a0]-+-01.0-[a1]--+-01.0
 |      |            \-02.0
 |      \-02.0
 +-[80]-+-01.0
 |      +-02.0-[81]--+-04.0
 |      |            +-05.0
 |      |            \-06.0
 |      \-04.0
 \-[00]---00.0

[xx] is the bus number, nn.n is the PCI device.function number.  If
there is a [xx] on a line after a nn.n number, then the [xx] is the
address of a PCI<->PCI bridge.

What I'm trying to figure out is, given bus and device numbers that
identify a PCI bridge, how can I find the PCI bridge number?

I have tried:

#!/usr/bin/perl
use warnings;
use strict;

my $pci_tree;
{ local $/; $pci_tree = <DATA> }

sub get_bridge_addr
{
    my ($bus,$dev) = @_;

    if ($pci_tree =~ /^[ -]\+-          # line starts with ' ' or '-'
                      [$bus]-.*(?<!\n \+) # bus number, followed by anything
                                        # that ISN'T '^ +' (signifying a new
                                        # top-level bus number)
                      $dev.*-\[([^]])+\] # device number is always on the same
                                        # line as the bridge address
                     /smx) {
        return $1;
    }

    die ("Can't find a bus address for $bus : $dev!");
}

print "bridge address on the same line as top-level bus: [",
      get_bridge_addr('a0', '01'), "]\n";
print "bridge address on a different line: [",
      get_bridge_addr('80', '02'), "]\n";
__DATA__
-+-[a0]-+-01.0-[a1]--+-01.0
 |      |            \-02.0
 |      \-02.0
 +-[80]-+-01.0
 |      +-02.0-[81]--+-04.0
 |      |            +-05.0
 |      |            \-06.0
 |      \-04.0
 \-[00]---00.0


but I get:

Can't find a bus address for a0 : 01! at /tmp/bah line 22, <DATA> line 1.

I've been staring at this regex for approximately forever, and though
I'm certain there's a blindingly obvious bug in it, I can't find
it. (Obviously, or I wouldn't have posted here!)  Suggestions,
comments, boots to da head are all welcome.

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: 01 Nov 2004 20:15:19 GMT
From: abuse@dopiaza.cabal.org.uk (Peter Corlett)
Subject: Re: parsing output of 'lspci -t' on Linux
Message-Id: <41869957$0$231$5a6aecb4@news.aaisp.net.uk>

Eric Schwartz <emschwar@pobox.com> wrote:
[...]
> I've been staring at this regex for approximately forever, and
> though I'm certain there's a blindingly obvious bug in it, I can't
> find it. (Obviously, or I wouldn't have posted here!) Suggestions,
> comments, boots to da head are all welcome.

Wouldn't it be easier to attempt to parse the output of "lspci -m -M"
instead?

-- 
PGP key ID E85DC776 - finger abuse@mooli.org.uk for full key

Please contribute to the beer fund and a tidier house:
http://cgi6.ebay.co.uk/ws/eBayISAPI.dll?ViewSellersOtherItems&userid=pndc


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

Date: Mon, 01 Nov 2004 13:22:34 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: parsing output of 'lspci -t' on Linux
Message-Id: <etoy8hlb9px.fsf@wilson.emschwar>

abuse@dopiaza.cabal.org.uk (Peter Corlett) writes:
> Eric Schwartz <emschwar@pobox.com> wrote:
> [...]
>> I've been staring at this regex for approximately forever, and
>> though I'm certain there's a blindingly obvious bug in it, I can't
>> find it. (Obviously, or I wouldn't have posted here!) Suggestions,
>> comments, boots to da head are all welcome.
>
> Wouldn't it be easier to attempt to parse the output of "lspci -m -M"
> instead?

Maybe; I'm not sure how that handles multiple PCI domains, though.
Running it on a single-domain system gives me only something like:

40: Secondary host bus (?)
        01.0 Bridge to 41-41
41: Entered via 40:01.0
80: Secondary host bus (?)
        01.0 Bridge to 81-81

Which is highly useful, but I need to find a multiple-domain system
that I can check this on.  Thanks for the tip, I didn't know that was
there!

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: Mon, 01 Nov 2004 17:14:42 -0500
From: Sparky <tyates@newsguy.com>
Subject: PERL 64bit Question
Message-Id: <9scdo05ef13vjgcg5t6654brsrnte0h8o0@4ax.com>

Ok, I've recompiled and now this is what I see, below (no
use_long_double).  I believe this is now 64bit, can someone state
otherwise?  However, I'm concerned that I cannot configure using the
option "uselongdouble" as I get

modfl() found.

modfl() prototype NOT found.
Checking to see whether your modfl() is okay for large values...
I don't understand your modfl() at all.

*** You requested the use of long doubles but you do not seem to have
*** the following mathematical functions needed for long double
support:
***     modfl
*** Please rerun Configure without -Duselongdouble and/or
-Dusemorebits.
*** Cannot continue, aborting.

anyone get 5.8.2 to compile on AIX 5.1 with long double?

(no use_long_double)

 ./perl -Ilib -V

Summary of my perl5 (revision 5.0 version 8 subversion 2)
configuration:
  Platform:
    osname=aix, osvers=5.1.0.0, archname=aix-64all
    uname='aix s11f30n01 1 5 0029449a4c00 '
    config_args='-Dprefix=/gpfs/database/dba/utilities/perl582-tru64
-Duse64bitall -Aprepend:libswanted=C128 '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=define uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc -qnolm', ccflags ='-D_ALL_SOURCE -D_ANSI_C_SOURCE
-D_POSIX_SOURCE -qmaxmem=16384 -qnoansialias -DUSE_NATIVE_DLOPEN -q64
-DUSE_64_BIT_ALL -q64',
    optimize='-O',
    cppflags=''
    ccversion='6.0.0.0', gccversion='', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=87654321
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
    ivtype='long long', ivsize=8, nvtype='double', nvsize=8,
Off_t='off_t',
lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='ld', ldflags ='-brtl -L/usr/local/lib -q64 -b64'
    libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib
    libs=-lC128 -lbind -lnsl -ldbm -ldl -lld -lm -lcrypt -lc -lbsd
    perllibs=-lC128 -lbind -lnsl -ldl -lld -lm -lcrypt -lc -lbsd
    libc=/lib/libc.a, so=a, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_aix.xs, dlext=so, d_dlsymun=undef, ccdlflags='
-bE:/gpfs/database/dba/utilities/perl582-tru64/lib/5.8.2
/aix-64all/CORE/perl.exp'
    cccdlflags=' ', lddlflags='-b64  -bhalt:4 -bM:SRE
-bI:$(PERL_INC)/perl.exp -bE:$(BASEEXT).exp -bnoentry -lc
-L/usr/local/lib'


Characteristics of this binary (from libperl):
  Compile-time options: USE_64_BIT_INT USE_64_BIT_ALL USE_LARGE_FILES
  Built under aix
  Compiled at Nov  1 2004 15:43:24
  @INC:
    lib
    /gpfs/database/dba/utilities/perl582-tru64/lib/5.8.2/aix-64all
    /gpfs/database/dba/utilities/perl582-tru64/lib/5.8.2
    /gpfs/database/dba/utilities/perl582-tru64/lib/site_perl/5.8.2
/aix-64all
    /gpfs/database/dba/utilities/perl582-tru64/lib/site_perl/5.8.2
    /gpfs/database/dba/utilities/perl582-tru64/lib/site_perl
    .


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

Date: Mon, 01 Nov 2004 22:26:13 -0000
From: Bjarne Stroustrup <bs@research.att.com>
Subject: Perl is awsome!
Message-Id: <10ode051dl0hq9a@news.supernews.com>

Scalars, arrays, hashes, references, modules...
Perl is so cool!  Why didn't I think of it?

How about Perl++?

B 




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

Date: 1 Nov 2004 08:32:36 -0800
From: yahavbaryosef@hotmail.com (Yahav Bar yosef)
Subject: perl self generating program
Message-Id: <f98582b7.0411010832.7a29dbe6@posting.google.com>

Anyone has something shorter than this ?

****************************************

#!/usr/bin/perl
open(F,$0);print<F>


****************************************

Yahav bar yosef


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

Date: 1 Nov 2004 16:44:19 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: perl self generating program
Message-Id: <Xns9594776A32483asu1cornelledu@132.236.56.8>

yahavbaryosef@hotmail.com (Yahav Bar yosef) wrote in 
news:f98582b7.0411010832.7a29dbe6@posting.google.com:

> Anyone has something shorter than this ?
> 
 ...
> #!/usr/bin/perl
> open(F,$0);print<F>

Bleh!

http://libarynth.f0.am/cgi-bin/twiki/view/Libarynth/SelfGOL

Sinan.


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

Date: Mon, 1 Nov 2004 11:01:48 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: perl self generating program
Message-Id: <slrncocqvs.q0m.tadmc@magna.augustmail.com>

Yahav Bar yosef <yahavbaryosef@hotmail.com> wrote:

> Anyone has something shorter than this ?
> 
> ****************************************
> 
> #!/usr/bin/perl
> open(F,$0);print<F>


Sure, an empty file is a shorter "quine" than that one is.

:-)


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


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

Date: Mon, 01 Nov 2004 14:51:56 -0500
From: Uri Guttman <uguttman@athenahealth.com>
Subject: Re: perl self generating program
Message-Id: <m37jp5ny8z.fsf@lap.athenahealth.com>

>>>>> "TM" == Tad McClellan <tadmc@augustmail.com> writes:

  TM> Yahav Bar yosef <yahavbaryosef@hotmail.com> wrote:
  >> Anyone has something shorter than this ?
  >> 
  >> ****************************************
  >> 
  >> #!/usr/bin/perl
  >> open(F,$0);print<F>


  TM> Sure, an empty file is a shorter "quine" than that one is.

and that isn't an 'official' quine as it cheats and accesses its own
source. there is a site (was that posted already in this thread?) with
short quines in many languages.

uri


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

Date: 1 Nov 2004 22:57:15 GMT
From: Lukas Mai <rwxr-xr-x@gmx.de>
Subject: Re: perl self generating program
Message-Id: <cm6f0b$dq4$1@wsc10.lrz-muenchen.de>

Yahav Bar yosef schrob:
> Anyone has something shorter than this ?

> ****************************************

> #!/usr/bin/perl
> open(F,$0);print<F>


open 0;print<0>

HTH, Lukas
-- 
use warnings; use strict; 
BEGIN{*'_ =sub {print@_}}_"l";END  {_"h";INIT {_"P";CHECK{_" ";BEGIN{_"s";
CHECK{_"n";INIT{_"r";END{_"k";BEGIN{_"J";CHECK{_"t";END  {_"r";INIT {_"e"}
_", "}_"h"}_"u"}_"e"}_" "}_"o"}_"t" }_"a"     }_"e";END  {_"c"}_"r" }_"a"}_" "


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

Date: Mon, 1 Nov 2004 16:59:12 -0500
From: "daniel kaplan" <nospam@nospam.com>
Subject: Proper quitting
Message-Id: <1099346414.112693@nntp.acecape.com>

sorry, but have to ask, as if this is asnwered directly in the FAQ i missed
it.

when my Perl program terminates, is there anything i "must" free?  it just
doesn't seem it.  and i love that, but the world i came from (windows) you
really needed to be dilligent about cleaning up after yourself.  so i guess
i just really needed to be sure about those situations here in Perl, between
using "my", creating, references, etc.

the closest i came to finding was this "How can I free an array or hash so
my program shrinks?" but that didn't answer my question directly.

thanks ahead.

daniel




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

Date: Tue, 02 Nov 2004 08:18:01 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Proper quitting
Message-Id: <2unr0sF2ctk3bU1@uni-berlin.de>

daniel kaplan wrote:

> sorry, but have to ask, as if this is asnwered directly in the FAQ i
> missed it.
> 
> when my Perl program terminates, is there anything i "must" free?  it just
> doesn't seem it.  and i love that, but the world i came from (windows) you
> really needed to be dilligent about cleaning up after yourself.  so i
> guess i just really needed to be sure about those situations here in Perl,
> between using "my", creating, references, etc.
> 
> the closest i came to finding was this "How can I free an array or hash so
> my program shrinks?" but that didn't answer my question directly.
> 
> thanks ahead.
> 
> daniel

If you're using a real operating system (linux/bsd/unix) you dont need to
free anything after program termination.

The toys that Microsoft makes (I don't call them operating systems) trace
their heritage back to CP/M http://en.wikipedia.org/wiki/CP/M which were
nothing more than glorified program loaders. 

gtoomey


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

Date: Mon, 1 Nov 2004 17:43:38 -0500
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: Proper quitting
Message-Id: <1099349080.543212@nntp.acecape.com>

"Gregory Toomey" <nospam@bigpond.com> wrote in message
news:2unr0sF2ctk3bU1@uni-berlin.de...
> If you're using a real operating system (linux/bsd/unix) you dont need to
> free anything after program termination.
>
i assumed as much, but had to make sure,

thanks




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

Date: Mon, 1 Nov 2004 12:17:12 -0500
From: "Scott Medaugh" <medaugh@bellsouth.net>
Subject: Question about Javascript and Perl form
Message-Id: <cm5r6r$otf$1@inntp-m1.news.aol.com>


From: "Scott Medaugh" <medaugh@bellsouth.net>
Subject: Question about Javascript and Perl form
Date: Monday, November 01, 2004 12:15 PM

Hello,

I am trying to do something unusual and it has me stumped.  I am looking to
change the Env variable for RemoteUser essentially.  What I would like to
happen is that the user would choose a name from the dropdown box populated
by the list in test.txt.  Once the user chooses that name, the home
directory is then pointed to the chosen name and the user is able to see the
files listed in the new directory.  I have included the snippet that I have
been trying to accomplish this with and would gladly appreciate some
feedback on how to make this happen.




#my $user_file = "/Volumes/data01/cgi-bin/rem_user.txt";
my $user_file = "test.txt";

# The code sections generate the pulldown boxes in the slug form.
#
# Freeform fields are populated from cookies with inline perl.
#

print $query->header ( );

print <<END_HTML;

<HTML>
<head>

<script language="JavaScript">

        function changeUser(user){
         remoteuser = $user;
         homedir = "/Volumes/data01/Users/$remoteuser";
         alert("$homedir");

         }



</script>

<link rel="stylesheet" href="/catch.css" type="text/css" />
</head>
<body>
<div id="Header">
<div id="MainText">

<form action="/cgi-bin/slugreg"
enctype="multipart/form-data" name="dataBuild" onSubmit="return
verify(this.form)" method="post">

<h3> SLUG ENTRY FORM</h3>

<table>
<tr><td>
<span  CLASS="intable">
Select User Name:
</td><td>


END_HTML

############################################################################
###########################
###Start Media Manager special###

open (REMUSER, "$user_file") || Error('open','file');
#read (REMUSER);
my @users = <REMUSER>;

close (REMUSER);

print "<select name='uname'>\n";
foreach (@users){
 print "<option value='$_'>$_'";
 }

print "</select>\n";

sub Error {
 print "Content type: text/html\n\n";
 print "The server cannot $_[0] the $_[1]: $! \n";
 exit;
 }
############################################################################
##########################

print <<END_HTML;
</td><td>
<input type="button" name="test" value="Change User!"
onClick="changeUser(document.dataBuild.uname.options[document.dataBuild.unam
e.selectedIndex].value)">
</td></tr>

<tr><td>
<span  CLASS="intable">
Select File You've Uploaded:
</td><td>
<select name="photo">

END_HTML

# -------------------------------- code /
html ---------------------------------

# This code generates a list of files in their home directory for the file
pulldown box

opendir(DIRHANDLE, "$homedir");
while ($name = readdir(DIRHANDLE)) {
 open(FILEHANDLE, "$homedir/$name");
 if ((-f FILEHANDLE) and ($name ne ".htaccess") and ($name ne ".DS_Store"))
{

 print "<option value='$name'>$name\n";
#end if
}
#end while
}





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

Date: 1 Nov 2004 18:15:00 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: Question about Javascript and Perl form
Message-Id: <Xns959486C91A4B8asu1cornelledu@132.236.56.8>

"Scott Medaugh" <medaugh@bellsouth.net> wrote in
news:cm5r6r$otf$1@inntp-m1.news.aol.com: 

> From: "Scott Medaugh" <medaugh@bellsouth.net>
> Subject: Question about Javascript and Perl form
> Date: Monday, November 01, 2004 12:15 PM

No need to repeat this information in the body of your post. 

> I am trying to do something unusual and it has me stumped.  I am
> looking to change the Env variable for RemoteUser essentially. 

Your question is related to CGI and web server configuration and not to 
Perl specifically. You should post in the appropriate groups.

Incidentally, I am not sure what you mean by RemoteUser. There is an 
environment variable REMOTE_USER set by the web server upon successful 
basic authentication. See:

http://cgi-spec.golux.com/draft-coar-cgi-v11-03-clean.html#6.1.12

> would like to happen is that the user would choose a name from the
> dropdown box populated by the list in test.txt.  Once the user chooses
> that name, the home directory is then pointed to the chosen name and
> the user is able to see the files listed in the new directory.

You'll need to partition/explain your problem better.

use strict;
use warnings;

> #my $user_file = "/Volumes/data01/cgi-bin/rem_user.txt";
> my $user_file = "test.txt";

 ...

In the code below, I do not see any effort to untaint the incoming 
variable.

perldoc perlsec

> open (REMUSER, "$user_file") || Error('open','file');

perldoc -q always quote

Found in C:\Perl\lib\pod\perlfaq4.pod
  What's wrong with always quoting "$vars"?

> sub Error {
>  print "Content type: text/html\n\n";
>  print "The server cannot $_[0] the $_[1]: $! \n";
>  exit;
>  }

This is really, really not necessary or even useful:

1. You have already sent a header above.

2. die together with CGI::Carp does this right

> #######################################################################
> ##### ##########################
> 
> print <<END_HTML;
> </td><td>
> <input type="button" name="test" value="Change User!"
> onClick="changeUser(document.dataBuild.uname.options[document.dataBuild
> .unam e.selectedIndex].value)">
> </td></tr>

This whole mixing HTML, Javascript and Perl together thing is making it 
very hard (at least for me) to follow what you are trying to accomplish. I 
am going to suggest HTML::Template.

> # This code generates a list of files in their home directory for the
> file pulldown box
> 
> opendir(DIRHANDLE, "$homedir");
> while ($name = readdir(DIRHANDLE)) {
>  open(FILEHANDLE, "$homedir/$name");
>  if ((-f FILEHANDLE) and ($name ne ".htaccess") and ($name ne
>  ".DS_Store")) 

Again, you are trying to deal with something that should be a web server 
configuration issue. Also, since you have not untainted the $name variable, 
this will pretty much echo any file on your server. 

Sinan.


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

Date: 1 Nov 2004 13:39:17 -0800
From: botfood@yahoo.com (dan baker)
Subject: Re: Question: need to parse web pages to extract data
Message-Id: <13685ef8.0411011339.734739bf@posting.google.com>

"Troll" <abuse@microsoft.com> wrote in message news:<102hd.5249$K7.1478@news-server.bigpond.net.au>...

> What I'm trying to do is to extract price info 
---------

try module LWP::Simple and get() to grab the source... then extract
what you want....

d


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

Date: 01 Nov 2004 19:55:15 GMT
From: ctcgag@hotmail.com
Subject: Re: web hoster won't secure CGI
Message-Id: <20041101145515.765$DX@newsreader.com>

ioneabu@yahoo.com (wana) wrote:
> According to Lincoln Stein's book on CGI.pm, to make CGI safe, you
> have to make configuration changes at the beginning of the CGI.pm
> file.  I asked my web hosting company if they had made these changes
> to protect me from multi-megabyte uploads or large entries in
> textfields and they told me that they make no changes to Perl modules
> and I have no access to it myself.

I am not an expert on this, but I believe that the OS provides the
capabilities to limit user processes in various which, if employed, would
be just as effective against mult-megabyte uploads as the changes to CGI
would be.  (And would also protect against other things that changing CGI
does not.)

> Is there another way to provide this protection?

You can do it yourself as described in the docs, but that only protects you
against DOS aimed at you.  DOS aimed you co-hostees could still take you
down along with the intended target.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 7349
***************************************


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