[22287] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4508 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 4 00:21:49 2003

Date: Mon, 3 Feb 2003 21:20: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, 3 Feb 2003     Volume: 10 Number: 4508

Today's topics:
    Re: Parse a logfile - 1st column DateStamp; extract lat <spam@thecouch.homeip.net>
        Patent perl nonsense... (Curious rabbit)
    Re: Patent perl nonsense... (Sara)
    Re: Patent perl nonsense... <goldbb2@earthlink.net>
    Re: Patent perl nonsense... <nospam-abuse@ilyaz.org>
    Re: perl simple script <jurgenex@hotmail.com>
    Re: perl simple script (h\)
    Re: perl simple script (zr)
    Re: perl simple script <abigail@abigail.nl>
    Re: Perl standalone programms and copyright <mgjv@tradingpost.com.au>
        perlfaq4.pod - question re. pack examples (Lee Goddard)
    Re: perlfaq4.pod - question re. pack examples (Anno Siegel)
    Re: perlfaq4.pod - question re. pack examples (Ben Morrow)
    Re: purpose of threads? <"456#$_invalid"@yahoo.co.uk>
        read web content (Chas Friedman)
    Re: read web content <stuart@spidersoft.co.uk>
    Re: Regex help (Michael Robbins)
        sort, my concoction of <istink@real.bad.com>
    Re: sort, my concoction of <uri@stemsystems.com>
        strange localtime return (Shadowfax)
    Re: Tainting individual variables <cingram@pjocsNOSPAMORHAM.demon.co.uk>
    Re: Tainting individual variables <nobull@mail.com>
    Re: Tainting individual variables (Lack Mr G M)
    Re: what's the best book for learning perl? <mgjv@tradingpost.com.au>
    Re: what's the best book for learning perl? <tassilo.parseval@post.rwth-aachen.de>
    Re: what's the best book for learning perl? <mgjv@tradingpost.com.au>
    Re: what's the best book for learning perl? <swen@news.com>
        where is GD::Font::Small defined? (jerron)
    Re: where is GD::Font::Small defined? <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 03 Feb 2003 20:19:31 -0500
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: Parse a logfile - 1st column DateStamp; extract latest mods toan ItemNumber
Message-Id: <DyE%9.26466$k52.435676@wagner.videotron.net>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1



Benjamin Goldberg wrote:
| Mina Naguib wrote:
| [snip]
|
|>| TimeStamp in YYYYMMDDHHMMSS
|>| format|ItemNumber|Attribute1|Attribute2|Attribute3
|>|
|>| Sample Input File
|>| 20020731114502|0144058Y01|CHRM|LHSG|MISC
|>| 20030109174500|0144058Y01|PLAS|RHSG|MISC
|
| [snip]
|
|>If you want it sorted by the item id as in your "desired output":
|>
|>perl -naF'\|' -e '$i{$F[1]} = $_ if ($F[0] > $i{$F[1]});
|>END {map {print $i{$_}} sort keys %i}' infilename > outfilename
|
|
| There's no need for the map{} there:
|
|    perl -naF'\|' \
|       -e '$i{$F[1]} = $_ if $F[0] > $i{$F[1]};'
|       -e 'END {print @i{sort keys %i}}' \
|       infilename > outfilename
|
| See perldoc perldata for more info on hash slices.

Very clever. I've never used hash slices before.  I like!

Thanks Benjamin.



-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE+PxUjeS99pGMif6wRAkPjAJ9I3Ane/4Fyl0h2mcPNgXhLv7XdQwCgjDUl
QgV6MdbX9TMu9oFQXuvGuuQ=
=oeTt
-----END PGP SIGNATURE-----



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

Date: 3 Feb 2003 06:40:34 -0800
From: rabbits_in_golden_gate_park@hotmail.com (Curious rabbit)
Subject: Patent perl nonsense...
Message-Id: <f999f733.0302030640.68bfb35b@posting.google.com>

Anyone seen this one yet? US Patent Application 6,513,153.
"Automatically integrating and executing application software
modules."  http://patft.uspto.gov/netahtml/srchnum.htm and key in the
patent # given above.  Having read it a few times now, this successful
patent application seems nothing more than a fudge of 'use'. Or is
there really something new, original or innovative (or even
worthwhile) in there?  Rabbit.


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

Date: 3 Feb 2003 13:00:44 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: Patent perl nonsense...
Message-Id: <776e0325.0302031300.6a119051@posting.google.com>

