[17556] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4976 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 28 03:05:34 2000

Date: Tue, 28 Nov 2000 00:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <975398709-v9-i4976@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 28 Nov 2000     Volume: 9 Number: 4976

Today's topics:
         basic keys question <kulabocca69@hotmail.com>
    Re:  basic keys question <kulabocca69@hotmail.com>
        [ in regex <johngros@Spam.bigpond.net.au>
    Re: [ in regex <tony_curtis32@yahoo.com>
    Re: [ in regex <johngros@Spam.bigpond.net.au>
    Re: basic keys question (Sam Holden)
    Re: basic keys question (Chris Fedde)
        FAQ 4.15:   How do I find yesterday's date? <faq@denver.pm.org>
    Re: for loop: brackets make any difference? (Andrew N. McGuire)
        foreach output manipulation help <sbraswe1@email.unc.edu>
    Re: NEWBEE: How to Encrypt Data ?? (OTR Comm)
        newbie dowloading file ? lightfoote@my-deja.com
        Perl + MySQL Tutorial Homepage <sales@kafelinux.com>
    Re: Perl + MySQL Tutorial Homepage <bwalton@rochester.rr.com>
    Re: Perl + MySQL Tutorial Homepage <not.my.real.email@bellglobal.com>
    Re: Perl not executing from Cron job <douglas@apperley.com>
    Re: Pie Chart Font Size <r_hao@hotmail.com>
    Re: Pie Chart Font Size (Martien Verbruggen)
    Re: Posting Guidelines? (Jon Bell)
    Re: REGEXP Help! Trying to parse funky time format... (Andrew N. McGuire)
        run perl against multiple files <kenneth.hopkins@pegs.com>
    Re: run perl against multiple files (Tad McClellan)
        Win32::Perms <brianlk@pacific.net.hk>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 28 Nov 2000 04:32:46 GMT
From: "nougat" <kulabocca69@hotmail.com>
Subject:  basic keys question
Message-Id: <OzGU5.561$Ei1.32965@bgtnsc05-news.ops.worldnet.att.net>

Hi,

I'm in need of some clarification as to the order in which the keys operator
unwinds a hash when used in a foreach loop.

Specifically, here is a section of my code:

-----------------------
%fields = ("REG" => "Regular", "WIN" => "Window");

# ...

foreach $field_key (keys %fields) {

     $type_field = $fields{$field_key};

# ...
}
------------------------

When I do this, the first value assigned to $field_key is "WIN", not "REG".
The debugger shows the values of  %fields in the order in which they were
assigned when initialized. What I'm trying to accomplish is some way to
initialize the hash so that I can return the keys in a predictable order.

I understand that hashes access key/value pairs randomly, but I have also
read that the keys operator is supposed to unwind the elements "in order",
i.e. first key first, etc.

When I preface the keys operator with the sort operator, all is fine, as
they're returned sorted alphabetically. However, not every instance in which
I need to do something like this can be resolved that way.

Thanks in advance.










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

Date: Tue, 28 Nov 2000 04:41:10 GMT
From: "nougat" <kulabocca69@hotmail.com>
Subject: Re:  basic keys question
Message-Id: <GHGU5.569$Ei1.34141@bgtnsc05-news.ops.worldnet.att.net>

> I understand that hashes access key/value pairs randomly

^^^^^^
I meant non-sequentially. Pardon.




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

Date: Tue, 28 Nov 2000 02:59:00 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: [ in regex
Message-Id: <UbFU5.8474$GW5.50484@news-server.bigpond.net.au>

if (/^[/)

I am trying to find a line that starts with "[".
I have tried a "\" to escape it.
I have tried [[] and ([)
Anybody know how?




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

Date: 27 Nov 2000 21:02:53 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: [ in regex
Message-Id: <87hf4sajdu.fsf@limey.hpcc.uh.edu>

>> On Tue, 28 Nov 2000 02:59:00 GMT,
>> "John Boy Walton" <johngros@Spam.bigpond.net.au> said:

> if (/^[/) I am trying to find a line that starts with
> "[".  I have tried a "\" to escape it.  I have tried [[]
> and ([) Anybody know how?

aanfoch...as they say in austria:

    /^\[/

hth
t
-- 
Eih bennek, eih blavek.


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

Date: Tue, 28 Nov 2000 03:11:34 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: [ in regex
Message-Id: <GnFU5.8480$GW5.50448@news-server.bigpond.net.au>

Soz ignore my last post.
Doh!
"John Boy Walton" <johngros@Spam.bigpond.net.au> wrote in message
news:UbFU5.8474$GW5.50484@news-server.bigpond.net.au...
> if (/^[/)
>
> I am trying to find a line that starts with "[".
> I have tried a "\" to escape it.
> I have tried [[] and ([)
> Anybody know how?
>
>




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

Date: 28 Nov 2000 04:46:58 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: basic keys question
Message-Id: <slrn926e62.7g8.sholden@pgrad.cs.usyd.edu.au>

On Tue, 28 Nov 2000 04:32:46 GMT, nougat <kulabocca69@hotmail.com> wrote:
>Hi,
>
>I'm in need of some clarification as to the order in which the keys operator
>unwinds a hash when used in a foreach loop.
>
>Specifically, here is a section of my code:
>
>-----------------------
>%fields = ("REG" => "Regular", "WIN" => "Window");
>
># ...
>
>foreach $field_key (keys %fields) {
>
>     $type_field = $fields{$field_key};
>
># ...
>}
>------------------------
>
>When I do this, the first value assigned to $field_key is "WIN", not "REG".
>The debugger shows the values of  %fields in the order in which they were
>assigned when initialized. What I'm trying to accomplish is some way to
>initialize the hash so that I can return the keys in a predictable order.
>
>I understand that hashes access key/value pairs randomly, but I have also
>read that the keys operator is supposed to unwind the elements "in order",
>i.e. first key first, etc.

I guess you could say it does it in order, according to the internal hashing
of the elements. Which means that the order could change when you insert/delete
elements.

In practice that means the order is essentially random.

It's safer to consider it to be random so that you don't rely on some
lucky ordering you happen to get, anyway.

>
>When I preface the keys operator with the sort operator, all is fine, as
>they're returned sorted alphabetically. However, not every instance in which
>I need to do something like this can be resolved that way.

You could keep an array of keys as well, which you keep in your predefined
order.

There might be a hash object that maintains order on CPAN somewhere too
I guess.


-- 
Sam Holden



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

Date: Tue, 28 Nov 2000 05:38:56 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: basic keys question
Message-Id: <QxHU5.129$QX6.171076608@news.frii.net>

In article <slrn926e62.7g8.sholden@pgrad.cs.usyd.edu.au>,
Sam Holden <sholden@cs.usyd.edu.au> wrote:
>On Tue, 28 Nov 2000 04:32:46 GMT, nougat <kulabocca69@hotmail.com> wrote:
>>Hi,
>>
>>I'm in need of some clarification as to the order in which the keys operator
>>unwinds a hash when used in a foreach loop.
>>
>
>In practice that means the order is essentially random.
>
>There might be a hash object that maintains order on CPAN somewhere too
>I guess.
>
>

when I run the following:

    $ perl -MCPAN -e 'readme  Tie::IxHash'

I see that:

    This is the README file for Tie::IxHash, the Perl module that 
    implements ordered in-memory associative arrays.

It might be close to what you want.

chris

-- 
    This space intentionally left blank


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

Date: Tue, 28 Nov 2000 05:20:47 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ 4.15:   How do I find yesterday's date?
Message-Id: <PgHU5.128$QX6.178750464@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 yesterday's date?

    The `time()' function returns the current time in seconds since the
    epoch. Take twenty-four hours off that:

        $yesterday = time() - ( 24 * 60 * 60 );

    Then you can pass this to `localtime()' and get the individual year,
    month, day, hour, minute, seconds values.

    Note very carefully that the code above assumes that your days are
    twenty-four hours each. For most people, there are two days a year when
    they aren't: the switch to and from summer time throws this off. A
    solution to this issue is offered by Russ Allbery.

        sub yesterday {
            my $now  = defined $_[0] ? $_[0] : time;
            my $then = $now - 60 * 60 * 24;
            my $ndst = (localtime $now)[8] > 0;
            my $tdst = (localtime $then)[8] > 0;
            $then - ($tdst - $ndst) * 60 * 60;
        }
        # Should give you "this time yesterday" in seconds since epoch relative to
        # the first argument or the current time if no argument is given and
        # suitable for passing to localtime or whatever else you need to do with
        # it.  $ndst is whether we're currently in daylight savings time; $tdst is
        # whether the point 24 hours ago was in daylight savings time.  If $tdst
        # and $ndst are the same, a boundary wasn't crossed, and the correction
        # will subtract 0.  If $tdst is 1 and $ndst is 0, subtract an hour more
        # from yesterday's time since we gained an extra hour while going off
        # daylight savings time.  If $tdst is 0 and $ndst is 1, subtract a
        # negative hour (add an hour) to yesterday's time since we lost an hour.
        #
        # All of this is because during those days when one switches off or onto
        # DST, a "day" isn't 24 hours long; it's either 23 or 25.
        #
        # The explicit settings of $ndst and $tdst are necessary because localtime
        # only says it returns the system tm struct, and the system tm struct at
        # least on Solaris doesn't guarantee any particular positive value (like,
        # say, 1) for isdst, just a positive value.  And that value can
        # potentially be negative, if DST information isn't available (this sub
        # just treats those cases like no DST).
        #
        # Note that between 2am and 3am on the day after the time zone switches
        # off daylight savings time, the exact hour of "yesterday" corresponding
        # to the current hour is not clearly defined.  Note also that if used
        # between 2am and 3am the day after the change to daylight savings time,
        # the result will be between 3am and 4am of the previous day; it's
        # arguable whether this is correct.
        #
        # This sub does not attempt to deal with leap seconds (most things don't).
        #
        # Copyright relinquished 1999 by Russ Allbery <rra@stanford.edu>
        # This code is in the public domain

- 

Historically documents such as this are called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition and generally serve to reduce the
volume of redundant traffic on a particular news group.  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 are not able to find this or other Perl documentation from
your installation you can access it via the web from

    http://theoryx5.uwinnipeg.ca/mod_perl/cpan-search
    http://www.perldoc.com
    http://www.cpan.org
or
    http://www.perl.com

Answers to questions about LOTS of other stuff not related to
Perl can be found at

    news:news.answers

and in the many thousands of other useful Usenet news groups.

The perlfaq manual pages contain the following copyright notice.

  AUTHOR AND COPYRIGHT

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

    When included as an integrated part of the Standard
    Distribution of Perl or of its documentation (printed or
    otherwise), this work is covered under Perl's Artistic
    License.  For separate distributions of all or part of
    this FAQ outside of that, see the perlfaq manpage.

    Irrespective of its distribution, all code examples here
    are public domain.  You are permitted and encouraged to
    use this code and any derivatives thereof in your own
    programs for fun or for profit as you see fit.  A simple
    comment in the code giving credit to the FAQ would be
    courteous but is not required.

-- 
    This space intentionally left blank


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

Date: 27 Nov 2000 23:22:24 -0600
From: anmcguire@ce.mediaone.net (Andrew N. McGuire)
Subject: Re: for loop: brackets make any difference?
Message-Id: <87d7fgekmn.fsf@hawk.ce.mediaone.net>

>>>>> "DW" == David Wall <darkon@one.net> writes:

DW> Out of curiousity, is there any difference between the way the two 
DW> following constructs are compiled?

  Perl will tell you this, if you ask it. :-)

DW> for (list) { statement }

leaving off the LABEL and the continue, that is:

   for ( LIST ) BLOCK

DW> statement for (list);

   SIMPE_STATEMENT for ( LIST )

not to be confused with a compound statement ( block ), as it is called
in some other languages.

DW> The question about getting data into columns brought this to mind. ("Newbie 
DW> question concerning columns")  I'd think they would compile exactly the 
DW> same, but somehow I seem to recall reading that they are a little 
DW> different.

( anm@hawk ~ ) cat for.pl                                           ( 0 pts/1 )
print "hello, world\n" for 1;
for ( 1 ) { print "hello, world\n"; }
( anm@hawk ~ ) perl -MO=Deparse for.pl                              ( 0 pts/1 )
foreach $_ (1) {
    print "hello, world\n";
}
foreach $_ (1) {
    print "hello, world\n";
}
for.pl syntax OK
( anm@hawk ~ )                                                      ( 0 pts/1 )

anm

-- 
perl -wMstrict -e '
$a=[[qw[J u s t]],[qw[A n o t h e r]],[qw[P e r l]],[qw[H a c k e r]]];$.++
;$@=$#$a;$$=[reverse sort map$#$_=>@$a]->[$|];for$](--$...$$){for$}($|..$@)
{$$[$]][$}]=$a->[$}][$]]}}$,=$";$\=$/;print map defined()?$_:$,,@$_ for @$;
'


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

Date: 28 Nov 2000 05:22:28 GMT
From: Stephen Braswell <sbraswe1@email.unc.edu>
Subject: foreach output manipulation help
Message-Id: <8vvfek$21p$1@news2.isis.unc.edu>

Hello,

I have a script that performs an LDAP search and prints out the results
using a foreach statement.  I want to manipulate the data that is
displayed by "$entry->dump" (see below) using Unix grep, cut, and sort
before it gets displayed to the screen.  I know how to do this on the
command-line (i.e. script.pl | grep blah | cut -f2 -d: | sort) but I want
to do all of that within the perl script.  I've tried using system calls
but can't seem to get the output that I want.  I've included a sample of
the script below.  Any assistance is much appreciated.  If you need more
information, please feel free to ask.

Thanks,
  
Stephen
-----------

$ldap = new Net::LDAP('ldap.foobar.com');

$ldap->bind;

$mesg = $ldap->search (
                        base   => "o=MyCorp,c=US",
                        filter => "(ou=*)"

                       ) or die ("Failed on search.$!");

foreach $entry ($mesg->entries) { $entry->dump; }

$ldap->unbind;


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

Date: Tue, 28 Nov 2000 02:52:55 GMT
From: otrcomm***NO-SPAM***@wildapache**NO-SPAM***.net (OTR Comm)
Subject: Re: NEWBEE: How to Encrypt Data ??
Message-Id: <3a231c4e.3219671343@news.wildapache.net>

On 27 Nov 2000 23:57:37 GMT, trammell@nitz.hep.umn.edu (John J. Trammell) wrote:

>On Mon, 27 Nov 2000 23:45:59 GMT, OTR Comm
><otrcomm***NO-SPAM***@wildapache**NO-SPAM***.net> wrote:
>[snip]
>>$pin_number1 = "6357243";
>>$pin_number2 = "3427536";
>>
>>push(@plaintext,$pin_number1,$pin_number2);    
>>
>>$ciphertext = $pgp->encrypt(@plaintext);
>[snip]
>>Can't use string ("6357243") as an ARRAY ref while "strict refs" in
>>use at /usr/lib/perl5/site_perl/5.005/Crypt/PGP5.pm line 289.
>
>A quick 'perldoc Crypt::PGP5' yields:
>
>  $ciphertext = $pgp->encrypt([@recipients], @plaintext);
>
>So, what's the plan?  Are you going to store the encrypted data
>in the database, but leave the password in plaintext in the
>script?  Not much of an improvement IMHO.  Maybe you should
>hang out in sci.crypt for a while and read some Bruce Schneier.

I read the perldoc Crypt::PGP5 also, that is where I got the code for my example and that is the code
that gave me the error above.

The encrytped data will be stored in the database, but the password/passphrase will be read from a
secure machine via an ssh tunnel connection.

I will pose the questions to sci.crypt.

Thanks for the thread,
Murrah Boswell
>
>-- 
>John J. Trammell
>johntrammell@yahoo.com



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

Date: Tue, 28 Nov 2000 03:12:04 GMT
From: lightfoote@my-deja.com
Subject: newbie dowloading file ?
Message-Id: <8vv7pv$rru$1@nnrp1.deja.com>

hi perl family..

i'm trying to allow users to download a large 6 meg zip file

when a windows user uses it will the standard dowload window
open up????

will this perl scipt work:

  where $file = 'http//www.mysite.com/myfile.zip'

  print "Content-type text/html\n";
  print "Location: $file\n\n";
  exit

thanks......john.....


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 28 Nov 2000 10:07:59 -0700
From: Rudy Hermawan <sales@kafelinux.com>
Subject: Perl + MySQL Tutorial Homepage
Message-Id: <3A23E66F.4D3FD2B4@kafelinux.com>

Greetings,

Pls help me find the Perl + MySQL Tutorial Homepage.

TIA

Rudy Hermawan



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

Date: Tue, 28 Nov 2000 03:35:12 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Perl + MySQL Tutorial Homepage
Message-Id: <3A232896.88FBF99D@rochester.rr.com>

Rudy Hermawan wrote:
 ...
> Pls help me find the Perl + MySQL Tutorial Homepage.
 ...
> Rudy Hermawan
Try http://www.perl.com/reference/query.cgi?tutorials .  There are some
listed there, even one in German.  You can also look for DBI, since DBI
is the best way of getting to just about any database.  And very little
if anything about DBI is special to MySQL or any other database (one of
the great features of using Perl and DBI).  Try
 
    perldoc DBI

That's how I learned it.
-- 
Bob Walton


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

Date: Tue, 28 Nov 2000 05:25:02 GMT
From: "MNJP" <not.my.real.email@bellglobal.com>
Subject: Re: Perl + MySQL Tutorial Homepage
Message-Id: <OkHU5.34687$xK.1103690@news20.bellglobal.com>


Give http://www.devshed.com a shot

"Rudy Hermawan" <sales@kafelinux.com> wrote in message
news:3A23E66F.4D3FD2B4@kafelinux.com...
> Greetings,
>
> Pls help me find the Perl + MySQL Tutorial Homepage.
>
> TIA
>
> Rudy Hermawan
>




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

Date: Mon, 27 Nov 2000 22:18:45 -0800
From: Douglas Apperley <douglas@apperley.com>
Subject: Re: Perl not executing from Cron job
Message-Id: <3A234E45.D0D8249D@apperley.com>

Hey Paul:

I have run across this exact problem in HP UNIX and it killed me for a week.
I solved my problem by executing a shell script that ran the .profile of the
user
that runs the program at the command line just fine.  You need to have PATHS
SET and whatever else is in the .profile of the user that can run at the command
line
just fine.  When you call a program from CRONTAB there is NO environment
set up at all (that I can see).  Try calling something like this (in Cron):

00 07 * * * /usr/joeblow/run_it.sc

The shell script run_it.sc should look something like this:

cd /usr/joeblow
 ./.profile
cd /your_run_dir
 ./you_perl_program

Good-Luck
Douglas Apperley

Paul Mulloni wrote:

> Hello all,
> System:
>     Red hat 6.1
>     Perl 5.005_03
>
> The perl script will execute from the command line but when the perl scripts
> is run from a cron job it does not work.  It looks like it wants to run the
> script file using the /usr/sh shell instead of the perl shell even though
> the "#!/usr/bin/perl" line is set. I have found that a SHELL environment
> variable can be set within the cron job so setting it  to "/usr/bin/perl"
> has the perl script working to a certain extent.  When this is set then the
> perl script is executed as if the -c option is set so it does not actually
> execute the script only compiles it!!!
>
> Not sure why this is happening??
>
> Paul.



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

Date: Mon, 27 Nov 2000 21:53:50 -0500
From: "Randy" <r_hao@hotmail.com>
Subject: Re: Pie Chart Font Size
Message-Id: <8vv6q6$ouh$1@nntp9.atl.mindspring.net>

Hi, Martien;

Thank you for your wonderful job on Graph module. It worked great. The only
thing we have now is the font size too small on the pie chart. It like small
ant on the big pie, users say.

I also tested 'gdMediumBoldFont', it does not work either.
It displays the percentage, like '66%', and so small, I can not tell it is
right font or not.

Thank you again

Randy

"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn92643q.br5.mgjv@verbruggen.comdyn.com.au...
> On Mon, 27 Nov 2000 20:34:25 -0500,
> Randy <r_hao@hotmail.com> wrote:
> > We have create a Pie Chart according to GD::Graph::Pie module. However,
we
> > can't make font size on the pie chart bigger by using
> > $graph->set_value_font('arial', 20). Anyone has idea?
>
> Is the font displayed at all? Can 'arial.ttf' be found by the program?
> The tiny bit of code you submit is demonstrated in sample92.pl in the
> source distribution, and it works fine there.
>
> What exactly is the problem you're seeing? Nothing at all? Too small a
> font, but the correct one? The wrong font?
>
> Martien
> --
> Martien Verbruggen              |
> Interactive Media Division      | Make it idiot proof and someone will
> Commercial Dynamics Pty. Ltd.   | make a better idiot.
> NSW, Australia                  |




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

Date: Tue, 28 Nov 2000 04:13:42 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Pie Chart Font Size
Message-Id: <slrn926c44.br5.mgjv@verbruggen.comdyn.com.au>

On Mon, 27 Nov 2000 21:53:50 -0500,
	Randy <r_hao@hotmail.com> wrote:
> "Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
> news:slrn92643q.br5.mgjv@verbruggen.comdyn.com.au...

[reordered post to be more chronological]

>> On Mon, 27 Nov 2000 20:34:25 -0500,
>> Randy <r_hao@hotmail.com> wrote:
>> > We have create a Pie Chart according to GD::Graph::Pie module.
>> > However, we can't make font size on the pie chart bigger by using
>> > $graph->set_value_font('arial', 20). Anyone has idea?
>>
>> Is the font displayed at all? Can 'arial.ttf' be found by the program?
>> The tiny bit of code you submit is demonstrated in sample92.pl in the
>> source distribution, and it works fine there.
>>
>> What exactly is the problem you're seeing? Nothing at all? Too small a
>> font, but the correct one? The wrong font?
>
> I also tested 'gdMediumBoldFont', it does not work either.
> It displays the percentage, like '66%', and so small, I can not tell it is
> right font or not.

That is very odd...

I suspect that arial.ttf cannot be found. In that case, the font for
the values on the pie will default to gdinyFont (I believe), which is
pretty small, and ugly. To fix, set TTF_FONT_PATH or FONT_PATH in your
environment before running your program, or do it in your program.
I'll include an adapted version of the sample92.pl file distributed
with the original source archive, with some comments.

For more information see the GD::text documentation, somewhere at the
end.

BEGIN{
    # Set this environment variable for your fonts. It's in a BEGIN{}
    # block, because it has to be set before GD::Text gets loaded by
    # GD::Graph. See the GD::Text documentation for details. 
    #
    # Instead of using this, we'll use the method documented later:
    # $ENV{FONT_PATH} = '/usr/share/fonts/ttfonts';
}

use GD::Graph::pie;
use GD; # For gdMediumBoldFont

# This is where my fonts live. Normally you'd set the FONT_PATH or
# TTF_FONT_PATH to this value in your shell environment. See the
# GD::Text documentation.
GD::Text->font_path('/usr/share/fonts/ttfonts');

@data = ( 
    ["1st","2nd","3rd","4th","5th","6th"],
    [    4,    2,    3,    4,    3,  3.5]
);

$my_graph = new GD::Graph::pie( 250, 200 );

$my_graph->set( 
    title           => 'A Pie Chart',
    label           => 'Label',
    axislabelclr    => 'white',
    dclrs           => [ 'lblue' ],
    accentclr       => 'lgray',
);

# Set the font of the title above the pie
$my_graph->set_title_font('arial', 18);
# Set the font of the label below the pie
$my_graph->set_label_font(gdMediumBoldFont);
# Set the font of the values printed on the pie
$my_graph->set_value_font('arial', 20);

$my_graph->plot(\@data);
open(OUT, '>foo.png') or die $!;
binmode OUT;
print OUT $my_graph->gd->png;
close OUT;


Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Unix is user friendly. It's just
Commercial Dynamics Pty. Ltd.   | selective about its friends.
NSW, Australia                  | 


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

Date: Tue, 28 Nov 2000 05:16:34 GMT
From: jtbell@presby.edu (Jon Bell)
Subject: Re: Posting Guidelines?
Message-Id: <G4pynM.MJF@presby.edu>

In article <0JCU5.118$QX6.189355520@news.frii.net>,
Chris Fedde <cfedde@fedde.littleton.co.us> wrote:
>
> [...]  I'm talking about
>a few periodic postings that say things like "post in plain text",
>"edit quoted text", and "write below what you are responding to."

Like this?

  http://www.geocities.com/nnqweb/nquote.html

It's a bit wordy, but I'm working on an "executive summary" for posting
regularly in news.newusers.questions, that refers to this for details.

-- 
Jon Bell <jtbell@presby.edu>                        Presbyterian College
Dept. of Physics and Computer Science        Clinton, South Carolina USA
[ Questions about newsgroups?  Visit http://www.geocities.com/nnqweb/  ]
[                or ask in news:news.newusers.questions                ]


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

Date: 28 Nov 2000 00:40:00 -0600
From: anmcguire@ce.mediaone.net (Andrew N. McGuire)
Subject: Re: REGEXP Help! Trying to parse funky time format...
Message-Id: <878zq4eh1b.fsf@hawk.ce.mediaone.net>

>>>>> "CF" == Chris Fedde <cfedde@fedde.littleton.co.us> writes:

CF> In article <t1lsiaostpnga2@news.supernews.com>,
CF> Liam Furniss <liam@nethelpnow.com> wrote:
>> Hello Perlish Types,
>> 
>> I have a some time data in the form XXd,XX:XX.XX (e.g. 5d,23:55.07), and I
>> can't seem to craft a regexp the will extract just the numbers into
>> variables that will be useful to me. Currently, I'm trying
>> /(\d*d,)?(\d*:)?(\d*\.)?(\d*)?/, but it reports the minutes in $4 and $3 is
>> empty...The other problem of course is making it work when the no day or
>> hour data (e.g. 5.23)...Anyone feel kind enough to work their regexp mojo
>> for me? This script could help save a struggling dot com! Hehe.
>> 

CF> Here is my solution.  Note that it takes a different approach than you've
CF> been using.

  [ snip code ]

  Sorry to follow up like this, but the OP is not available to me...

To the OP:

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

while ( <DATA> ) {
    my @date;
    if ( @date = /^(\d{1,2})d,(\d{2}):(\d{2})\.(\d{2})$/ ) {
        print "full date -> @date\n";
    }
    elsif ( @date = /^(\d{1,2})\.(\d{2})$/ ) {
        print "partial date -> @date\n"
    }
}


__DATA__
5d,23:55.07
5.23
yada yada yada
blah blah

anm

-- 
perl -wMstrict -e '
$a=[[qw[J u s t]],[qw[A n o t h e r]],[qw[P e r l]],[qw[H a c k e r]]];$.++
;$@=$#$a;$$=[reverse sort map$#$_=>@$a]->[$|];for$](--$...$$){for$}($|..$@)
{$$[$]][$}]=$a->[$}][$]]}}$,=$";$\=$/;print map defined()?$_:$,,@$_ for @$;
'


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

Date: Mon, 27 Nov 2000 19:42:51 -0800
From: Ken Hopkins <kenneth.hopkins@pegs.com>
Subject: run perl against multiple files
Message-Id: <3A2329BB.74593077@pegs.com>

Hello - I am a very new programmer (and I have written a little perl
program called "parse.pl" to run against a file and it works! YA!  But
now I want to take it a step further and run this program against
multiple files in the same UNIX directory.  The problem is how to change
it to (1) so it automatically runs against all files in the directory
and how would I execute it from teh command line then (2) some of those
files are compressed so it would need to temporarily uncompress each
file as it go. A friend suggested that maybe some one out here might be
able to help me out.

Any help here would greatly be appreciated. Also any general pionter
base on by code thus far would be appreciated too.

Thanks ooodles - Ken

I was doing the following for a single file from the cmd line: perl
parse.pl < fileName > output

Here is my program:
#!/usr/bin/perl -w
use strict;
use POSIX;

while( <> )
{
  next if /^[^Z]/;
  my $ctime = substr( $_, 1, 9 );
  next if $ctime < 974851200;
  last;
}

while( <> )
{

  if ( /^Z/ )
  {
    my $ctime = substr( $_, 1, 9 );
    last if ctime > 974874200;
    next;
  }

  # Parse the Time, Session, Transaction, and Record Length
  my $tim = substr( $_, 1, 8 );
  my $ses = substr( $_, index($_,'[') + 1, index($_,']') - index($_,'[')
- 1 );
     $ses = ~s/\s//g; #strip leading spaces
  my $txn = substr( $_, index($_,'>') + 1, index($_,'|') - index($_,'>')
- 1 );

  # Is this a APALS transaction?
  if( $txn eq "APALS" )
  {
      my %apltbl;
      my %apltim;

      $apltbl{$ses} = $_;
      $apltim{$ses} = $tim;

      my $apl = $apltbl{$ses};
      my $pid = &parse( $apl, '|PID' );
      my $sga = &parse( $apl, '|SGA' );
      my $gds = &parse( $apl, '|GDS' );
      my $ind = &parse( $apl, '|IND' );
      my $otd = &parse( $apl, '|OTD' );
      my $rpc = &parse( $apl, '|RPC' );
      my $rpi = &parse( $apl, '|RPI' );
      my $iat = &parse( $apl, '|IAT' );
      my $ccn = &parse( $apl, '|CCN' );
      my @sgs = split( /\|\|/, $_ );

      printf( "\n%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|",
              $tim, $gds, $pid, $sga, $rpc, $rpi, $ind, $otd, $iat, $ccn
);

      delete $apltbl{$ses};
      delete $apltim{$ses};
  }
}

sub parse
{
  my $rc;
  my $st;
  my $a;
  my $b;
  my $v;
  ( $rc, $st ) = @_;
  $a = index( $rc, $st );
  if( $a > 0 )
  {
    $a += 4;
    $b = index( $rc, '|',  $a );
    $v = substr( $rc, $a, $b-$a );
  }
  else
  { $v = ""; }
}



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

Date: Mon, 27 Nov 2000 22:36:51 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: run perl against multiple files
Message-Id: <slrn926a2j.h79.tadmc@magna.metronet.com>

Ken Hopkins <kenneth.hopkins@pegs.com> wrote:

>run this program against
>multiple files in the same UNIX directory.  The problem is how to change
>it to (1) so it automatically runs against all files in the directory
>and how would I execute it from teh command line then 


Do you mean run against more than one file and put all of the
output to the same place? You can already do that with your
program as-is:

   parse.pl fileName1 fileName2 fileName3... >output

Or do you want to determine the filenames from within
your Perl program?

   parse.pl >output

If the later, then these functions will likely help:

   perldoc -f opendir
   perldoc -f readdir
   perldoc -f grep
   perldoc -f open
   perldoc -f -X


>(2) some of those
>files are compressed so it would need to temporarily uncompress each
>file as it go. A friend suggested that maybe some one out here might be
>able to help me out.


There are modules (libraries) that can do compression, or you
could "shell out" and call an external compression program
from within your Perl program.

   perldoc -q 'external command'

Shows 3 ways of running other programs from within Perl.


>Any help here would greatly be appreciated. Also any general pionter
>base on by code thus far would be appreciated too.
>
>Thanks ooodles - Ken
>
>I was doing the following for a single file from the cmd line: perl
>parse.pl < fileName > output
>
>Here is my program:

>     $ses = ~s/\s//g; #strip leading spaces
           ^^^

That doesn't strip spaces at all.

The operator is =~ , you cannot put a space between them.

But even after you take out that space, it still won't do
what the comment says it will do. It will strip _all_ spaces.

You should just do it like in the Perl FAQ, part 4:

   "How do I strip blank space from the beginning/end of a string?"


>  my $txn = substr( $_, index($_,'>') + 1, index($_,'|') - index($_,'>')
>- 1 );


I wonder what your data lines look like?

I expect there is a better way to extract what you want than
a bazillion index() calls.

Maybe use regex "memories" or the unpack() function.

But you didn't give us any data...


>      my $pid = &parse( $apl, '|PID' );
>      my $sga = &parse( $apl, '|SGA' );
>      my $gds = &parse( $apl, '|GDS' );
>      my $ind = &parse( $apl, '|IND' );
>      my $otd = &parse( $apl, '|OTD' );
>      my $rpc = &parse( $apl, '|RPC' );
>      my $rpi = &parse( $apl, '|RPI' );
>      my $iat = &parse( $apl, '|IAT' );
>      my $ccn = &parse( $apl, '|CCN' );


You might like to collect those variables altogether into a hash:

   #UNTESTED
   my %vars;
   foreach ( qw/pid sga gds ind otd rpc rpi iat ccn/ ) {
      $vars{$_} = &parse( $apl, "|\U$_" );
   }

>      my @sgs = split( /\|\|/, $_ );


Errr, that variable goes out of scope in a few lines, and you
don't use it between now and then. It is useless cruft.

>      printf( "\n%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|",
>              $tim, $gds, $pid, $sga, $rpc, $rpi, $ind, $otd, $iat, $ccn

               $vars{tim}, $vars{gds}, $vars{pid}, ...


>sub parse
>{
>  my $rc;
>  my $st;
>  my $a;
>  my $b;
>  my $v;


One-character variable names suck.

Especially the $a and $b names, as Perl already uses those
for something (sorting).


>  ( $rc, $st ) = @_;


You can just stick the "my" in front there, making the earlier
declarations unnecessary:

   my( $rc, $st ) = @_;


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


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

Date: Tue, 28 Nov 2000 11:16:10 +0800
From: Brian Leung <brianlk@pacific.net.hk>
Subject: Win32::Perms
Message-Id: <3A23237A.D6D1BD6F@pacific.net.hk>

Hello,
I try to write the following script:
use Win32::Perms;

$FILE = new Win32::Perms;
$FILE -> Add('administrator',READ);
$FILE -> Set('c:\temp\test');
And, there is no any problems, but i try to write the following:
use Win32::Perms;

$FILE = new Win32::Perms('c:\temp') || die;
$FILE -> Add('administrator',READ) || die;
$FILE -> Set() || die;
It always dies in line 4. Why?
P.S. c:\temp is a directory


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4976
**************************************


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