[18888] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1056 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 4 18:07:03 2001

Date: Mon, 4 Jun 2001 15:05:21 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <991692321-v10-i1056@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 4 Jun 2001     Volume: 10 Number: 1056

Today's topics:
    Re: 2 questions about flock <keesh@users.sf.net>
        accept input from client <nguyentn@utdallas.edu>
        AuthCookie extension module working with text files (ht (Gururaj Upadhye)
    Re: Background start of program in CGI? <buggs-clpm@splashground.de>
    Re: Complex Parser... <mischief@velma.motion.net>
        Deleting old files <cochise@sky.net>
    Re: Deleting old files (Randal L. Schwartz)
    Re: Deleting old files <mischief@velma.motion.net>
    Re: Deleting old files (Randal L. Schwartz)
    Re: Deleting old files <mischief@velma.motion.net>
    Re: dos commands <bart.lateur@skynet.be>
    Re: getpwnam - Unimplemeted Function <mischief@velma.motion.net>
    Re: Help a script to prompt to input and have those inp <c_clarkson@hotmail.com>
    Re: Help with Range operators (Eric Bohlman)
    Re: HELP: modifying a referenced array from a library s <ren@tivoli.com>
        How to add a 0 in front of single number??? <Rene.Scheibe@gmx.net>
    Re: How to add a 0 in front of single number??? <bart.lateur@skynet.be>
    Re: How to add a 0 in front of single number??? <hartleh1@westat.com>
    Re: How to add a 0 in front of single number??? (Rafael Garcia-Suarez)
    Re: How to add a 0 in front of single number??? <rsherman@ce.gatech.edu>
    Re: locking files before writing data (?) <bart.lateur@skynet.be>
        Newb needs help with input from forms <shawntaub@yahoo.ca>
    Re: Newb needs help with input from forms <mischief@velma.motion.net>
    Re: Newb needs help with input from forms (Jon Bell)
        OT :: What to do if you've been kill filed <lmoran@wtsg.com>
        Pack, Unpack help (I think!) (Sam)
    Re: Passing XML string to the URL (Eric Bohlman)
    Re: Passing XML string to the URL <m.astrakhanskaya@gte.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 04 Jun 2001 18:24:08 GMT
From: "Ciaran McCreesh" <keesh@users.sf.net>
Subject: Re: 2 questions about flock
Message-Id: <cnQS6.550$IY1.143032@news1.cableinet.net>

In article <3B1BC99B.5076A474@salford.ac.uk>, "Mark Grimshaw"
<m.grimshaw@salford.ac.uk> said:
> Thanks.  So to be safe/efficient, use LOCK_EX for writing and LOCK_SH
> for reading?

Ya, pretty much. I sometimes skip LOCK_SHing a file if I'm fairly sure
no-one else will be using it, but for safety it's a good idea.

> When you say this:
>> "Obviously, there can only ever be
>> one LOCK_EX on a file at a time."
> do you actually mean file or filehandle?

A file. Well, techincally, I guess, a resource, since in theory locking
isn't necessarily limited to files, but basically a file. A file handle
is just a way of accessing a file. The lock is established via the handle
(that's not too elegant an explanation...) but it acts upon the file the
handle refers to.

I'm not entirely sure what happens on *nix if you flock a symlinked file,
I would guess it would lock the file being linked to...

-- 
Ciaran McCreesh
mail:         keesh at users dot sf dot net
web:          http://www.opensourcepan.com


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

Date: Mon, 4 Jun 2001 15:06:28 -0500
From: "nguyentn" <nguyentn@utdallas.edu>
Subject: accept input from client
Message-Id: <9fgpod$s6t$1@news.utdallas.edu>

hello,
What syntax command should I use to let the Server program get the input
from a Client program.
Righnow, I could send a statement from a server to a client by using a print
statement with a client name.
I couldn't do the reverse.
Please help.





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

Date: 4 Jun 2001 13:07:30 -0700
From: gururaj@powertec.com (Gururaj Upadhye)
Subject: AuthCookie extension module working with text files (htpasswd format)
Message-Id: <23c54ab6.0106041207.67aac8d0@posting.google.com>

I am looking for a module that extends Apache::AuthCookie, 
similar to AuthCookieDBI that works with text files generated by htpasswd or
user_manage.cgi. 

Thanks and Regards,
-Gururaj.


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

Date: Mon, 4 Jun 2001 20:32:40 +0200
From: buggs <buggs-clpm@splashground.de>
Subject: Re: Background start of program in CGI?
Message-Id: <9fgkaa$4a3$00$1@news.t-online.com>

Steen Suder wrote:


> I've tried with system(), exec(), backticks and qx{}, neither does what
> I what:
> B runs C, that runs in the background after B is terminated.
> 
> It might be a problem with the program (pptpd), but is there a way that
> I can use to force background run/detach of C?
> 

Consider fork() perldoc -f fork

Buggs


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

Date: Mon, 04 Jun 2001 19:31:08 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Complex Parser...
Message-Id: <thnofs7dk1cg04@corp.supernews.com>

Joe B <joeb@jagas.demon.co.uk> wrote:
> Hello All,

> I am trying to write a script that will take input from a web form and
> parse
> it, however I am having some difficulties. Any help will be appreciated:

Instead of a language parser for this sort of thing (which would
help programmers if they take the time to use all the features),
you might consider breaking things off into separate text boxes.

    match this EXACT PHRASE:    [__________________]
    match ALL of these words:   [__________________]
    match ANY of these words:   [__________________]
    EXCLUDE all of these words: [__________________]

Actually, this turns out to look much like
 http://groups.google.com/advanced_group_search for better or worse.
It's a simple interface for the user, and it's simpler to build a
database query from this than from a string you must parse by tokens.
It cuts down on syntax errors from your end users by a great margin,
too, making it not only easier but also less frustrating to use.

Chris

-- 
Try not. Do, or do not. The Force is binary. -- Yoda,
The Empire Strikes Back (paraphrased)



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

Date: Mon, 04 Jun 2001 14:55:59 -0500
From: Steve <cochise@sky.net>
Subject: Deleting old files
Message-Id: <3B1BE7CF.81D804ED@sky.net>

Is there a way to delete files that are older that a certain time?  

I've got some temporary graphics whose names are based on the time that
they were created using localtime.

	991680688.gif
	991679373.gif
	etc.

At the moment I'm using:

	  unlink <9*.gif>;

and deleting them all.

I would rather delete anything that is older than say 2 hours and keep
the more recent files ... which would in turn be deleted later on in the
day.

Any help, or direction to the appropriate on-line resource, would be
appreciated.

Steve


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

Date: 04 Jun 2001 13:12:13 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Deleting old files
Message-Id: <m17kysm2ci.fsf@halfdome.holdit.com>

>>>>> "Steve" == Steve  <cochise@sky.net> writes:

Steve> Is there a way to delete files that are older that a certain time?  
Steve> I've got some temporary graphics whose names are based on the time that
Steve> they were created using localtime.

Steve> 	991680688.gif
Steve> 	991679373.gif
Steve> 	etc.

Steve> At the moment I'm using:

Steve> 	  unlink <9*.gif>;

Steve> and deleting them all.

Interesting.  Are those named for the time(2) Unix Epoch value?  If
so, do you realize that rolls over on september 8th of this year to be
1-something instead?  And they won't sort in alphabetic order either.

Steve> I would rather delete anything that is older than say 2 hours
Steve> and keep the more recent files ... which would in turn be
Steve> deleted later on in the day.

@goners = grep -M > (2 / 24), <*.gif>;

Do what you will with @goners.

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Mon, 04 Jun 2001 20:52:26 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Deleting old files
Message-Id: <thnt8a2fpvh219@corp.supernews.com>

Steve <cochise@sky.net> wrote:
> Is there a way to delete files that are older that a certain time?  

> I've got some temporary graphics whose names are based on the time that
> they were created using localtime.

> 	991680688.gif
> 	991679373.gif
> 	etc.

> At the moment I'm using:

> 	  unlink <9*.gif>;

> and deleting them all.

The Unix epoch will soon be past the poitn of starting with '9'.

> I would rather delete anything that is older than say 2 hours and keep
> the more recent files ... which would in turn be deleted later on in the
> day.

Let's say you have an array of the filenames as returned by
readdir(). This should let you subtract two hours from the
current time, and compare the value to the first part of the
file name for each file:


    my $time = time - ( 2 * 3600 );
    for (@file) {
        next if -d $_;
        /^(.*?)\./;
        unlink( $_ ) if $time > $1;
    }

Then again, you might want to name the files with something
which isn't exactly an epoch time for the first section of the
file name. The stat() function can give you seconds since the
last modification of a file. If you wanted to judge something
on the last time it was accessed (as in aging out pictures by
popularity on a website), you can also get that from stat().
There are -x operator shortcuts if you're working with days
instead of smaller units.

    my $time = time - 2 * 3600;
    for ( @file ) {
        next if -d $_;
        my $mod_time = ( stat ($_) )[9];
        unlink ( $_ ) if $time > $mod_time;
    }


You could refigure $time for each file, but that's more
computation, and you probably were referring to the age
of the files when the script began.

> Any help, or direction to the appropriate on-line resource, would be
> appreciated.

Additional help can be found at 'perldoc -f stat' and 'perldoc -f time'.
You may also want to check out the opendir(), readdir(), and closedir()
calls if you do not know those already.

The code above was tested using the wonderful Unix utility touch(1).
If you have any code which needs to be tested and which relies on
the ages of files, you need a version of touch(1) for your OS. There
are versions available for many platforms, and it has other uses, too.

Chris
-- 
If they can get you asking the wrong questions, they don't
have to worry about the answers.
  -- Thomas Pynchon, Gravity's Rainbow



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

Date: 04 Jun 2001 14:12:33 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Deleting old files
Message-Id: <m1snhgj6f2.fsf@halfdome.holdit.com>

>>>>> "Chris" == Chris Stith <mischief@velma.motion.net> writes:

Chris>         /^(.*?)\./;
Chris>         unlink( $_ ) if $time > $1;

Oooh ouch OOOh  ouch ouch ouch.  Don't use $1 unless you are SURE
that the regex did in fact match.  Otherwise, you'll be deleting the
next file using the previous file's criterion!

Bad code.  No donut. :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Mon, 04 Jun 2001 21:42:23 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Deleting old files
Message-Id: <tho05vi793620a@corp.supernews.com>

Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>>>>> "Chris" == Chris Stith <mischief@velma.motion.net> writes:

> Chris>         /^(.*?)\./;
> Chris>         unlink( $_ ) if $time > $1;

> Oooh ouch OOOh  ouch ouch ouch.  Don't use $1 unless you are SURE
> that the regex did in fact match.  Otherwise, you'll be deleting the
> next file using the previous file's criterion!

> Bad code.  No donut. :)

Ouch indeed. Make those two lines above into this:

    if ( /^(.*?)\./ ) { unlink( $_ ) if $time > $1 }

There are actually _two_ lessons to be learned here. The other
is that if you say you're sure of your data's format, someone
will provide a fragile solution which only works if your
assumptions about your data are correct.

Randal's code is simpler and more concise than my corrected
code anyway. ;-)