rabbits_in_golden_gate_park@hotmail.com (Curious rabbit) wrote in message news:<f999f733.0302030640.68bfb35b@posting.google.com>...
> Anyone seen this one yet? US Patent Application 6,513,153.
> "Automatically integrating and executing application software
> modules."  http://patft.uspto.gov/netahtml/srchnum.htm and key in the
> patent # given above.  Having read it a few times now, this successful
> patent application seems nothing more than a fudge of 'use'. Or is
> there really something new, original or innovative (or even
> worthwhile) in there?  Rabbit.

Hi there Rabbit. Yes, that's what it looks like to me. Of course it
took a whole lot of pages just to say that, but as far as I can tell
it sort of looks like "require". If this application prevails, I may
file:

      "sub, a Unique Approach to Designate and Encapsulate Code
Blocks"

Yes!! I can see the royalties pouring in now!

-Gx


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

Date: Mon, 03 Feb 2003 19:35:27 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Patent perl nonsense...
Message-Id: <3E3F0ACF.4B624330@earthlink.net>

Curious rabbit wrote:
> 
> Anyone seen this one yet? US Patent Application 6,513,153.
> "Automatically integrating and executing application software
> modules."  http://patft.uspto.gov/netahtml/srchnum.htm and key in the
> patent # given above.  Having read it a few times now, this successful
> patent application seems nothing more than a fudge of 'use'. Or is
> there really something new, original or innovative (or even
> worthwhile) in there?  Rabbit.

Hmm, actually "electing, for execution from a pool of software modules,
a plurality of software modules that satisfy a first criterion," with
the emphasis on the word "plurality".

It's sortof like doing:

   use ModulesWhichMatchRegexp qr/^LWP::/;

AFAIK, no such thing currently exists for perl, though of course you
could write one.  Well, you could write one if it didn't violate the
patent.

-- 
"So, who beat the clueless idiot today?"
"Well, we flipped for it, but when Kuno
 landed, he wasn't in any shape to fight."
"Next time, try flipping a *coin.*"


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

Date: Tue, 4 Feb 2003 00:38:32 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Patent perl nonsense...
Message-Id: <b1n228$132n$1@agate.berkeley.edu>

[A complimentary Cc of this posting was NOT [per weedlist] sent to
Benjamin Goldberg 
<goldbb2@earthlink.net>], who wrote in article <3E3F0ACF.4B624330@earthlink.net>:
> > Anyone seen this one yet? US Patent Application 6,513,153.
> > "Automatically integrating and executing application software
> > modules."  http://patft.uspto.gov/netahtml/srchnum.htm and key in the
> > patent # given above.  Having read it a few times now, this successful
> > patent application seems nothing more than a fudge of 'use'. Or is
> > there really something new, original or innovative (or even
> > worthwhile) in there?  Rabbit.
> 
> Hmm, actually "electing, for execution from a pool of software modules,
> a plurality of software modules that satisfy a first criterion," with
> the emphasis on the word "plurality".
> 
> It's sortof like doing:
> 
>    use ModulesWhichMatchRegexp qr/^LWP::/;
> 
> AFAIK, no such thing currently exists for perl

See, e.g., Term::ReadLine.

Hope this helps,
Ilya


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

Date: Mon, 03 Feb 2003 16:33:02 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: perl simple script
Message-Id: <2Rw%9.453$lm4.131@nwrddc01.gnilink.net>

zr wrote:
> hi,
>
> I work in java, I have to program a very basic perl scipt. I have
> never done anything in perl, but I hoped the script is so simple, it
> would only take me an hour at
> most...but I have already spent an hour with no results. I am sure
> perl is great, but as I dont intend to need perl in the near future,
> investing the
> time needed to follow a tutorial etc would not pay off.
> So I hope someone can invest a minute to program my script...
> -input params: a filename, and a regexp expresion

perldoc perlvar (pay particular attention to @ARGV )
perldoc perlre or perldoc perlretut

> -output: boolean indication wether the regexp is contianed in the file

perldoc -f open
perldoc perlop (pay attention to the m operator)
maybe perldoc perlsyn

jue




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

Date: Mon, 3 Feb 2003 19:00:01 +0100
From: "Michael Peuser \(h\)" <post@mpeuser.de>
Subject: Re: perl simple script
Message-Id: <b1mal6$d69$03$1@news.t-online.com>


"zr" <zabo@mixmail.com> schrieb im Newsbeitrag
news:70ac9e9a.0302030128.20fb5e10@posting.google.com...

> I work in java,

I wonder what you _do_ in java .....

> ... but as I dont intend to need perl in the near future,
> investing the
> time needed to follow a tutorial etc would not pay off.

Kindly Mike






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

