[18242] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 410 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Mar 4 03:05:45 2001

Date: Sun, 4 Mar 2001 00:05:12 -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: <983693111-v10-i410@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 4 Mar 2001     Volume: 10 Number: 410

Today's topics:
    Re: #ifndef ???? (Gwyn Judd)
    Re: check open files ? (Garry Williams)
        Cut the space <khleung@cse.cuhk.edu.hk>
    Re: Cut the space (Chris Fedde)
    Re: Cut the space (Eric Bohlman)
    Re: dbm hashes : more DBM questions <gtoomey@usa.net>
    Re: dbm hashes : Operation not permitted (Joe Smith)
        Dynamic naming of arrays or hashes (OTR Comm)
    Re: Dynamic naming of arrays or hashes (Chris Fedde)
    Re: Dynamic naming of arrays or hashes (Eric Bohlman)
    Re: Dynamic naming of arrays or hashes (OTR Comm)
    Re: FAQ 4.49:   How do I permute N elements of a list? (Chris Fedde)
    Re: flock and close   with  empty read strangeness <groovyt@erols.com>
    Re: flock and close   with  empty read strangeness <groovyt@erols.com>
    Re: gif problems!!! <bart.lateur@skynet.be>
    Re: Is Perl right for me? <bowman@montana.com>
    Re: Is Perl right for me? <godzilla@stomp.stomp.tokyo>
    Re: length op <mjcarman@home.com>
        Perl Newbie 2 questions <acline@okstateerasecaps.edu>
    Re: Perl Newbie 2 questions <bwalton@rochester.rr.com>
    Re: Perl Newbie 2 questions <acline@okstateerasecaps.edu>
    Re: question on how to code a program (Martien Verbruggen)
    Re: Reading non-ASCII from XML file using DOM module (Eric Bohlman)
    Re: REVISED: Hash/array woes... <unixman@mindspring.com>
    Re: Submitting Forms from Code <joemoore@att.net>
    Re: Uploading a file <joemoore@att.net>
    Re: Uploading a file <joemoore@att.net>
    Re: using blat in a perl script to send form input <bwalton@rochester.rr.com>
    Re: Why doesnt it work. The whole list deletes. <nouser@emailunwelcome.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sun, 04 Mar 2001 03:59:36 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: #ifndef ????
Message-Id: <slrn9a3fd5.if9.tjla@thislove.dyndns.org>

I was shocked! How could Martien Verbruggen <mgjv@tradingpost.com.au>
say such a terrible thing:

>2) Only lad it once, with a begin block, and only refer to it in your
>code:
>
>my %hash;
>BEGIN {
>	%hash = get_hash_content();
>}
>
># Never refer to get_hash_content anywhere in the code ever again.

BEGIN {
    undef *get_hash_content;
}

Will cause a run-time error if you do. Useful for debugging purposes.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
McGowan's Madison Avenue Axiom:
	If an item is advertised as "under $50", you can bet it's not $19.95.


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

Date: Sun, 04 Mar 2001 02:25:58 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: check open files ?
Message-Id: <WIho6.175$mU5.6699@eagle.america.net>

On Sun, 4 Mar 2001 10:34:20 +1100, Martien Verbruggen
<mgjv@tradingpost.com.au> wrote:
>On Sat, 03 Mar 2001 18:56:19 GMT,
>	Garry Williams <garry@zvolve.com> wrote:
>> On Sat, 03 Mar 2001 16:19:53 +0100, Joel Nyholm
>> <joel.nyholm@home.se> wrote:
>>>Hello,
>>>
>>>How can i check if a file is open with perl ?
>> 
>> Wrap your I/O operation in eval {}; and examine $@ after that.  
>
>I'm a bit confused.. How is that going to show me whether a file is
>open?

[snip]