Chris

-- 
Disclaimer: Actual product may not resemble picture in ad in any way.



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

Date: Mon, 04 Jun 2001 19:15:58 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: dos commands
Message-Id: <ainnhtg2cn8bac94cmfji8bmq3vlvrsnip@4ax.com>

AtnNn wrote:

>How can I use dos commands in perl, and control the input and output?

system(), `...`, exec(). `...`simply returns the output to STDOUT. You
can redirect STDERR to a file before calling the program. Perhaps, in
the newer Win32 versions, open pipe to program might work too, I don't
know.

-- 
	Bart.


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

Date: Mon, 04 Jun 2001 19:18:49 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: getpwnam - Unimplemeted Function
Message-Id: <thnnopequ7s137@corp.supernews.com>

KeysDigital <shmink@keysdigital.com> wrote:
> Hello Group:

> I'm trying to get a script running on an NT maching running IIS and Perl
> 5.6. The code I'm having a problem with is as follows:

> sub CheckLogin {
>    if (kDebugLevel >= kShowSubroutines) { print STDERR "CheckLogin - \n"; }
>    (my $name, my $passwd) = getpwnam($userlogin);
>    if ($passwd ne "") {
>  if (crypt(&Obscure($userpassword), kEncryptedPassword) eq
> kEncryptedPassword) {
>            $cgi->delete("userlogin");
>            $cgi->delete("userpassword");
>      return 1;
>  }
>     }
>    $cgi->delete_all();
>     return 0;
>  }