Date: 3 Feb 2003 10:09:15 -0800
From: zabo@mixmail.com (zr)
Subject: Re: perl simple script
Message-Id: <70ac9e9a.0302031009.78a162c8@posting.google.com>

It was 'suggested' by the client to do it in perl, and I was told
perl's regexp is more powerfull than grep's (the regexp can be
complicated). But maybe it could work just with a grep...

Thanks to all (not to you, Tassilo, get a life), I guess I will use
Tonys 1 line code.


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

Date: 03 Feb 2003 19:29:26 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: perl simple script
Message-Id: <slrnb3tgom.8fm.abigail@alexandra.abigail.nl>

zr (zabo@mixmail.com) wrote on MMMCDXLIII September MCMXCIII in
<URL:news:70ac9e9a.0302030128.20fb5e10@posting.google.com>:
{}  hi,
{}  
{}  I work in java, I have to program a very basic perl scipt. I have
{}  never done anything in perl, but I hoped the script is so simple, it
{}  would only take me an hour at
{}  most...but I have already spent an hour with no results. I am sure
{}  perl is great, but as I dont intend to need perl in the near future,
{}  investing the
{}  time needed to follow a tutorial etc would not pay off. 
{}  So I hope someone can invest a minute to program my script...
{}  -input params: a filename, and a regexp expresion
{}  -output: boolean indication wether the regexp is contianed in the file


    system grep => reverse @ARGV;
    print !$?;


Abigail
-- 
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'


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

Date: Mon, 03 Feb 2003 22:32:55 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Perl standalone programms and copyright
Message-Id: <slrnb3trgn.se5.mgjv@verbruggen.comdyn.com.au>

On Sun, 02 Feb 2003 12:47:21 -0500,
	Andrew Lee <> wrote:
> On Sun, 02 Feb 2003 12:04:11 +0100, Ingo Wiarda <Ingo_Wiarda@web.de>
> wrote:

>>May I
>>a) freely distribute such a package?
>>b) sell the package?
> 
> If you include the source ... read the GNU copyleft.

But if the module is distributed with a license that differs from the
GNU ones, read it, instead of the GNU copyleft. Most modules on CPAN
[1] actually do not use the GNU licenses.

Martien

[1] at least, most modules that I've ever checked the copyright of...
-- 
                        | 
Martien Verbruggen      | 
Trading Post Australia  | What's another word for Thesaurus?
                        | 


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

Date: 3 Feb 2003 09:25:51 -0800
From: nospam@leegoddard.com (Lee Goddard)
Subject: perlfaq4.pod - question re. pack examples
Message-Id: <e0d7abe8.0302030925.59507564@posting.google.com>

(Also posted on comp.lang.perl)

Why does this, taken straight from perlfaq4.pod 
in build 633, produce the output listed at the 
__END__? I read it that the two examples would
produce identical output, and they don't: is
there something I should know?

Thanks
lee

# Found in C:\Lang\Perl633\lib\pod\perlfaq4.pod
#  How do I convert bits into ints?
#
#	To turn a string of 1s and 0s like "10110110" into a scalar
#	containing its binary value, use the pack() and unpack()
#	functions (documented in the section on "pack" in the perlfunc
#	manpage and the section on "unpack" in the perlfunc manpage):

		$decimal = unpack('c', pack('B8', '10110110'));

warn $decimal,"\n";

#	This packs the string "10110110" into an eight bit binary
#	structure. This is then unpacked as a character, which returns
#	its ordinal value.
#
#	This does the same thing:

		$decimal = ord(pack('B8', '10110110'));
warn $decimal,"\n";

#	Here's an example of going the other way:

		$binary_string = unpack('B*', "\x29");
warn $binary_string,"\n";

__END__

-74
182
00101001


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

Date: 3 Feb 2003 18:37:29 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perlfaq4.pod - question re. pack examples
Message-Id: <b1mct9$4ej$1@mamenchi.zrz.TU-Berlin.DE>

Lee Goddard <nospam@leegoddard.com> wrote in comp.lang.perl.misc:
> (Also posted on comp.lang.perl)

comp.lang.perl is dead.  Only ghosts live there.