Oops.  I was thinking that an I/O operation on a closed handle raised
an exception.  But it doesn't, of course.  I even tried it and saw
what I expected to see when the _warning_ printed.  :-(  

Here's a way to force the exception when warnings are enabled: 

  $ cat x
  #!/usr/bin/perl
  use strict;
  use warnings;

  #open FH1, "data" or die "data: $!";
  eval { local $SIG{__WARN__} = sub { die }; my $line = <FH1>; };
  print $@ || "no worries\n";

  open FH1, "data" or die "data: $!";
  eval { local $SIG{__WARN__} = sub { die }; my $line = <FH1>; };
  print $@ || "no worries\n";
  $ perl x
  Died at x line 6.
  no worries
  $

Not very pretty.  

I guess (as you point out) your own program should be less forgetful
about the open status of a file handle.  

-- 
Garry Williams


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

Date: 4 Mar 2001 05:34:58 GMT
From: Ivan Leung <khleung@cse.cuhk.edu.hk>
Subject: Cut the space
Message-Id: <97sk62$7ig$1@eng-ser1.erg.cuhk.edu.hk>

How can I cut the blank space(s) at the end of a string?

Thanks.

-- 
Cheers,
Ivan


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

Date: Sun, 04 Mar 2001 06:36:54 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Cut the space
Message-Id: <aolo6.302$T3.170619904@news.frii.net>

In article <97sk62$7ig$1@eng-ser1.erg.cuhk.edu.hk>,
Ivan Leung  <khleung@cse.cuhk.edu.hk> wrote:
>How can I cut the blank space(s) at the end of a string?
>
>Thanks.
>

this is documented in the faq:

perlfaq blank
/usr/local/lib/perl5/5.6.0/pod/perlfaq4.pod chunk 176
  How do I strip blank space from the beginning/end of a string?

    Although the simplest approach would seem to be:

        $string =~ s/^\s*(.*?)\s*$/$1/;

    Not only is this unnecessarily slow and destructive, it also fails with
    embedded newlines. It is much faster to do this operation in two steps:

        $string =~ s/^\s+//;
        $string =~ s/\s+$//;

    Or more nicely written as:

        for ($string) {
            s/^\s+//;
            s/\s+$//;
        }

    This idiom takes advantage of the `foreach' loop's aliasing behavior to
    factor out common code. You can do this on several strings at once, or
    arrays, or even the values of a hash if you use a slice:

        # trim whitespace in the scalar, the array, 
        # and all the values in the hash
        foreach ($scalar, @array, @hash{keys %hash}) {
            s/^\s+//;
            s/\s+$//;
        }

-- 
    This space intentionally left blank


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

Date: 4 Mar 2001 06:42:22 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Cut the space
Message-Id: <97so4e$iel$3@bob.news.rcn.net>

Ivan Leung <khleung@cse.cuhk.edu.hk> wrote:
> How can I cut the blank space(s) at the end of a string?

See "How do I strip blank space..." in perlfaq4.



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

Date: Sun, 4 Mar 2001 17:34:41 +1000
From: "Gregory Toomey" <gtoomey@usa.net>
Subject: Re: dbm hashes : more DBM questions
Message-Id: <40mo6.7741$v5.29250@newsfeeds.bigpond.com>

On a related topic, can DBM files be used when there are multiple readers
and writers??
I am writing Perl CGI scripts which may be used by concurrent users.
Presumably I would need to do locking myself if ther are multiple DBM files?

gtoomey
------------------------
"Joe Smith" <inwap@best.com> wrote in message
news:97sdip$p0u$1@nntp1.ba.best.com...
> In article <GlGg6.720$Ld2.4018@eagle.america.net>,
> Garry Williams <garry@zvolve.com> wrote:
> >Many DBM files are *unmovable*.  That's because of hardware
> >differences or disk information embedded in them, etc.
>
> Huh?  The problem with embedded cylinder/track/sector values in DBM
> files went away when IBM mainframes changed from ISAM to VSAM thirty
> years ago.  DBM files can be moved from one directory to another on
> the same machine with no problems.
>
> >In general, DBM files should be unloaded into some serialized form
> >(usually simple ASCII) and then reloaded in their new "home" from
> >the unloaded version.
>
> That is definitely the way to go when copying files from one machine
> to another when the other machine may be running a different version
> of the DBM library or different OS or different CPU architecture.
> -Joe
>
> --
> See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.




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

Date: 4 Mar 2001 03:42:17 GMT
From: inwap@best.com (Joe Smith)
Subject: Re: dbm hashes : Operation not permitted
Message-Id: <97sdip$p0u$1@nntp1.ba.best.com>

In article <GlGg6.720$Ld2.4018@eagle.america.net>,
Garry Williams <garry@zvolve.com> wrote:
>Many DBM files are *unmovable*.  That's because of hardware
>differences or disk information embedded in them, etc.

Huh?  The problem with embedded cylinder/track/sector values in DBM
files went away when IBM mainframes changed from ISAM to VSAM thirty
years ago.  DBM files can be moved from one directory to another on
the same machine with no problems.

>In general, DBM files should be unloaded into some serialized form
>(usually simple ASCII) and then reloaded in their new "home" from
>the unloaded version.

That is definitely the way to go when copying files from one machine
to another when the other machine may be running a different version
of the DBM library or different OS or different CPU architecture.
	-Joe

--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: Sun, 04 Mar 2001 06:30:12 GMT
From: otrcomm***NO-SPAM***@wildapache**NO-SPAM***.net (OTR Comm)
Subject: Dynamic naming of arrays or hashes
Message-Id: <3aa1dfba.2499244012@news.wildapache.net>

hello,

Is it possible to dynamically assign a name to an array?

For example, I want to have some code like so:

push(@past_due_$customer_id, $invoice_number);

and dynamically create the array @past_due_20087 for customer with id of
20087.

Has anyone ever done this and if so, how do I code it?

Thanks,
Murrah Boswell


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

Date: Sun, 04 Mar 2001 06:33:49 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Dynamic naming of arrays or hashes
Message-Id: <hllo6.301$T3.189279744@news.frii.net>

In article <3aa1dfba.2499244012@news.wildapache.net>,
OTR Comm <otrcomm***NO-SPAM***@wildapache**NO-SPAM***.net> wrote:
>hello,
>
>Is it possible to dynamically assign a name to an array?
>
>For example, I want to have some code like so:
>
>push(@past_due_$customer_id, $invoice_number);
>
>and dynamically create the array @past_due_20087 for customer with id of
>20087.
>

It's posible to do this using "symbolic" variables when you don't have 'use
strict' in force.  but that not what you usualy want to do in these cases.
I think that you realy want  to use a hash of hashes.

    push(@{$past_due{$customer_id}, $invoice_number);

Causes the hash %past_due to have an element 20087 that is an array
containing an $invoice_number. 

Read more about these ideas in the "Perl Data Structures Cookbook" (manual
page perldsc) that was part of your Standard Perl Distribution.

Good Luck!
chris

-- 
    This space intentionally left blank


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

Date: 4 Mar 2001 06:41:08 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Dynamic naming of arrays or hashes
Message-Id: <97so24$iel$2@bob.news.rcn.net>

OTR Comm <otrcomm***NO-SPAM***@wildapache**no-spam***.net> wrote:

> Is it possible to dynamically assign a name to an array?

Yes, but that's not the best way to handle your problem.

> For example, I want to have some code like so:

> push(@past_due_$customer_id, $invoice_number);

> and dynamically create the array @past_due_20087 for customer with id of
> 20087.

What you really want is a hash of array references (commonly called a 
"HoL" for "hash of lists").  Something like:

my %past_due;
push @{$past_due{$customer_id}}, $invoice_number;



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

Date: Sun, 04 Mar 2001 07:18:45 GMT
From: otrcomm***NO-SPAM***@wildapache**NO-SPAM***.net (OTR Comm)
Subject: Re: Dynamic naming of arrays or hashes
Message-Id: <3aa1eb3c.2502189918@news.wildapache.net>

On Sun, 04 Mar 2001 06:33:49 GMT, cfedde@fedde.littleton.co.us (Chris
Fedde) wrote:

>In article <3aa1dfba.2499244012@news.wildapache.net>,
>OTR Comm <otrcomm***NO-SPAM***@wildapache**NO-SPAM***.net> wrote:
>>hello,
>>
>>Is it possible to dynamically assign a name to an array?
>>
>>For example, I want to have some code like so:
>>
>>push(@past_due_$customer_id, $invoice_number);
>>
>>and dynamically create the array @past_due_20087 for customer with id of
>>20087.
>>
>
>It's posible to do this using "symbolic" variables when you don't have 'use
>strict' in force.  but that not what you usualy want to do in these cases.
>I think that you realy want  to use a hash of hashes.

Yeah, you are right:

I did get:

push(@{$customer_id}, $invoice_number);

to work and can reference like so:

foreach $invoice (@{$customer_id}) {
  print "$customer_id has invoice $invoice past due\n";
} # End foreach $invoice (@{$customer_id})

but only with 'use strict' turned off.

>
>    push(@{$past_due{$customer_id}, $invoice_number);
>
>Causes the hash %past_due to have an element 20087 that is an array
>containing an $invoice_number. 

I will use your approach so I can turn 'use strict' back on.

Thanks,
Murrah Boswell

>
>Read more about these ideas in the "Perl Data Structures Cookbook" (manual
>page perldsc) that was part of your Standard Perl Distribution.
>
>Good Luck!
>chris
>
>-- 
>    This space intentionally left blank



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

Date: Sun, 04 Mar 2001 06:27:18 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: FAQ 4.49:   How do I permute N elements of a list?
Message-Id: <aflo6.300$T3.189168640@news.frii.net>

In article <97s3d2$obd$1@news.panix.com>,
David Combs <dkcombs@panix.com> wrote:
>In article <dyzk6.291$zN2.189028864@news.frii.net>,
>Chris Fedde <cfedde@fedde.littleton.co.us> wrote:
>>
>>There are 303 files in the rotation right now.  4 are posted every day.
>>That makes the rotation 75.75 days or about 2.5 months per 'lap.'
>>
>
>What would be *especially* worth while would be
>the UPDATED (ie FIXED) faqs.
>
>Perhaps a prefix "UPDATED: " for subject-line.
>
>Also, we need to know which are "mere" changes
>in english text (style, spelling, and the like),
>
>and those that change the CODE.
>

Hum... An interesting idea.  I have no real way of marking changes
other than the output of the diff command.   I'm not sure what "mere" text
changes are though.  Since the discussion of "why" is as important as the
"how".  

chris
-- 
    This space intentionally left blank


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

Date: Sun, 04 Mar 2001 02:11:17 -0500
From: ZepHead <groovyt@erols.com>
Subject: Re: flock and close   with  empty read strangeness
Message-Id: <groovyt-69733E.02111604032001@virt-reader.news.rcn.net>

In article <slrn9a0s5c.qmu.mgjv@martien.heliotrope.home>,
 mgjv@tradingpost.com.au (Martien Verbruggen) wrote:


> 
> perldoc doesn't suggest anything, really. It's just a program to look at
> the standard perl documentation. If you refer to the documentation,
> maybe you should mention which documentation. perlopentut contains this
> information, for example.
> 
> Martien

well i said "suggests" for a reason    ; )

all the examples of hit counters and file read/write
with fast turn around all show sysopen and not open +<

if yor read one of the tutorials it even says WHY to use sysopen
over open.   Too me that suggest sysopen should be used.  Is it 100%
clear on this?  nope and why i said suggests and not demands   lol

Also think about my problem.
if i went with +< then how do I create the files?

if i do  >  then I'm right back to a race condidtion and the data wipes.
With 1000's of read/writes/creates a minute the time waiting for a lock
to creat the file and print the default data into it I will have other proccesses
reading from it before i get the lock.  

so sysopen IS better here and of course if i use sysopen
then there is no need for  +< to start out with or all the extra code
to check for exists.  (-e $dirpath)     etc...

so the code I ended up with also suggests because it works
so well that sysopen is the way to go.  

yes i feel the docs need to set the record straight here
and sadly they do not.  : (     (at least as far as i could find)


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

Date: Sun, 04 Mar 2001 02:29:04 -0500
From: ZepHead <groovyt@erols.com>
Subject: Re: flock and close   with  empty read strangeness
Message-Id: <groovyt-0B8FBB.02290404032001@virt-reader.news.rcn.net>

In article <slrn9a15sf.qmu.mgjv@martien.heliotrope.home>,
 mgjv@tradingpost.com.au (Martien Verbruggen) wrote:


> 
> You may very well say that, but it would be terrible to implement.


maybe.  


> Besides that, many programs do many many opens and closes in short
> times, without ever requiring a lock. I wouldn't want to sacrifice large
> amounts of performance in that area because there now has to be some
> logic that checks when the first operation on the file handle after the
> open occurs.

if feel if you can get a race condition then you need locks.
Now i would be more than happy to make it so you could turn if off
but if should default to on IMHO

say something like this

open FH, "> $file,  locks_off" or die $1;

but now it starting to look like sysopen  heh

> 
> Now, If you change your statement to 'open should have a mode that opens
> the file for write without truncating', 

well yes but that is sysopen and we have that already.   : )



> open FH, "%> $file" or die $!;   # open for write, truncate, LOCK_EX
> open FH, "%+> $file" or die $!;  # open for read/write, truncate, LOCK_EX
> open FH, "%< $file" or die $!;   # open for read, LOCK_SH
> open FH, "%>> $file" or die $!;  # open for append, LOCK_EX
> 
> etc..

yes .  Dump sysopen and combine all into  open would be a good thing IMHO
of course I'm have no idea what the differnces  are LOW LEVEL.

there very well might be reason open does what it does and sysopen does what it 
does


> 
> Maybe you can suggest it to the p5p and/or p6p in a more formal manner.
> I would probably not use it, or at least nto for another few years. I'm
> just too much accustomed to the way tis has been done for decades :)

; )   I hear you.  




thanks

Russ


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

Date: Sun, 04 Mar 2001 02:00:34 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: gif problems!!!
Message-Id: <df83at0boif6si1kcp61nktiut8d1v3qrc@4ax.com>

ToDa wrote:

>Why doesn't my gif-images shows? It works when I run the code as html
>document but not as perl code.
 ...
><img src="img/hr.gif" width="500" height="3">

Is your script in the same location as the HTML file that works?

-- 
	Bart.


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

Date: Sat, 3 Mar 2001 18:40:28 -0700
From: "bowman" <bowman@montana.com>
Subject: Re: Is Perl right for me?
Message-Id: <b5io6.1413$Kj3.6497@newsfeed.slurp.net>


Godzilla! <godzilla@stomp.stomp.tokyo> wrote in message
news:3AA188E5.1FD2CFCF@stomp.stomp.tokyo...
>
> Perl is not right for you.

your suggestion to use a database has some merit, proving that a perl of
wisdom can be found in the steaming pile of offal that constitutes the rest
of your post.

to the OP: you might want to look at MySql. It would allow you to structure
your data in an easily accesible form, and works very well with the Perl
DBI/DBD interface.





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

Date: Sat, 03 Mar 2001 20:16:33 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Is Perl right for me?
Message-Id: <3AA1C1A1.85A1A43D@stomp.stomp.tokyo>

bowwowman barked:
 
> Godzilla! provided a realistic perspective:

(snippage not noted by bowwowman)

> > Perl is not right for you.
 
> your suggestion to use a database has some merit, proving that
> a perl of wisdom can be found in the steaming pile of offal that
> constitutes the rest of your post.


"Your...."

"...holds some merit...."

"...proving a pearl of wisdom...."

"...in this steaming pile...."

"...offal which constitutes...."

"...the remainder of your...."


Use of "constipates" in place of "constitutes"
would be very punny! However, you are not punny.


Ahh... po' boy. Have I been brusing your fragile
masculine ego a bit too much lately, Frank?


Godzilla!
--
Kira, Professional Poker Player
  http://la.znet.com/~callgirl/android/poker.cgi
Kira, Professional Blackjack Player
  http://la.znet.com/~callgirl/android/blakjack.cgi
Androids And More
  http://la.znet.com/~callgirl/android.html


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

Date: Sun, 04 Mar 2001 02:18:55 GMT
From: Michael Carman <mjcarman@home.com>
Subject: Re: length op
Message-Id: <3AA1A7D6.4C7CD2D3@home.com>

Eduard Grinvald wrote:
> 
> Am i correct in assuming that length, given a pointer, only returns
> the size of the pointer in bytes, an not the actual object 
> referenced?

Bob already answered this quite well, so I won't bother.

> [I]s there any place on the web or is there a book that gives a
> listing of what the sizes of different data types are (int,strings,
> arrays, arrayrefs, etc).

Perl has three basic data types: scalar, array, and hash. A scalar is
any single value be it integer, float, character, string, reference,
etc. An array is a (named) list of scalars. A hash is an associative
array with strings for keys and scalars for values. There are no other
data types (e.g. 'int') at the user level.

Memory allocation is handled behind the scenes; you don't generally
know, need to know, or care how big something is. A scalar/array/hash is
as big as it needs to be to hold its data. There is some overhead, of
course; arrays take more memory than scalars, hashes take more than
arrays, but that's an implementation detail. As a programmer, you should
be focused on what the right tool for the job is, not how much space it
takes in your toolbox.

If you were just asking out of curiousity then that's probably as much
as you need to know to be a productive Perl programmer. If you're
targeting a specific problem, then maybe you really do need to know
more. Without knowing what you're trying to do, though, I can't tell
which of a half-dozen different directions to send you in. Lest we give
you bad advice and send you off on a wild goose chase, tell us what it
is you're trying to do.

-mjc


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

Date: Sat, 03 Mar 2001 21:40:19 +0500
From: "Aaron Cline" <acline@okstateerasecaps.edu>
Subject: Perl Newbie 2 questions
Message-Id: <5Kio6.203$Rx.2639@news.onenet.net>

Hello all:

First questions should be easy.  I need to know how to search though a
screen returned from a program that has a bunch of numbers surrounded by
brackets and put just the number into a variable.  Something like

	[123423.234234.236868388.3849293949394.29429398]

I want to grab the number (including periods) into a variable.  I am
currently accomplishing it with a couple of "split" commands, but I'm
sure there's a better, more efficient way.

Next question.  I want to start using perl to put and pull information
from a Postgre SQL database.  I really have no idea where to get started
at learning how to do this (I have bough the Camel version 3 book, but
it's not really helping me in that area).  Are there any really good
online perl/postgre tutorials that anyone can tell me about... I would
greatly appreciate it.

Thanks in advance.

Aaron Cline


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

Date: Sun, 04 Mar 2001 04:12:48 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Perl Newbie 2 questions
Message-Id: <3AA1C117.FB467D66@rochester.rr.com>

Aaron Cline wrote:
 ...
> First questions should be easy.  I need to know how to search though a
> screen returned from a program that has a bunch of numbers surrounded by
> brackets and put just the number into a variable.  Something like
> 
>         [123423.234234.236868388.3849293949394.29429398]
> 
> I want to grab the number (including periods) into a variable.  I am
> currently accomplishing it with a couple of "split" commands, but I'm
> sure there's a better, more efficient way.

Split is pretty efficient.  Something like:

    @numbers=split /[].[]/,$line;

should work fine, noting that $numbers[0] is null (if your string starts
and ends with brackets).  I'm confused, though, by your references to "a
bunch of numbers surrounded by brackets" and "the number (including
periods)".  If you want to just get whatever is between the brackets in
to a variable, that could be done with:

    ($variable)=$line=~/\[([^]]*)\]/;

> 
> Next question.  I want to start using perl to put and pull information
> from a Postgre SQL database.  I really have no idea where to get started
> at learning how to do this (I have bough the Camel version 3 book, but
> it's not really helping me in that area).  Are there any really good
> online perl/postgre tutorials that anyone can tell me about... I would
> greatly appreciate it.

You want to use DBI; .  See:

    perldoc DBI

for help.  With DBI, your Perl database code will be database
independent, and you can seek help from the whole community of DBI
users, instead of just Postgres users.  You will need to obtain the
appropriate DBD module for your database (probably DBD::Pg).
 ...
> Aaron Cline
-- 
Bob Walton


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

Date: Sat, 03 Mar 2001 23:00:28 +0500
From: "Aaron Cline" <acline@okstateerasecaps.edu>
Subject: Re: Perl Newbie 2 questions
Message-Id: <eVjo6.204$Rx.2431@news.onenet.net>

In article <3AA1C117.FB467D66@rochester.rr.com>, "Bob Walton"
<bwalton@rochester.rr.com> wrote:

I appreciate your post very much, however, can you tell me exactly what

($variable)=$line=~/\[([^]]*)\]/;

all means?  Too many symbols for me to follow it.

Could it also be written as $variable=($line =~ /\[([^]]*)\]/);

Thanks for the help.

> Aaron Cline wrote:
> ...
>> First questions should be easy.  I need to know how to search though a
>> screen returned from a program that has a bunch of numbers surrounded
>> by brackets and put just the number into a variable.  Something like
>> 
>>         [123423.234234.236868388.3849293949394.29429398]
>> 
>> I want to grab the number (including periods) into a variable.  I am
>> currently accomplishing it with a couple of "split" commands, but I'm
>> sure there's a better, more efficient way.
> 
> Split is pretty efficient.  Something like:
> 
>     @numbers=split /[].[]/,$line;
> 
> should work fine, noting that $numbers[0] is null (if your string starts
> and ends with brackets).  I'm confused, though, by your references to "a
> bunch of numbers surrounded by brackets" and "the number (including
> periods)".  If you want to just get whatever is between the brackets in
> to a variable, that could be done with:
> 
>     ($variable)=$line=~/\[([^]]*)\]/;
> 
>> 
>> Next question.  I want to start using perl to put and pull information
>> from a Postgre SQL database.  I really have no idea where to get
>> started at learning how to do this (I have bough the Camel version 3
>> book, but it's not really helping me in that area).  Are there any
>> really good online perl/postgre tutorials that anyone can tell me
>> about... I would greatly appreciate it.
> 
> You want to use DBI; .  See:
> 
>     perldoc DBI
> 
> for help.  With DBI, your Perl database code will be database
> independent, and you can seek help from the whole community of DBI
> users, instead of just Postgres users.  You will need to obtain the
> appropriate DBD module for your database (probably DBD::Pg).
> ...
>> Aaron Cline


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

Date: Sun, 4 Mar 2001 13:10:32 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: question on how to code a program
Message-Id: <slrn9a390n.300.mgjv@martien.heliotrope.home>

On 4 Mar 2001 01:45:10 GMT,
	David Combs <dkcombs@panix.com> wrote:
> In article <3a96d6fc.15701003@nntp.ix.netcom.com>,
> Torque <gifg@netzero.netNOSPAM> wrote:
>>I'm trying to code a cgi program with perl to count the number of
>>years, months, days, hours, minutes, and seconds since a given date.
>>
>>I thought I could use Matt's Script archive's countdown.pl as an
> 
> What, where, and what is opinion on "Matt's Script Atchive"?

what: An archive of Perl programs, with a emphasis on CGI.

where: Do a search on Google.

opinion: Don't bother with it. Stay away from it. The only thing you can
get out of those scripts is how _not_ to write programs.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | +++ Out of Cheese Error +++ Reinstall
Commercial Dynamics Pty. Ltd.   | Universe and Reboot +++
NSW, Australia                  | 


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

Date: 4 Mar 2001 06:28:49 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Reading non-ASCII from XML file using DOM module
Message-Id: <97snb1$iel$1@bob.news.rcn.net>

Thomas Theakanath <thomastk@prodigy.net> wrote:
> I use XML::DOM module to read a simple XML file with following format, that
> has non-ASCII chars in the text nodes.

> <?xml version="1.0" encoding="ISO-8859-1"?>
> <content>
>    <matter>rrÎ aÏkA d]ukA ejgjuRCADkA Lisx |MkilÍj[
> rrÎ akmjujqdX Qfk]jiØk;
> do}AsfMju Qgk dkc{fjÙjg[
> Lixksm sdlhkckdX djhk]jSrl]j;</matter>
> </content>

> I use getData method to read the values of text nodes. But the non-ascii
> letters are replaced with some junk characters in the result. I have not
> tested the DOM methods to write the data, because the XML files get created
> without using DOM methods.

Regardless of what your input encoding is, XML::Parser (which is what 
XML::DOM uses to read XML) delivers all characters in UTF-8 encoding.  
That's what you're getting.  If you want some code to convert UTF-8 back 
into 8859-1, look at the source for XML::TokeParser or XML::TiePyx.


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

Date: Sat, 03 Mar 2001 23:17:09 -0800
From: scott <unixman@mindspring.com>
Subject: Re: REVISED: Hash/array woes...
Message-Id: <3AA1EBF5.720C3F18@mindspring.com>

Tad - thanks much for the response.  However, what I posted as an example
of an output model, along with the description of the three database
columns, make for a pretty generic problem.  I'll try to put a bit more
meat on the problem here:

The idea is for a routine to create a formatted, indented list of these
values, so that it will appear something along the lines of:

CATEGORY 1
    Subcategory 1
    Subcategory 2
        Sub-Subcategory 1
        Sub-Subcategory 2
CATEGORY 2
    Subcategory 1
    Subcategory 2
CATEGORY 3
CATEGORY 4

Also of note is that there is a need to have an unlimited number of
category/subcategory relationships.

The values are fetched from a database table, with three relevant columns:
ID, NAME, PARENT_ID.  Consider this mock data:

ID,NAME,PARENT_ID
1,Sports,0
2,Investing,0
3,Computers,0
4,Football,1
5,Baseball,1
6,Soccer,1
7,Mutual Funds,2
8,Online Trading,2
9,Draft Picks,4

The ID field (first column) is a unique identifier for each category or
subcategory in the database.  The NAME is a simple description.  The
PARENT_ID is simply the ID of the parent category.  For example, Mutual
Funds is a child category of category ID 2, Investing.

Given the above data, the perl sub should spit out a scalar formatted for
an HTML SELECT list (Replacing HTML chevrons with brackets for ease of
reading):

[OPTION VALUE=1] Sports
[OPTION VALUE=4] ... Football
[OPTION VALUE=9] ........Draft Picks
[OPTION VALUE=5] ... Baseball
[OPTION VALUE=6] ... Soccer
[OPTION VALUE=2] Investing
[OPTION VALUE=7] ... Mutual Funds
[OPTION VALUE=8] ... Online Trading
[OPTION VALUE=3] Computers

Currently, I slurp the table (it's fairly small) and create the following
structure:

while(@result = $sth->fetchrow_array) {
      $channel_hash{$result[0]} = [($result[1], $result[2])];
}

For a frame of reference above, result[0] is the ID, result[1] is the NAME,
and result[2] is the PARENT_ID.

My challenge is to cobble up working code to actually navigate the data
structure as quickly and as efficiently as possible, and of course, spit
out the actual code.  Ideally, the list would be sorted by top-level
categories first, followed by sorts within each as needed.

Looking forward to hearing possible streamlined approaches to this.

Cheers.
Scott

Tad McClellan wrote:

> You have shown what you want the output to look like. Good.
>
> You have not shown what input would make that output. Bad. (hint again)
>
> You are asking potential answerers to synthesize input data
> so that they can test their answers before posting them.
>
> That amount of extra work put me "over the top" on my per-article
> time budget, so I can' work on answering your post. On to the next one.
>
> Post some input data, and the corresponding desired output
> (and don't fluff up the output with HTML, you can add that later).
>
> --
>     Tad McClellan                          SGML consulting
>     tadmc@augustmail.com                   Perl programming
>     Fort Worth, Texas



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

Date: Sun, 04 Mar 2001 06:53:06 GMT
From: "Joe Moore" <joemoore@att.net>
Subject: Re: Submitting Forms from Code
Message-Id: <mDlo6.2930$Ey1.209541@bgtnsc06-news.ops.worldnet.att.net>


"brian d foy" <comdog@panix.com> wrote in message
news:comdog-BD561F.17515215022001@news.panix.com...

> > > I have built a Perl Script which grabs data from a web page and
performs
> > some
> > > calculations on that data. The calculations returned need to be
entered
> > into a
> > > form on another webpage. Is there a way that I can enter the returned
data
> > into
> > > the webpage form and submit it from the Perl script?
>
>
> > Sure, but you don't really want to load it into another webpage, you
want
> > your perl script to emulate the webpage, right?
>
> > Then you can just redirect to the page you are submitting to
> >
> > print "Location: $url?$query_string\n\n";
>
> that only works (maybe) if your script is another CGI script. based
> on the OP's question, that doesn't sound right though.
>
> the HTTP::Request docs show an example that answers the question:
>
>     http://search.cpan.org/doc/GAAS/libwww-perl-5.50/lib/LWP.pm
>
> --
> brian d foy <comdog@panix.com>
>

Thanks for adding to the confusion.  Clearly the OP wants to insert the data
into a web page and automatically submit it and you can't do that.  You have
to do it the easy way, like I explained, or if the form requires a POST
submission, then they can use a request as you indicated.  However, if the
user expects to put the data into a webpage form that executes JavaScript,
then neither of our solutions will work.  I figured I'd go after the nail
before looking at the splinter.




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

Date: Sun, 04 Mar 2001 06:55:56 GMT
From: "Joe Moore" <joemoore@att.net>
Subject: Re: Uploading a file
Message-Id: <0Glo6.2931$Ey1.210141@bgtnsc06-news.ops.worldnet.att.net>

I've been doing Perl since 1995.  I thought I might help out on this group,
but on second thought there are better experts around.

"brian d foy" <comdog@panix.com> wrote in message
news:comdog-1B70C7.17433515022001@news.panix.com...
> In article <Go%i6.11959$Nj5.772872@bgtnsc07-news.ops.worldnet.att.net>,
> "Joe Moore" <joemoore@att.net> wrote:
>
> > 0A in a text file is a "\n" character.  0D is the "\r" character.
>
> not really.  it depends on what your operating system calls those
> characters.
>
> --
> brian d foy <comdog@panix.com>
>




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

Date: Sun, 04 Mar 2001 07:05:05 GMT
From: "Joe Moore" <joemoore@att.net>
Subject: Re: Uploading a file
Message-Id: <BOlo6.2933$Ey1.209863@bgtnsc06-news.ops.worldnet.att.net>

Sorry.

'0A' is a newline character as defined in ASCII
'0D' is a carriage return character as defined in ASCII

The fact that these bad boys keep getting switched in an upload file is
clearly an indication of an improper conversion.

My response to use binary mode may have helped.  Your response?

Well you proved you are way smarter than me, congratulations.

I know when I'm not wanted <sob> goodbye cruel Perl world </sob>

"Alan J. Flavell" <flavell@mail.cern.ch> wrote in message
news:Pine.LNX.4.30.0102160249300.17336-100000@lxplus003.cern.ch...
> On Fri, 16 Feb 2001, Joe Moore wrote:
>
> > 0A in a text file is a "\n" character.
>
> \n is not a "character", it's an end of line.  How that is represented
> is platform-dependent.
>
> >  0D is the "\r" character.
>
> And so on.  You really ought to make yourself more familiar with the
> discussion in perldoc perlport, before offering misleading advice to
> innocent readers.
>
> > In Unix text files all lines end with a "\n".
>
> In Perl, all lines end by definition in "\n", irrespective of
> platform.  But what that "\n" is, is platform-dependent.
>
> > "Mark" <mark_shutt@hotmail.com> wrote in message
> > news:t8ot4de4n71a28@corp.supernews.com...
>
> Oh dear, an upside-down fullquoter.  Figures.
>
> The questioner should also, of course, make themselves familiar with
> the discussion in perldoc perlport.
>




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

Date: Sun, 04 Mar 2001 03:47:02 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: using blat in a perl script to send form input
Message-Id: <3AA1BB0D.4566BE62@rochester.rr.com>

Pamela Polk wrote:
> 
> I have a situation that I am having a problem with. I have successfully done
> the below on linux with the sendmail command. I tested the last portion of
> the email on linux and it works.
> 
> Background:
> Hardware is an HP Netserver LX Pentium Pro 180 384mb of Ram
> MS Windows 2000 Advanced Server
> IIS 5
> ActivePerl 5.0 Build 521
 ...
> $blatpath='d:/blat186/blat.exe ';

Since you are sending a command to DOS to be executed, it must conform
to DOS rules:  \ is required for a path separator.  Perl won't fix that
one for you (and if you think about it, you wouldn't want it to,
either).  And, of course, you'll have to observe Perl's quoting rules
around \'s to ensure that you actually really do send \'s in the right
places and quantities to DOS.

> 
 ...
> Pam Polk
 ...
-- 
Bob Walton


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

Date: Sat, 03 Mar 2001 21:25:32 -0500
From: Jay Tilton <nouser@emailunwelcome.com>
Subject: Re: Why doesnt it work. The whole list deletes.
Message-Id: <kj93atkvb61tbuevoiskcg5f80mjg3oval@4ax.com>

"Kalle Anka" <kalle@tvettsvamp.a.se> wrote:

>Same result! The whole list is deleted.
>After I wrote "use strict;"  ,   = Internal server error

At the command line, have perl run a check on it before you try to run
it from the web server.
  perl -c unsub.pl

>$email = param('address');

Where did 'address' come from?

> <p>Email Address: <input type="text" size="20" name="email">

According to this line of the html source you posted earlier,
the parameter you want is 'email', not 'address'.

A careful person would perform some validation on the value of $email
before stuffing it into a regex that will delete data.  The logical
first check would be to make sure it's not an empty string.



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

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 V10 Issue 410
**************************************


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