> When I call the program, I get an error message saying that "The getpwanm
> function is unimplemented at XXXXXXX  line 382".

This is because NT doesn't seem to support getpwnam(). Can
anyone confirm or debunk this? If NT does support all of
POSIX.1/1990 through the so-called POSIX subsystem, then
perhaps Perl on NT should support that subsystem.

According to the GNU glibc documentation, it seems this is a
POSIX.1/1990 call. Can anyone confirm or debunk this? This also
seems to be the case for all POSIX.1 documentation I can find.
Perhaps someone should tell Microsoft that if they want to be
known for POSIX-compliant software, they should start by
implementing POSIX.1/1990 in their C library. Cygwin seems to
handle the POSIX.1/1990 system database calls just fine! Try
using Cygwin if you must program on Windows.

According to the MSDN, the following is needed to allow a POSIX
application to run:

    Running POSIX Applications
        POSIX applications can be started from a Windows NT console
        window (command prompt), File Manager, Program Manager, or
        by invocation from within another POSIX application.


    The POSIX files
        The following files are required to support the POSIX
        subsystem and run POSIX applications:

        PSXSS.EXE, the POSIX subsystem server

        PSXDLL.DLL, the POSIX dynamic-link library

        POSIX.EXE, the POSIX console session manager


    File systems
        POSIX requires a certain amount of functionality from the
        file system, such as the ability for a file to have more
        than one name (or hard links), and case-sensitive file
        naming. Neither FAT nor HPFS supports these features,
        which is another reason why a new file system was required
        for Windows NT. NTFS supports both hard links and
        case-sensitive naming. If you want to run in a
        POSIX-conforming environment, you need at least one NTFS
        disk partition on your computer.

        You can run POSIX applications from any Windows NT file
        system. If the application does not need to access the file
        system, the application will run with no problems. However,
        if the application does require access to the file system,
        there is no way to guarantee that it will behave correcly
        on a non-NTFS disk partition.