> Why does this, taken straight from perlfaq4.pod 
> in build 633, produce the output listed at the 
> __END__? I read it that the two examples would
> produce identical output, and they don't: is
> there something I should know?
> 
> Thanks
> lee
> 
> # Found in C:\Lang\Perl633\lib\pod\perlfaq4.pod
> #  How do I convert bits into ints?
> #
> #	To turn a string of 1s and 0s like "10110110" into a scalar
> #	containing its binary value, use the pack() and unpack()
> #	functions (documented in the section on "pack" in the perlfunc
> #	manpage and the section on "unpack" in the perlfunc manpage):
> 
> 		$decimal = unpack('c', pack('B8', '10110110'));
> 
> warn $decimal,"\n";
> 
> #	This packs the string "10110110" into an eight bit binary
> #	structure. This is then unpacked as a character, which returns
> #	its ordinal value.
> #
> #	This does the same thing:
> 
> 		$decimal = ord(pack('B8', '10110110'));
> warn $decimal,"\n";
> 
> #	Here's an example of going the other way:
> 
> 		$binary_string = unpack('B*', "\x29");
> warn $binary_string,"\n";
> 
> __END__
> 
> -74
> 182
> 00101001

Those two numbers are really the same, mod 256.  They represent the
same pattern of bits in a byte, but one is interpreted as a signed
binary, the other is unsigned.

Anno


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

Date: Mon, 3 Feb 2003 18:43:35 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: perlfaq4.pod - question re. pack examples
Message-Id: <b1md8n$40m$1@wisteria.csv.warwick.ac.uk>

nospam@leegoddard.com (Lee Goddard) wrote:
>(Also posted on comp.lang.perl)

I shouldn't, it doesn't exist any more.

>Why does this, taken straight from perlfaq4.pod 
>in build 633, produce the output listed at the 
>__END__? I read it that the two examples would
>produce identical output, and they don't: is
>there something I should know?
>
<snip comments>
>
>		$decimal = unpack('c', pack('B8', '10110110'));
>
>warn $decimal,"\n";
>
<and again>
>
>		$decimal = ord(pack('B8', '10110110'));
>warn $decimal,"\n";
>
>#	Here's an example of going the other way:
>
>		$binary_string = unpack('B*', "\x29");
>warn $binary_string,"\n";
>
>__END__
>
>-74
>182
>00101001

You need to read perldoc -f pack. 'c' unpacks a signed char, whereas ord is
producing an unsigned char. unpack will give you an unsigned char with 'C'.

Ben


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

Date: Mon, 03 Feb 2003 22:07:58 -0500
From: L D Jones <"456#$_invalid"@yahoo.co.uk>
Subject: Re: purpose of threads?
Message-Id: <3E3F2E8E.C873713B@yahoo.co.uk>

jake johnson wrote:
> 
> Juha Laiho <Juha.Laiho@iki.fi> wrote in message news:<b19aod$e7i$1@ichaos.ichaos-int>...
> > jake@omnimode.com (jake johnson) said:
> > >I'm a relative perl newbie.  I'm looking to advance my skills though
> > >and one of the things I keep bumping into is this idea of threads.  I
> > >understand that they are needed mostly in server applications, right?
> >
> > They're very usable in client applications as well.
> >
> > >[...] This has piqued my curiosity about what threads are and why
> > >people are aching to use them. I haven't been able to find any 'threads
> > >for newbies' discussions,
> >
> > ... perhaps beause threads are not for newbies. In addition to being
> > a good tool, they also can be a great source of frustration.
> >
> > >For one thing, are threads an alternative to fork?
> >
> > In a way, yes. They're multiple simultaneous execution units. But threads
> > operate within a single process, so they all share the same memory space,
> > for example.
> >
> > Where threads fit are situations where you're doing multiple tasks
> > simultaneously (in parallel), and the tasks have much data to interchange
> > with each other. You could do this with several processes and various
> > forms of IPC, too, but communication between processes is expensive
> > in terms of CPU use. So, threads lower the CPU utilization by reducing
> > the need for IPC, and can also reduce communications latency when
> > compared to multiple processes exchanging data.
> >
> > I hope this gives you a starting point.
> 
> Thanks everyone for their answers.  Regarding threads, you often hear
> Perl vs. Java, but its not to be forgotten that Python apparently has
> excellent threads support also, right?

Forget about Perl v java. Read the 2 FAQs for comp.programming.threads
to get an idea of some of the interesting topics in threads programming
(that are likely to apply to any implementation).


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

Date: Mon, 3 Feb 2003 22:52:33 +0000 (UTC)
From: friedman@math.utexas.edu (Chas Friedman)
Subject: read web content
Message-Id: <b1mrrh$5uh$1@geraldo.cc.utexas.edu>



__________
You wrote:
>I would like to write a script to read the content of
>Web page, and copy it to a file *.txt for later use
>such as filtering or putting it in a string?
>can any one help? if not ignore me !
>
>
>-Pons
>pons@gmx.li
>
 I've used the following:

use LWP::Simple;
print $html = get($url=shift);

 Probably you should check for errors (e.g., see if $html is defined). 
This prints to standard output, but you can redirect to a file.
                      chas



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

Date: Mon, 03 Feb 2003 16:16:29 +0000
From: Stuart Marshall <stuart@spidersoft.co.uk>
Subject: Re: read web content
Message-Id: <b1m4kl$140l0f$1@ID-142465.news.dfncis.de>

Pons wrote:

> I would like to write a script to read the content of
> Web page, and copy it to a file *.txt for later use
> such as filtering or putting it in a string?
> can any one help? if not ignore me !

http://www.perlfaq.com/cgi-bin/view?view_by_id=69

Regards,

Stuart.



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

Date: 3 Feb 2003 06:25:09 -0800
From: michael.robbins@us.cibc.com (Michael Robbins)
Subject: Re: Regex help
Message-Id: <c6c65b14.0302030625.4078e6fd@posting.google.com>

Thanks for your response.

> > I have a large file that consists of many lines concatenated together.
> > 
> > Each author's name appears at the beginning of his message (a bunch of
> > lines) followed by another author's name and more lines, etc.
> 
> How do you know that you are looking at another author's name and not
> part of the first author's message.

> > I have a regex to find the author's name in a line.

I have several Regex's that solve this problem.  The author's name is
always in one of several distinct formats.

> > I slurp in the file
> > 
> > I loop through each line.
> > 
> > If I find an author's name, I add a tag to the end of each subsequent
> > line to identify the author until I find another author's name and
> > repeat.
>  
> > Is this the right aproach to get this result?
> 
> Er? Sounds OK but I'd probably process the file line-wise rather than
> slurp unless there is some other reason to slup.

OK.  Thanks.


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

Date: Mon, 03 Feb 2003 23:39:36 -0500
From: istink <istink@real.bad.com>
Subject: sort, my concoction of
Message-Id: <3E3F4408.CD90A009@real.bad.com>

my concoction of sort. It *seems* to work. what do you think. 

my flatfile:

@db equals:
1|d|h|c|3|w
2|d|h|6|t|4
3|d|s|6|3|r
4|d|h|z|t|t
5|5|h|6|7|y
6|t|f|c|t|u
7|d|h|6|i|jce
8|d|h|v|t|k
9|7|g|6|u|j(bh
10|d|h|b|t|h
11|u|m|6|y|b
12|d|h|n|T|v
13|d|h|6|t|c
14|l|j|m|r|x
15|d|h|6|t|z
16|k|h|j|e|q
17|d|s|6|t|2
18|g|h|k|w|e
19|d|h|6|t|f
20|d|w|l|q|g
21|d|h|6|t|f
22|a|h|j|s|d
23|d|r|6|t|g
24|s|h|h|d|b
25|c|g|6|t|jaj
26|d|h|g|f|u
27|e|h|6|t|3

I'm sorting the last column, column 5 (you know, 0,1,2,3,4,5)
pay attention to:
jaj
j(bh
jce

a normal cmp will give
j(bh
jaj
jce

I want it to strip all non alpha/num
and sort it.
I want:
jaj
j(bh
jce


here's my experiment:
    @temp = sort {
        my $aa=(split '\|',uc($a), 6)[5];
        my $bb=(split '\|',uc($b), 6)[5];
        $aa=~ s/\W+//g;
        $bb=~ s/\W+//g;
        $aa cmp $bb;
                  } @db;
    @db=@temp;
it *seem* to work, but do you see any problems with it?
as you can see I've avoided the complicate bubble sort.
any potential problems with it?
can it be made shorter? more efficent way?
what is the purpose of life?

again, I'm sorting only alpha/numeric, ignoring all symbols, maybe keep
spaces (but not important)
I'm using this to sort material that contains lots of () and * and &
etc...
think of this as a perl critique.


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

Date: Tue, 04 Feb 2003 05:00:03 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: sort, my concoction of
Message-Id: <x7isw0skrw.fsf@mail.sysarch.com>

>>>>> "i" == istink  <istink@real.bad.com> writes:

  i> my concoction of sort. It *seems* to work. what do you think. 

  i> here's my experiment:
  i>     @temp = sort {
  i>         my $aa=(split '\|',uc($a), 6)[5];
  i>         my $bb=(split '\|',uc($b), 6)[5];
  i>         $aa=~ s/\W+//g;
  i>         $bb=~ s/\W+//g;
  i>         $aa cmp $bb;
  i>                   } @db;
  i>     @db=@temp;
  i> it *seem* to work, but do you see any problems with it?
  i> as you can see I've avoided the complicate bubble sort.
  i> any potential problems with it?
  i> can it be made shorter? more efficent way?
  i> what is the purpose of life?

it will be very slow with large amounts of input.

read this paper:

	http://www.sysarch.com/perl/sort_paper.html

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class


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

Date: 3 Feb 2003 20:41:12 -0800
From: shadowfax@optonline.net (Shadowfax)
Subject: strange localtime return
Message-Id: <22e9b972.0302032041.4ace8d38@posting.google.com>

Hi, All,

I'm new to Perl/W32, I try to use below script to modify filenames
under specific directory to make it looks like yyyymmdd_x. But when I
run the script, surprisingly I saw the $year return as "691131", did I
do something wrong ?

Perl Script:

$org_dir="E:\\temp\\testfolder";

opendir(DIR,$org_dir)||die "can't open original directory $org_dir" ;
@org_files=readdir(DIR) ;
closedir(DIR) ;

foreach $org_file(@org_files)
{
	$mtime=(stat($org_file))[9] ;
	my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime
mtime;
	print "$year.$mon.$mday \n";
	$file_date{$year.$mon.$mday}=$file_date{$year.$mon.$mday}+1;
	$new_filename=$year.$mon.$mday."_".$file_date{$year.$mon.$mday};
	rename $org_file,$new_filename;
}

Thanks,
Shadowfax


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

Date: Mon, 3 Feb 2003 16:12:43 -0000
From: "Clyde Ingram" <cingram@pjocsNOSPAMORHAM.demon.co.uk>
Subject: Re: Tainting individual variables
Message-Id: <b1m4df$jt$1$8302bc10@news.demon.co.uk>

Brian,

"Brian McCauley" <nobull@mail.com> wrote in message
news:u9adhlw3ng.fsf@wcl-l.bham.ac.uk...
> mauzo@ux-ma160-16.csv.warwick.ac.uk (Ben Morrow) writes:
<snip>
> > >
> > >(I'd rather eval than simply substitute values via su///, as this
allows
> > >the string to include logical constructs such as '? :'.)
> >
> > You might want to look at the Safe module.
>
> Actually it's a lot of work to use Safe to contain the interpolation
> engine safely.  That's largely why I wrote String::Interpolate.
<snip>
> Agghhh!  Another "small language".  Perl has a very good interpolation
> engine.  I think you should use it rather than re-invent the wheel.

I have a simple database comprising several files, each containing a literal
value of a 2-D hash, generated by Data::Dumper in Terse mode - so the first
and last characters of each file are open "{" and close "}" curly braces,
respectively.  Like this:

{
    'Fred' => {
        'age'    => '30',
        'hair'   => 'brown',
        'height => '1.73'
    }
    'Bill' => {
        'age'    => '20',
        'hair'   => 'red',
        'height => '1.85'
    }
}

To access each one, I slurp the file, and eval it, like:

my $hash_ref = eval( $whole_file );

Now, $whole_file is tainted, of course.
Will using String::Interpolate safely de-taint the hash literal for me?
Is String::Interpolate overkill, since the $whole_file string does not
itself contain any variables to be interpolated?
Can you suggest a better (simpler, more appropriate) way to de-taint my hash
literal?

Thanks,
Clyde




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

Date: 03 Feb 2003 17:47:51 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Tainting individual variables
Message-Id: <u9lm0xxnlk.fsf@wcl-l.bham.ac.uk>

"Clyde Ingram" <cingram@pjocsNOSPAMORHAM.demon.co.uk> writes:

> "Brian McCauley" <nobull@mail.com> wrote in message
> news:u9adhlw3ng.fsf@wcl-l.bham.ac.uk...
>
> > Agghhh!  Another "small language".  Perl has a very good interpolation
> > engine.  I think you should use it rather than re-invent the wheel.
> 
> I have a simple database comprising several files, each containing a literal
> value of a 2-D hash, generated by Data::Dumper in Terse mode - so the first
> and last characters of each file are open "{" and close "}" curly braces,
> respectively.  Like this:
> 
> {
>     'Fred' => {
>         'age'    => '30',
>         'hair'   => 'brown',
>         'height => '1.73'
>     }
>     'Bill' => {
>         'age'    => '20',
>         'hair'   => 'red',
>         'height => '1.85'
>     }
> }
> 
> To access each one, I slurp the file, and eval it, like:
> 
> my $hash_ref = eval( $whole_file );

If these are truely files and not records in some database system then
you can do() them rather than slurp and eval().

> Now, $whole_file is tainted, of course.

> Will using String::Interpolate safely de-taint the hash literal for
> me?

String::Interpolate forces it's return value to be a plain string.

> Is String::Interpolate overkill, since the $whole_file string does not
> itself contain any variables to be interpolated?

Yes.

> Can you suggest a better (simpler, more appropriate) way to de-taint my hash
> literal?

Simply blindly untaint the scalar $whole_file and reval() it in a Safe
compartment.  If these are true files than just rdo() them in a Safe
compartment.

Note: Safe is not truely safe.  Make sure that there's nothing of
value accesible via *_ before you call reval() or rdo() and also make
sure that you disable the bless() and tie() opcodes - they are enabled
by default and can be used to escape the sandbox.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Mon, 03 Feb 2003 18:11:02 GMT
From: gml4410@ggr.co.uk (Lack Mr G M)
Subject: Re: Tainting individual variables
Message-Id: <2003Feb3.181102@ukwit01>

In article <b1m4df$jt$1$8302bc10@news.demon.co.uk>, "Clyde Ingram" <cingram@pjocsNOSPAMORHAM.demon.co.uk> writes:
|>
|> I have a simple database comprising several files, each containing a literal
|> value of a 2-D hash, generated by Data::Dumper in Terse mode - so the first
|> and last characters of each file are open "{" and close "}" curly braces,
|> respectively.  Like this:
|> 
|> {
|>     'Fred' => {
|>         'age'    => '30',
|>         'hair'   => 'brown',
|>         'height => '1.73'
|>     }

   You'll need a , after this for the eval to work (and you've missed
one after 'height).  However, read on...

|> Now, $whole_file is tainted, of course.

   So untaint it?

   Assuming the data is in "hinfo" in the format above (so this code
adds the commas - you should check this works for every layotu you might
put in there).
===============================
#!/usr/central/bin/perl 

open HINFO, "hinfo" or die "open: hinfo - $!\n";

$/ = undef;
my $tainted_file = <HINFO>;

# Add a comma after every }
#
$tainted_file =~ s/}/},/gs;

# Untaint the data by matching all of it in a regex
# (This assumes you are confident the file contents are OK).
#
(my $whole_file) = $tainted_file =~ /(.*)/s;

my $hash_ref = eval( $whole_file );

while ((my $k, $v) = each %$hash_ref) {
   print "$k -> $v\n";
}   


-- 
--------- Gordon Lack --------------- gml4410@ggr.co.uk  ------------
This message *may* reflect my personal opinion.  It is *not* intended
to reflect those of my employer, or anyone else.


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

Date: Mon, 03 Feb 2003 22:39:50 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: what's the best book for learning perl?
Message-Id: <slrnb3trtm.se5.mgjv@verbruggen.comdyn.com.au>

On Sun, 2 Feb 2003 08:41:28 -0600,
	Barry Kimelman <barryk2@SPAM-KILLER.mts.net> wrote:
> 
> In article <eb41f4fa.0302020348.664356da@posting.google.com>, SJA 
> (sagejustinadams@yahoo.com) says...
>> hi,
>> 
>> what's the best book for learning perl from the ground up?
>> 
> 
> That would depend in part (possibly ?) on how much of a programming 
> background you posess.
> 
> Anyway, there a couple of good books published by the O'Reily publishing 
> company.
> 
> 	"Programmaing Perl" (commonly known as "The Camel")

"Programming Perl", Larry Wall, Tom Christiansen, Jon Orwant.  

> 	- this is more of a language reference manual, but a MUST for 
> 	  serious Perl programmers

I got along quite well for a long time without a copy, just using the
standard documentation. I now own a few copies, but I can't say I use
them much.

> 	"Learning to Program in Perl" (known as "The Lama")

The Llama is actually "Learning Perl" by Randal Schwartz and Tom
Phoenix.


And if you don't know how to program yet: "Elements of Programming
with Perl" by Andrew Johnson.

Martien
-- 
                        | 
Martien Verbruggen      | 
Trading Post Australia  | Can't say that it is, 'cause it ain't.
                        | 


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

Date: 3 Feb 2003 22:51:15 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: what's the best book for learning perl?
Message-Id: <b1mrp3$8pc$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Martien Verbruggen:

> On Sun, 2 Feb 2003 08:41:28 -0600,
> 	Barry Kimelman <barryk2@SPAM-KILLER.mts.net> wrote:

>> 	"Programmaing Perl" (commonly known as "The Camel")
> 
> "Programming Perl", Larry Wall, Tom Christiansen, Jon Orwant.  
> 
>> 	- this is more of a language reference manual, but a MUST for 
>> 	  serious Perl programmers
> 
> I got along quite well for a long time without a copy, just using the
> standard documentation. I now own a few copies, but I can't say I use
> them much.

Err, what is the benefit of having 'a few copies' over just one?

As for the frequency of using it: The Camel is indeed more a reference
than anything else so the perldocs are probably superior (especially
since they are partially searchable and allow a sort of 'random
access') when programming Perl.

But still I learnt a lot of Perl through it...simply by promoting it to
the one book that is always on the basin in my toilet. So if you happen
to have more than one rest room you naturally need more than one copy to
equip each one with a Camel. ;-)

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Mon, 03 Feb 2003 23:02:23 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: what's the best book for learning perl?
Message-Id: <slrnb3tt7v.se5.mgjv@verbruggen.comdyn.com.au>

On 3 Feb 2003 22:51:15 GMT,
	Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote:
> Also sprach Martien Verbruggen:
> 
>> On Sun, 2 Feb 2003 08:41:28 -0600,
>> 	Barry Kimelman <barryk2@SPAM-KILLER.mts.net> wrote:
> 
>>> 	"Programmaing Perl" (commonly known as "The Camel")
>> 
>> "Programming Perl", Larry Wall, Tom Christiansen, Jon Orwant.  
>> 
>>> 	- this is more of a language reference manual, but a MUST for 
>>> 	  serious Perl programmers
>> 
>> I got along quite well for a long time without a copy, just using the
>> standard documentation. I now own a few copies, but I can't say I use
>> them much.
> 
> Err, what is the benefit of having 'a few copies' over just one?

One second edition, and two third editions. Two at home and one at
work.

> As for the frequency of using it: The Camel is indeed more a reference
> than anything else so the perldocs are probably superior (especially
> since they are partially searchable and allow a sort of 'random
> access') when programming Perl.
> 
> But still I learnt a lot of Perl through it...simply by promoting it to
> the one book that is always on the basin in my toilet. So if you happen
> to have more than one rest room you naturally need more than one copy to
> equip each one with a Camel. ;-)

I guess the difference is, maybe, that I learned most of my Perl quite
a while ago, when it was still a much smaller language than it is now.
It all fitted on one manual page. From there I more or less grew with
the language, and never really needed the Camel. I finally bought a
few, simply because I felt I should :)

Martien
-- 
                        | 
Martien Verbruggen      | If at first you don't succeed, try again.
Trading Post Australia  | Then quit; there's no use being a damn fool
                        | about it.


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

Date: Mon, 03 Feb 2003 16:57:07 -0800
From: swen <swen@news.com>
Subject: Re: what's the best book for learning perl?
Message-Id: <3E3F0FE3.FBB3D0CA@news.com>

you can probably learn what you need online somewhere. there are at
least hundreds of resources to learn perl. perl is easy to get started
with. you don't really need a book. you can get started with an online
tutorial, and since almost everything in the most recommended book,
Programming with Perl, is straight from the perldocs, you don't really
need a book.

SJA wrote:

> hi,
>
> what's the best book for learning perl from the ground up?



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

Date: 3 Feb 2003 12:00:08 -0800
From: zhiyong6@yahoo.com (jerron)
Subject: where is GD::Font::Small defined?
Message-Id: <206afc3f.0302031200.3a7d31bb@posting.google.com>

I'm new to perl. here is something I can't understand.

when I try to run my test.cgi, I met following error message:
#perl test.cgi
Undefined subroutine &GD::Font::Small called at
/usr/lib/perl5/site_perl/5.8.0/GD.pm line 91.

the code cause this message in the test.cgi is:
$my_font=GD::gdSmallFont;

and in GD.pm, the function gdSmallFont (start from line 90) is like
this:
sub GD::gdSmallFont {
   return GD:Font:Small;
}


I can't find where GD:Font:Small is defined in GD.pm. can anyone tell
me where it is defined? what mechinism perl uses to locate it? thanks
a lot.


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

Date: Tue, 04 Feb 2003 03:17:04 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: where is GD::Font::Small defined?
Message-Id: <3E3F30A4.1070001@rochester.rr.com>

jerron wrote:

 ...
> I can't find where GD:Font:Small is defined in GD.pm. can anyone tell
> me where it is defined? what mechinism perl uses to locate it? thanks
> a lot.
> 

The GD module is mostly written in C.  Perl's XS interface is used for 
this, and those routines will all show up in the relevant executable, 
GD.dll (on Windoze; perhaps other filenames on other systems).  If a 
given font isn't there, it must not have been compiled in.  You might 
check out the source code, and try recompiling it.

-- 
Bob Walton



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

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


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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


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


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