> Folks, I'm stumped. If I try "use User::pwent" I get the same message
> (different file and line #).

Again, my best advice is to try Cygwin or a more standards-compliant
OS.

> Any suggestions or fixes would be appreciated.


Chris

-- 
People understand instinctively that the best way for computer programs to
communicate with each other is for each of the them to be strict in what they
emit, and liberal in what they accept. The odd thing is that people themselves
are not willing to be strict in how they speak, and liberal in how they listen.
 -- Larry Wall, 2nd State of the Onion Address, August 1998



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

Date: Mon, 4 Jun 2001 14:24:30 -0500
From: "Charles K. Clarkson" <c_clarkson@hotmail.com>
Subject: Re: Help a script to prompt to input and have those input add or append certain lines in a text file
Message-Id: <A779E843681012E9.A830A653F5EEA175.616A0F8174F5503E@lp.airnews.net>


"Steve" <stpham@qwest.net> wrote in message
news:P9QO6.220$a32.34759@news.uswest.net...
: Hi all,
:
: I am new to perl and I need help to write to perl script
: that will ask certain values and have those values enter
: or modify on a certain of a specific text file.
:
: For example: Let say I have a text file that looks like
: this when I open with a notepad.
:
:         [UserDate]
:            ComputerName = computer1
:
:         [Params.TCPIP.Adapter1]
:             IPAddress = 10.0.0.5
:             SubnetMask = 255.0.0.0
:             DefaultGateway = 10.0.0.1
:
:         [Etc....]
:
: I wanted to change or modify the line ComputerName,
: IPAddress, SubnetMask, and DefaultGateway, Etc...
:
: I would I go about writting a perl script to do
: that I think you are a perl programmer it would not
: be so hard to write this script.

    I wrote a short sub to do just this when I was
learning about wantarray, please feel free to fold,
spindle, and mutilate it to your hearts content.

    You can find it at:
<http://groups.yahoo.com/group/perl-beginner/files/ini.pl.txt>


HTH,
Charles K. Clarkson



Don't vote . . . you'll only encourage them.





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

Date: 4 Jun 2001 18:06:54 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Help with Range operators
Message-Id: <9fginu$75k$1@bob.news.rcn.net>

Jason C. Hill <jhill@technoslave.net> wrote:
> That just gets a DUH...I know this...why didn't I do it?!?!!? *grin*
> I've run in to this problem before...that's the solution I took...I just
> didn't go through and reuse any of my code ;-)

Psychological set strikes again.  Since you know how to use the range 
operator (something many Perl programmers don't), whenever you use it 
you're going to see what you meant to write rather than what you actually 
did write.  Once I had some assembly code with a rather mysterious bug 
that turned out to be the result of pushing more things onto a stack than 
got popped off; since I *knew* how a stack worked, I managed to see the 
code that did the pop even though I'd forgotten to write it.



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

Date: 04 Jun 2001 13:23:46 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: HELP: modifying a referenced array from a library subroutine...
Message-Id: <m33d9gxfwt.fsf@dhcp9-173.support.tivoli.com>

On Sat, 02 Jun 2001, goldbb2@earthlink.net wrote:

> Anno Siegel wrote:
>> 
[snip]
>>     push @{$sysressource ->{operators}}, $newuser;
[snip]
> 
> Considering that lines of code can get long and unpretty if you do
> this, you might want to make an alias for it... for example
> 
> 	local *the_operators = $sysressource->{operators};
> 	push @the_operators, $newuser;
> 
> This can result in much clearer code than explicit dereferencing.

No need to invoke the glob syntax.  Simply copying the reference is
sufficient:

  my $operators_ref = $sysressource->{operators};
  push @$operators_ref, $newuser;

unless that "@$" is unpretty enough to bother you.  The benefit of
avoiding the glob seems well worth it.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Mon, 4 Jun 2001 22:21:42 +0200
From: "Rene Scheibe" <Rene.Scheibe@gmx.net>
Subject: How to add a 0 in front of single number???
Message-Id: <9fgqhj$40iac$1@ID-65612.news.dfncis.de>

I tried this:
$d =~ s/(\d)(?!\d)/0$1/;

My thought was, that it test if there
is a digit (\d) but no other (?\d) and
then a 0 in front of my number.
e.g.: "5" -> "05"

But something is a bit other than I
thought :-)




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

Date: Mon, 04 Jun 2001 20:40:55 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: How to add a 0 in front of single number???
Message-Id: <uksnhto3k6i184hs263h90cqred8hvbmch@4ax.com>

Rene Scheibe wrote:

>I tried this:
>$d =~ s/(\d)(?!\d)/0$1/;

>But something is a bit other than I
>thought :-)

$d = sprintf '%02d', $d;

-- 
	Bart.


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

Date: Mon, 04 Jun 2001 16:42:22 -0400
From: Henry Hartley <hartleh1@westat.com>
Subject: Re: How to add a 0 in front of single number???
Message-Id: <3B1BF2AE.B407B1BB@westat.com>

Rene Scheibe wrote:
> 
> I tried this:
> $d =~ s/(\d)(?!\d)/0$1/;
> 
> My thought was, that it test if there
> is a digit (\d) but no other (?\d) and
> then a 0 in front of my number.
> e.g.: "5" -> "05"
> 
> But something is a bit other than I
> thought :-)

perldoc -q pad
How do I pad a string with blanks or pad a number with zeroes?

-- 
Henry Hartley


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

Date: 4 Jun 2001 20:43:50 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: How to add a 0 in front of single number???
Message-Id: <slrn9hnrij.gi.rgarciasuarez@localhost.localdomain>

Rene Scheibe wrote in comp.lang.perl.misc:
> I tried this:
> $d =~ s/(\d)(?!\d)/0$1/;
> My thought was, that it test if there
> is a digit (\d) but no other (?\d) and
> then a 0 in front of my number.
> e.g.: "5" -> "05"

Perhaps you want to use sprintf :

  $y = sprintf '%02d', $x;

Look up sprintf() in perlfunc, and also the manpage for printf(3) if you
have it.

-- 
Rafael Garcia-Suarez


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

Date: Mon, 04 Jun 2001 17:40:39 +0500
From: Robert Sherman <rsherman@ce.gatech.edu>
Subject: Re: How to add a 0 in front of single number???
Message-Id: <3B1B81C7.8791872A@ce.gatech.edu>

Rafael Garcia-Suarez wrote:

> Rene Scheibe wrote in comp.lang.perl.misc:
> > I tried this:
> > $d =~ s/(\d)(?!\d)/0$1/;
> > My thought was, that it test if there
> > is a digit (\d) but no other (?\d) and
> > then a 0 in front of my number.
> > e.g.: "5" -> "05"
>
> Perhaps you want to use sprintf :
>
>   $y = sprintf '%02d', $x;
>
> Look up sprintf() in perlfunc, and also the manpage for printf(3) if you
> have it.
>
> --
> Rafael Garcia-Suarez

not certain whether OP wants formatting solution (in which case sprintf
works) or pattern matching, but if the latter:

perl -e '$d="jabber67foo7widget 8 bar 8000"; $d=~s/(?<=\D)(\d)(?=\D)/0$1/g;
print $d."\n";'

-rob



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

Date: Mon, 04 Jun 2001 19:21:26 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: locking files before writing data (?)
Message-Id: <knnnhtc7t4073hnp9pl7kgn4ji74h3ejrb@4ax.com>

Muddy Cat wrote:

>Oddly... the code has just been appending
>to the end of the file, rather than overwriting. The "seek" bit has since
>been taken out. I originally did want "newest at the top" but, as you say,
>it's a bit too much of a chore.

Perhaps you want a different approach. Removing the first line from a
log every time a new line gets added, is a bit of a chore. Hav you
thought of rotating logs? Once a file gets too big, you open a new log
file, archiving older logs. After some files are opened, the oldest log
file gets discarded.

There is even a module on CPAN for this, under the name Logfile::Rotate.




-- 
	Bart.


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

Date: Mon, 4 Jun 2001 16:10:24 -0400
From: "Shawn Michael Taub" <shawntaub@yahoo.ca>
Subject: Newb needs help with input from forms
Message-Id: <9fgq4l$d0i$1@newsmaster.axxent.ca>

    Hi guys, I was reffered here on several occasions by a friend and I was
slightly hesitant to do so, considering as to how I don't actually have my
own news program.  Right now I'm being forced to use my dad's, and it'll
prove to be a pain until I can actually find a working web based news
service.  I'll be able to check back once in a while, but in the meantime, I
have a giant assignment due and I'm extremely screwed.
    Essentially, I offered to make a Perl Tutorial in a very short amount of
time, and I still don't get a number of things.  I'm trying right now to
understand how Perl deals with data input from a form.  POST, GET, Regular
Expressions, Foreach, %ENV, QUERY_STRING, CONTENT_LENGTH and other things
involved in simply taking data from a form are really bugging me.  Yeah,
that's pretty much well everything.  But I finally understood Perl's
perversion of data structures as well as all the extremely basic stuff.
Then I stumbled across http://www.abiglime.com/articles/cgi/021098.htm and
I'm confused all over again.  Here's a script they posted that takes both
POST and GET.

#! /usr/local/bin/perl
# CGI script that demonstrates how to unencode
# form data from both GET and POST methods

# this script will spit out only plain text
print "Content-type: text/plain\n\nHere's the form data:\n\n";

if ($ENV{'CONTENT_LENGTH'} > 0) {
    # read POST data from STDIN
    read STDIN, $temp, $ENV{'CONTENT_LENGTH'};
    # add in the GET data:
    $temp.="&".$ENV{'QUERY_STRING'} if length $ENV{'QUERY_STRING'};
} else {
    # read only the GET data
    $temp=$ENV{'QUERY_STRING'};
}

# separate each keyword
foreach ( split( /&/, $temp ) ) {
    # separate the keys and values
    ( $key, $val ) = split( /=/, $_, 2 );

    # translate + to spaces
    $key=~s/\+/ /g;
    $val=~s/\+/ /g;

    # translate %xx codes to characters
    $key=~s/%([0-9a-f]{2})/pack("c",hex($1))/gie;
    $val=~s/%([0-9a-f]{2})/pack("c",hex($1))/gie;

    print "$key = $val\n";
}

This takes both POST and GET data from their respected places in the %ENV
hash and then processes it all.  But here's my question.  What it one of
them is empty?  What is this script doing?  Here's another question on the
same stuff.  POST and GET methods, this is how they look, briefly:

POST /cgi-bin/script.pl HTTP/1.0
Content-type: application/x-www-form-urlencoded
Content-length: 26

in=hello+there&button=Send

and GET is:

GET /cgi-bin/script.pl?in=hello+there&button=Send HTTP/1.0

So when this thing adds the two to each other, it'll have a much harder time
parsing and processing with all that extra stuff, won't it?  It won't
necessarily be able to get rid of all the extra info such as that POST
header thing that has this content type stuff or the GET stuff before the
question mark.

Dude, I am so confused.  A little help please.  If someone could explain
this stuff to me, that would be too cool.  Thanks.




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

Date: Mon, 04 Jun 2001 21:00:47 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Newb needs help with input from forms
Message-Id: <thntnve983td6c@corp.supernews.com>

Shawn Michael Taub <shawntaub@yahoo.ca> wrote:

> #! /usr/local/bin/perl
> # CGI script that demonstrates how to unencode
> # form data from both GET and POST methods

> Dude, I am so confused.  A little help please.  If someone could explain
> this stuff to me, that would be too cool.  Thanks.

In this case, take a look at the standard module CGI.pm and its
associated documentation. AIUI, there's better and more recent
documentation for CGI.pm on the web somewhere, written by
Lincoln Stein himself (the author of the module).

In general, if you're having trouble implementing a whell, use
the reference implementation. If you _do_ create a better wheel
than the reference implementation, please send the diffs to the
maintainer.

Chris

-- 
Even in the worst of times, there is always someone who's
never had it better. Even in the best of times, there is
always someone who's never had it worse.



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

Date: Mon, 4 Jun 2001 20:50:25 GMT
From: jtbell@presby.edu (Jon Bell)
Subject: Re: Newb needs help with input from forms
Message-Id: <GEFB81.GIw@presby.edu>

In article <9fgq4l$d0i$1@newsmaster.axxent.ca>,
Shawn Michael Taub <shawntaub@yahoo.ca> wrote:
>    Essentially, I offered to make a Perl Tutorial in a very short amount of
>time, [...]

>#! /usr/local/bin/perl
># CGI script that demonstrates how to unencode
># form data from both GET and POST methods

Why are you re-inventing the wheel?  The CGI.pm module that comes with the 
standard distribution of Perl takes care of all the messy work for you.

  use CGI qw/:standard/;   # at the beginning of the script


  my $Action = param('action');  # get the value of the parameter 'action'
                                 # and store it in the variable $Action;
                                 # doesn't matter whether it was submitted
                                 # via GET or POST

A Google search will probably turn up dozens of pages with tutorials and 
examples of using CGI.pm.

-- 
Jon Bell <jtbell@presby.edu>                        Presbyterian College
Dept. of Physics and Computer Science        Clinton, South Carolina USA


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

Date: Mon, 04 Jun 2001 17:40:57 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: OT :: What to do if you've been kill filed
Message-Id: <300ohtok11sehc0evdbg438k8d1mlvquta@4ax.com>

--So let's say you get kill filed what do you do to be un kill filed?
Short of changing your identity that is.
--
BSOD? In my day we didn't have 0000FF!
lmoran@wtsg.com


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

Date: 4 Jun 2001 13:44:08 -0700
From: Goggle.news@novelground.com (Sam)
Subject: Pack, Unpack help (I think!)
Message-Id: <34e16cd6.0106041244.3f76da85@posting.google.com>

Hi everyone, 

I just wanted to put a request out for some guidance before I get too
deep down the wrong path :)

Heres the problem:

I've got a short string of form (word)(number)(word) that I want to
encode, EG: "hello121world". Length doesn't vary too much with the
words being 5 to 7 letters and the numbers 2 to 4 digits.

I want to "encode" the string into a seemingly random collection of
letters and numbers, EG: hello121world -> jf92894fklsj84

In addition the string needs to have somekind of "checkbit" included
in it so if I change it there is only a low chance of it being decoded
(<1% seems ok). Most changes should result in a error from the
un-encoder.

The length shouldn't grow by too much, no more than 50% overhead and
if it can be reasonably effecient thats a bonus as this will be in a
fairly long loop.

I was thinking that at least the 1st half of this problem was suited
to pack(), unpack() but I've played with it to no avail. Frankly I'm
not sure what to do as I've only really seem pack() used to obscure
code in various wacky perl contests.

Just to repeat: This is a casual encoding, not an encryption system.
It can be anything more complicated than a simple ciphar, and even
that might be enough if it looks strange enough.

Any ideas, pointers etc?

I've not given this too much thought yet and will have a real stab at
it in the next couple of days but I just wanted to make sure I wasn't
reinventing the wheel.

Thanks in advance,
Sam.


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

Date: 4 Jun 2001 18:11:04 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Passing XML string to the URL
Message-Id: <9fgivo$75k$2@bob.news.rcn.net>

Maya <m.astrakhanskaya@gte.net> wrote:
> Could anybody give me a friendly helping hand?
> I am trying send XML formatted string ( which should become the part of
> URL )

>   $XMLReq = new HTTP::Request POST =>
> 'http://host/path/CreateAppcount.aspMetaData=';

That doesn't look like a valid URL.  It looks like you're trying to add 
a query string to it, but your syntax is wrong, and this is a POST request 
anyway, so the request content doesn't belong in the query string.

>   $XMLReq->content_type ('text/xml');

>   $XMLReq->content($XML_string); #XML_string is 1146 char long

This will be sent in the body of the POST.

>   $Resp = $TheAgent->request($XMLReq);

>   if ($Resp->is_success)
>   { print STDERR $Resp->content; }
>   else
>   { print "script failed\n"; }

> I am getting the error message :'Incomplete request' . What am I doing
> wrong?

What exactly is the receiving process expecting?



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

Date: Mon, 04 Jun 2001 20:15:28 GMT
From: "Maya" <m.astrakhanskaya@gte.net>
Subject: Re: Passing XML string to the URL
Message-Id: <A%RS6.941$2g7.163089@dfiatx1-snr1.gtei.net>

I change my code to:

$XMLReq = new HTTP::Request POST =>
'http://172.27.12.228/IBCMEntitlements/ESNICreateAppAccount.asp';

 $XMLReq->content_type ('text/xml');

 $Request="Metadata=".$XML_string;

 $XMLReq->content($Request);

 $Resp = $TheAgent->request($XMLReq);

I am not sure how to handle the query string .

"Eric Bohlman" <ebohlman@omsdev.com> wrote in message
news:9fgivo$75k$2@bob.news.rcn.net...
> Maya <m.astrakhanskaya@gte.net> wrote:
> > Could anybody give me a friendly helping hand?
> > I am trying send XML formatted string ( which should become the part of
> > URL )
>
> >   $XMLReq = new HTTP::Request POST =>
> > 'http://host/path/CreateAppcount.aspMetaData=';
>
> That doesn't look like a valid URL.  It looks like you're trying to add
> a query string to it, but your syntax is wrong, and this is a POST request
> anyway, so the request content doesn't belong in the query string.
>
> >   $XMLReq->content_type ('text/xml');
>
> >   $XMLReq->content($XML_string); #XML_string is 1146 char long
>
> This will be sent in the body of the POST.
>
> >   $Resp = $TheAgent->request($XMLReq);
>
> >   if ($Resp->is_success)
> >   { print STDERR $Resp->content; }
> >   else
> >   { print "script failed\n"; }
>
> > I am getting the error message :'Incomplete request' . What am I doing
> > wrong?
>
> What exactly is the receiving process expecting?
>




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

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


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