[10780] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4381 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 8 16:07:20 1998

Date: Tue, 8 Dec 98 13:00:19 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 8 Dec 1998     Volume: 8 Number: 4381

Today's topics:
    Re: & (Andrew M. Langmead)
    Re: 3 perl cgi questions... <chrknudsen@hotmail.com>
    Re: 3 perl cgi questions... <ringwood@berbee.com>
    Re: 80 column conversion (Tim Gim Yee)
    Re: 80 column conversion <phenix@interpath.com>
    Re: CGI Redirection <raikak@rpi.edu>
    Re: Conditional statements (solved) <jeffbREMOVETHIS@mcguckin.com>
        Emailing something from a cgi script (Mark Shaw)
        Errors with SETUID and Perl Script mike_orourke@em.fcnbd.com
    Re: Errors with SETUID and Perl Script <Allan@due.net>
    Re: Getting Perl Modules to work on ISPs that don't all (Tad McClellan)
    Re: Help!  Possible permissions problem? <Alex.Davies@tiuk.ti.com>
        Is there a 'predeclare subs' module ? <Alex.Davies@tiuk.ti.com>
    Re: Is there a 'predeclare subs' module ? (brian d foy)
        need info on oraperl webboss@freenet.co.uk
        Packing Multiple Arrays.... (Jim Matzdorff)
    Re: Packing Multiple Arrays.... (Jim Matzdorff)
    Re: Perl Script and HTML (brian d foy)
    Re: Perl Script and HTML <ebohlman@netcom.com>
    Re: Redirecting STDIN <r28629@email.sps.mot.com>
    Re: Redirecting STDIN <ebohlman@netcom.com>
    Re: shift. <dgris@moiraine.dimensional.com>
    Re: simple regular expression problem ptimmins@netserv.unmc.edu
        Sorting Associative Arrays <saima@dkhollow.gsfc.nasa.gov>
        sub reference and name <kin@symmetrycomm.com>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Tue, 8 Dec 1998 19:40:18 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: &
Message-Id: <F3nvz7.JDp@world.std.com>

om7@cyberdude.com writes:

>I have the following code...

>sub qwerty(&)

the "(&)" is a function prototype. It tells perl that a certain number
and type of arguments are needed (even if the numbers is "zero or
more") In certain cases it allows perl to make an implict reference on
the arguments. In this case, it forces the functino to take only one
argument, which is a reference to a subroutine.

>{
>     my $var_name = shift;
[stuff deleted]

>     &$var_name($f1, $f2);

This calls the subroutine referred to by the scalar $var_name. So what
it actually does depends on the what gets passed to qwerty().

for example, if qwerty() opens $f1 for reading and $f2 for writing, and
it gets called this way:

qwerty(sub {my($in,$out) = @_; print $out <$in>});

The contents of $f1 would get copied into $f2.

If it got called this way:

qwerty(sub {my($in,$out) = @_; print $out reverse <$in>});

Then $f2 would get a copy of $f1 but with the lines reversed (last
line first).


I think that the perlsub man page has the stuff about prototypes, but
it might be some heavy reading. Prototypes aren't designed for
beginners, they are designed for module writers so that they can
create code that mimics some ofthe behaviors of perl's built in
operators.
-- 
Andrew Langmead


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

Date: Tue, 08 Dec 1998 19:08:28 GMT
From: "Christian H. Knudsen" <chrknudsen@hotmail.com>
Subject: Re: 3 perl cgi questions...
Message-Id: <366D7A40.507ECCD5@hotmail.com>

Thanks a lot! It really helped!

-- Christian H. Knudsen



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

Date: Tue, 08 Dec 1998 13:31:52 -0600
From: Tim <ringwood@berbee.com>
Subject: Re: 3 perl cgi questions...
Message-Id: <366D7EA8.7B51@berbee.com>

Christian H. Knudsen wrote:
> 
> 1) Is it possible for a cgi perl script to check if a file
> on a remote server server exists? Check the size?
> 
> Ex.:
> $exists = -e "http://www.blah.com/images/image.gif";
> $size = -s "http://www.blah.com/images/image.gif";
> 

You have to attempt to get at leat the first character
of the file. I'd just open up a socket and make the request,
but then I'm wierd.

Maybe a module has a routine that does this for you.

tim


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

Date: Tue, 08 Dec 1998 19:04:54 GMT
From: tgy@chocobo.org (Tim Gim Yee)
Subject: Re: 80 column conversion
Message-Id: <366e73e9.385427822@news.oz.net>

On Tue, 8 Dec 1998 11:57:52 -0500, phenix@interpath.com (John Moreno)
wrote:

>A easy way to do it with regex in case you don't like Text::Format (I
>recently wanted to wrap while maintaining a prefix so I've written my
>own) is to do it recursively -- loop and use a regular expression like:
>
>   $preferred_length=72;
>   $max_length=80;
>   $min2wrap=$max_length-$preferred_length;
>   $rest_of_line =~ s/(.{1,$preferred_length})(\s.{$min2wrap,})/$1/ if (length $rest_of_line > $max_length);
>
>   # but what if the line doesn't have any 
>   if (length $rest_of_line  > $max_length) {
>      $rest_of_line =~ s/(.{1,$preferred_length})(.+)/$1/;
>   }
>
>  # and get ready to send it, while saving the leftover
>  $send_line_text = $rest_of_line;
>  $text_wrapped_from_last_line = $2;

My cat walked across the keyboard, and this is what she came up with:

sub linewrap {
    my $line = shift; defined $line or return '';
    my @data = split /\t/, $line;
    my $columns = shift || $columns;
    my $tabstop = shift || $tabstop;
    my $frag = '';
    my $col  = $columns - 1;

    for (@data) {
        $_ = "$frag$_";
        $frag = '';
        s/(.{1,$columns}$)|(.{1,$col}(?:\S\s+|-(?=\w)))|(.{$col})/
            $3 ? "$3-\n" :
            $2 ? "$2\n" :
            (($frag = $1), '')
        /ge;
        $frag .= (' ' x ($tabstop - length($frag) % $tabstop));
    }

    local $_ = join '', @data, $frag;
    s/\s+$//gm;
    return $_;
}

It breaks up lines along whitespace and after hyphens.  Really long
words get broken at one less than $columns where a hyphen is added.
And because tabs are expanded as lines are wrapped, all tabs will line
up with tabstops.

>The above is part of a function to wrap while keeping a prefix (testing
>some stuff for doing wrapping and rewrapping of usenet articles), if
>you'd to see the whole thing just ask.

I too wanted to wrap usenet articles.  And I did.  Then I scraped the
relevant code from my script, added a C<package News::Wrap> to the
top, and called it a module.  The above subroutine is from that
module.  The rest of it can be found elsewhere.

    http://www.chocobo.org/~tgy/moogle/perl/News/Wrap.pm

Hope it's useful to your task.


--
Tim Gim Yee
http://www.dragonfire.net/~tgy/moogle/
"Kupo! Round and round you go! Moogle!"


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

Date: Tue, 08 Dec 1998 14:50:21 -0500
From: John Moreno <phenix@interpath.com>
Subject: Re: 80 column conversion
Message-Id: <phenix-081219981450216523@roxboro0-020.dyn.interpath.net>

Tim Gim Yee <tgy@chocobo.org> wrote:

> phenix@interpath.com (John Moreno) wrote:
> 
> >A easy way to do it with regex in case you don't like Text::Format (I
> >recently wanted to wrap while maintaining a prefix so I've written my
> >own) is to do it recursively -- loop and use a regular expression like:
> >
> >   $preferred_length=72;
> >   $max_length=80;
> >   $min2wrap=$max_length-$preferred_length;
> >   $rest_of_line =~ s/(.{1,$preferred_length})(\s.{$min2wrap,})/$1/ if
> >   (length $rest_of_line > $max_length);
> >
> >   # but what if the line doesn't have any 
> >   if (length $rest_of_line  > $max_length) {
> >      $rest_of_line =~ s/(.{1,$preferred_length})(.+)/$1/;
> >   }
> >
> >  # and get ready to send it, while saving the leftover
> >  $send_line_text = $rest_of_line;
> >  $text_wrapped_from_last_line = $2;
> 
> My cat walked across the keyboard, and this is what she came up with:

Can I have that cat?
 
> sub linewrap {
>     my $line = shift; defined $line or return '';
>     my @data = split /\t/, $line;
>     my $columns = shift || $columns;
>     my $tabstop = shift || $tabstop;
>     my $frag = '';
>     my $col  = $columns - 1;
> 
>     for (@data) {
>         $_ = "$frag$_";
>         $frag = '';
>         s/(.{1,$columns}$)|(.{1,$col}(?:\S\s+|-(?=\w)))|(.{$col})/

Is this supposed to be taking care of the case where there isn't any
place to break?

>             $3 ? "$3-\n" :
>             $2 ? "$2\n" :
>             (($frag = $1), '')
>         /ge;
>         $frag .= (' ' x ($tabstop - length($frag) % $tabstop));
>     }
> 
>     local $_ = join '', @data, $frag;
>     s/\s+$//gm;
>     return $_;
> }
> 
> It breaks up lines along whitespace and after hyphens.  Really long
> words get broken at one less than $columns where a hyphen is added.
> And because tabs are expanded as lines are wrapped, all tabs will line
> up with tabstops.

I don't account for tabs at all (not that it would be hard to do so).
 
> >The above is part of a function to wrap while keeping a prefix (testing
> >some stuff for doing wrapping and rewrapping of usenet articles), if
> >you'd to see the whole thing just ask.
> 
> I too wanted to wrap usenet articles.  And I did.  Then I scraped the
> relevant code from my script, added a C<package News::Wrap> to the
> top, and called it a module.  The above subroutine is from that
> module.  The rest of it can be found elsewhere.
> 
>     http://www.chocobo.org/~tgy/moogle/perl/News/Wrap.pm
> 
> Hope it's useful to your task.

Not really -- my main task was writing it in C as a library which could
be used by newsreader authors.

A question though -- it looks like what you need to pass to newswrap is
a string containing lines that use the same quote prefix.  Is that the
case or am I missing something?  And those lines are wrapped using
paragraph filling (i.e. the lines with the same prefix are merged into
as few or as many lines as is needed to contain all of the text)?

-- 
John Moreno
(Newsreaders recognize the signature by looking for the sigdash, which is a
line which consist solely of two dashes followed by a space)


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

Date: Tue, 8 Dec 1998 15:47:36 -0500
From: ~ Kianoosh Raika ~  <raikak@rpi.edu>
Subject: Re: CGI Redirection
Message-Id: <Pine.A41.3.96.981208154642.24008A-100000@cii3112-12.rcs.rpi.edu>


taken from the following page:  http://tigger.rdg.ac.uk/perldocs/CGI.html


GENERATING A REDIRECTION INSTRUCTION 

   print $query->redirect('http://somewhere.else/in/movie/land');

redirects the browser elsewhere. If you use redirection like this, you
should not print out a header as well. As of version 2.0, we produce
both the unofficial Location: header and the official URI: header. This
should satisfy most servers and browsers. 

One hint I can offer is that relative links may not work correctly when
you generate a redirection to another document on your site. This
is due to a well-intentioned optimization that some servers use. The
solution to this is to use the full URL (including the http: part) of the
document you are redirecting to. 

You can use named parameters: 

    print $query->redirect(-uri=>'http://somewhere.else/in/movie/land',
                           -nph=>1);

The -nph parameter, if set to a true value, will issue the correct headers
to work with a NPH (no-parse-header) script. This is important
to use with certain servers, such as Microsoft Internet Explorer, which
expect all their scripts to be NPH. 



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

Date: Tue, 08 Dec 1998 11:53:10 -0700
From: Jeff Beard <jeffbREMOVETHIS@mcguckin.com>
Subject: Re: Conditional statements (solved)
Message-Id: <366D7596.FF808B9F@mcguckin.com>

After I posted this question I realized that it needed "eq" for a string
instead of "=". With that change all of my tests worked the way I wanted
them to. 

Anyway, thanks very much for all the good help. There were some great
explanations and examples which I'm going file away.

Cheers,

Jeff



Jeff Beard wrote:
> 
> Hello,
> 
> I've got an array that I want to loop through and when I am at the first
> value (regardless of the value) I want to do one thing but for the rest
> do something different. What I have is:
> 
> my @array = qw(apples oranges pears);
> 
> my $i = @array1[0];
> 
> foreach (@array) {
>     if ($_ = $i) {
>         print "$_\n";
>     } else {
>         print "$_\n";
> }
>


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

Date: 8 Dec 1998 18:59:23 GMT
From: mshaw@asic.sc.ti.unicorn.com (Mark Shaw)
Subject: Emailing something from a cgi script
Message-Id: <74jsub$gjm$1@spock.asic.sc.ti.com>

Howdy,

First, I've read the Programming FAQ (well not all of it), and it 
appears there's a more efficient way (Q4.1) to do this -- but just 
for grins could someone tell me what, specifically, I'm doing wrong 
here before I make any changes?

I've got a pair of CGI scripts that 1) present the user with a 
form to be filled out and 2) take the contents of that form and
sends them to an email address (which in turn forwards them to a
pager).

The contents of the form get formatted into a single temporary
file such that whatever lives behind the email address (someone
else's code to which I am not privy) can send them on to the
pager.  The file includes the message and the pager number.

After taking care of all this collection and formatting, I do
the actual emailing as follows:

  $retval = 0xffff & system("mail $pager_address < $tempfile");

And then test $retval for errors as described on p. 230 of the
Camel Book (2nd Ed).

A previous version of the script actually used: 

  $retval = 0xffff & system("cat $tempfile | mail $pager_address");

This has worked pretty well in the past, but lately I'm getting
(with both methods) very frequent occurences of failure -- speci-
fically an exit status of 12 (the 'elsif ($retval > 0x80)' case 
from the Camel Book).  I haven't been able to winkle out what '12'
means from manpages and the like....

I've confirmed that the temporary file is getting written properly,
and that it's readable.  I've also confirmed that the pager address
hasn't changed or anything, by emailing the temporary file directly
to the pager address from the command line.  The only way I can make
this break is by using the CGI scripts.

System info: Netscape 4.04 under Solaris 2.6 

Hmm, I've just upgraded to 2.6....

Anyway, thanks for any info or suggestions.  I can provide more info
or even the scripts if needed -- and if you respond directly via email, 
pls see demunging instructions below.


-- 
Mark Shaw
My opinions only
PGP public key available at ftp.netcom.com:/pub/ms/mshaw
(to email me, remove any mythical beasts from my address)




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

Date: Tue, 08 Dec 1998 19:12:50 GMT
From: mike_orourke@em.fcnbd.com
Subject: Errors with SETUID and Perl Script
Message-Id: <74jtnh$ana$1@nnrp1.dejanews.com>

I created a perl script that will allow users to "chown" files that they own
to another valid UID on the server.  I seemed to have resolved the "tainted"
data problem, but now the "chown" command is still failing. The Perl script
has "4755" permissions and is owned by "root". When I run the script as
"root", everything works O.K. But when I run the script while connected as
the "owner" of the file I am trying to modify, I get the following message :

chown: /export/home/lddv/test_chmod.txt: Not owner
Could not run CHMOD at /dev/fd/3 line 48.

Below is an example of the code that I am using :

$old_path = $ENV{"PATH"} ; $directory = "/export/home/lddv" ; $filename =
"test_chmod.txt" ; $file_owner = "lao7" ; if ($filename =~ /^([-\@\w.]+)$/) {
 $filename = $1 ; } else {  die "Bad data in $filename" ; } if ($file_owner
=~ /^([-\@\w.]+)$/) {  $file_owner = $1 ; } else {  die "Bad data in
$file_owner" ; } if ($directory =~ /^([\/\-\@\w.]+)$/) {  $directory = $1 }
else {	die "Bad data in $directory" ; } $ENV{"PATH"} = "/usr/sbin:/usr/bin";
system("chown  $file_owner '$directory/$filename'") && die "Could not run
CHMOD" ; $ENV{"PATH"} = $old_path ; exit ;


Any recommendations ???????????




-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Tue, 8 Dec 1998 14:31:26 -0500
From: "Allan M. Due" <Allan@due.net>
Subject: Re: Errors with SETUID and Perl Script
Message-Id: <74juha$7lu$1@camel18.mindspring.com>

mike_orourke@em.fcnbd.com wrote in message
<74jtnh$ana$1@nnrp1.dejanews.com>...

[snip]

>Below is an example of the code that I am using :
>
>$old_path = $ENV{"PATH"} ; $directory = "/export/home/lddv" ; $filename =
>"test_chmod.txt" ; $file_owner = "lao7" ; if ($filename =~ /^([-\@\w.]+)$/)
{
> $filename = $1 ; } else {  die "Bad data in $filename" ; } if ($file_owner
>=~ /^([-\@\w.]+)$/) {  $file_owner = $1 ; } else {  die "Bad data in
>$file_owner" ; } if ($directory =~ /^([\/\-\@\w.]+)$/) {  $directory = $1 }
>else { die "Bad data in $directory" ; } $ENV{"PATH"} =
"/usr/sbin:/usr/bin";
>system("chown  $file_owner '$directory/$filename'") && die "Could not run
>CHMOD" ; $ENV{"PATH"} = $old_path ; exit ;


Ow, ow, ow.  My head, my poor head hurts.  Just a little formatting please.

AmD




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

Date: Tue, 8 Dec 1998 14:24:03 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Getting Perl Modules to work on ISPs that don't allow shell access
Message-Id: <3t1k47.got.ln@magna.metronet.com>

rna16s@usa.net wrote:
: In order to use a Perl module does one have to have shell access? I
: have seen many postings that say that you must use "perl makefile.pl
: PREFIX=/my/dir" but I am unable to do this since I do not have shell
: access to my ISP. Can the module be placed inside a directory and then
: just referenced from the script making use of it? I am using two ISPs,
: one is UNIX and one is WinNT. Thanks.


   use lib '/my/dir';


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


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

Date: Tue, 08 Dec 1998 18:55:18 +0000
From: Alex Davies <Alex.Davies@tiuk.ti.com>
Subject: Re: Help!  Possible permissions problem?
Message-Id: <366D7615.14548E81@tiuk.ti.com>

Abe wrote:

> OK, I've written a Perl script that when run, will read a number from a
> data file, create a directory off of the main directory using that
> number, increment the number, and write it back to the data file.  For
> the most part, it works fine.  However, I think there is a permissions
> problem somewhere.  I use:
>
> system( "mkdir $dir/$num" );
>
> The directory creation works without a hitch.  I also make the directory
> world-writable with:
>
> chmod 777, '$dir/$num';
>

  may be you meant "$dir/$num" ?

HTH
alex.

_________________________________________________________________________

Alex Davies, MOS Design,               Email:  Alex.Davies@tiuk.ti.com
Texas Instruments Limited,
800 Pavillion Drive,                   Tel (work):  01604 663450
Brackmills Industrial Estate,              (home):  01604 764961
Northampton, NN4 7YL.
U.K.

>
> I've been having some problems, however.  When I FTP in to the server,
> it will not allow me to alter or delete anything in the new
> subdirectory, nor will it allow me to upload anything to that directory,
> set permissions on anything in the directory, or even set permissions on
> the directory itself.   Everything still works fine with every directory
> other than the one created by the script.  Other scripts that I have
> written can alter data in this directory, but I can't do it myself.  Is
> this a permissions problem?  Help!
>
> Oh, and abe@abe.com is a spamfoiler so please post your comments here.
> I understand that there is some poor guy named Abe getting email that is
> meant for me! ;)



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

Date: Tue, 08 Dec 1998 19:28:25 +0000
From: Alex Davies <Alex.Davies@tiuk.ti.com>
Subject: Is there a 'predeclare subs' module ?
Message-Id: <366D7DD8.47681C0F@tiuk.ti.com>


Is there a way of automatically predelcaring _all_  your
subroutines, kinda like:

BEGIN {
  my $eval = '';
  open(ME, "<$0") || die "**Error: can't open '$0' - $!\n";
  while (<ME>) {
    if (/^\s*sub\s+(\w+)/) {
      $eval .= "sub $1;";
    }
  }
  close ME;
  eval $eval;
  die "$@**Eval-Error: bad code>> $eval\n" if $@;
}

(but with the necesary bells and whistles...) ?

So you could say

foo "bar";
# ...
sub foo { print $_[0], "\n"; }

without either "use var qw( &foo )" or an explicit "sub foo;" at the
top...


Or is this a bad idea ... ;)

alex.
_________________________________________________________________________

Alex Davies, MOS Design,               Email:  Alex.Davies@tiuk.ti.com
Texas Instruments Limited,
800 Pavillion Drive,                   Tel (work):  01604 663450
Brackmills Industrial Estate,              (home):  01604 764961
Northampton, NN4 7YL.
U.K.




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

Date: Tue, 08 Dec 1998 15:30:27 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Is there a 'predeclare subs' module ?
Message-Id: <comdog-ya02408000R0812981530270001@news.panix.com>

In article <366D7DD8.47681C0F@tiuk.ti.com>, Alex Davies <Alex.Davies@tiuk.ti.com> posted:

> Is there a way of automatically predelcaring _all_  your
> subroutines, kinda like:

> So you could say
> 
> foo "bar";
> # ...
> sub foo { print $_[0], "\n"; }

maybe you wanted

   use subs qw( ... );

?

-- 
brian d foy                     <brianNOSPAM@NOSPAM.smithrenaud.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
remove NOSPAM or don't.  it doesn't matter either way.


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

Date: Tue, 08 Dec 1998 20:16:47 GMT
From: webboss@freenet.co.uk
Subject: need info on oraperl
Message-Id: <74k1fd$e6n$1@nnrp1.dejanews.com>

Hi -  are you using oraperl to talk to a remote oracle system???

Do you need to have an oracle client on the local machine or can oraperl log
into the remote machine directly ie our web machine does not have oracle
client on it but we want to extract data from our AIX based oracle server..

any help could just save the life of an overworked web designer!

--
--
Christopher J Williams
webboss@freenet.co.uk

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 8 Dec 1998 12:33:41 -0800
From: syran@shell1.ncal.verio.com (Jim Matzdorff)
Subject: Packing Multiple Arrays....
Message-Id: <74k2f5$apk$1@shell1.ncal.verio.com>

Does anyone know of a good way to pack two arrays (that are not identical)?
For instance, lets say I have two arrays, a and b

a = 1 2 3 4
b = a b b c
now, if I delete out of a the 3rd value (3), then i also want to delete out of b the 3rd value (b).

after any (1..all) value have been deleted in a, i want delete the corresponding array value in b, and pack BOTH arrays, so there are no
undefined value lurking the the middle:

a = 1 2 4 (not 1 2 undefined 4)
b = a b c

this is an off-the-wall question, so the perl faq and/or modules didn't help with this question (at least, not that i could find).  

please note: although array "a" has unique values, array b's values are not unique (so i can't do an intersection and/or different on b).

a mutli-dimensional array would work here, but as far as i can tell, it's not easily supported by perl.
i was thinking of combining them into an associative array, but i'm also not sure that's the best idea, but maybe it is, in which case you can just
tell me that :)

Thanks in advance,
--jim


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

Date: 8 Dec 1998 12:48:04 -0800
From: syran@shell1.ncal.verio.com (Jim Matzdorff)
Subject: Re: Packing Multiple Arrays....
Message-Id: <74k3a4$ca8$1@shell1.ncal.verio.com>

my mistake folks, i answered my own questions, oh, about 2 minutes after i posted the message (and yes, i had been thinking about it for sometime,
go figure).

sorry for your time,
--jim


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

Date: Tue, 08 Dec 1998 15:35:28 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Perl Script and HTML
Message-Id: <comdog-ya02408000R0812981535280001@news.panix.com>

In article <74jpq6$7cv$1@nnrp1.dejanews.com>, rmaglich@my-dejanews.com posted:

> I have written a perl script that accepts the contents of a form, but the HTML
> that is supposed to be displayed after the form processing is completed is not
> being returned to the client.  The code is as follows (noting modifications):

> #!/usr/local/bin/perl
> print "Status: 200\nContent-type: text/html\n\n";

are you sure you need to tell it Status: 200?  good servers will
assume that in this case.

> %cgivars= &getcgivars ;  #  getcgivars is a parser--  and it works correctly

that's what they all say ;)


> $OURFILE = `/usr/local/bin/tempname temp`;  #  creates a temporary file name
>  open(OURFILE, ">$OURFILE");

didn't you forget something in that line?

>  `chmod 777 $OURFILE > /dev/null`;

there is a Perl builtin for this - called chmod() strangely enough. :)

> It works from the command line, but when the form is submitted the HTML is not
> returned to the client machine.  Any help would be greatly appreciated......

what does the error log have to say about this?  have you looked through
the helpful docs in the CGI Meta FAQ?

-- 
brian d foy                     <brianNOSPAM@NOSPAM.smithrenaud.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
remove NOSPAM or don't.  it doesn't matter either way.


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

Date: Tue, 8 Dec 1998 20:43:06 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Perl Script and HTML
Message-Id: <ebohlmanF3nyvu.zB@netcom.com>

rmaglich@my-dejanews.com wrote:
: I have written a perl script that accepts the contents of a form, but the HTML
: that is supposed to be displayed after the form processing is completed is not
: being returned to the client.  The code is as follows (noting modifications):


: #!/usr/local/bin/perl

You're missing a -w here

: print "Status: 200\nContent-type: text/html\n\n";

Depending on how your server is set up, you may not want to print the 
"Status:" header (in many cases, a server will automatically generate 
it).  This might be the source of your problem; the only way to tell is 
to find out how your server is set up.

: %cgivars= &getcgivars ;  #  getcgivars is a parser--  and it works correctly
: $OURFILE = `/usr/local/bin/tempname temp`;  #  creates a temporary file name

It would be a Very Good Idea (VGI) to check that you got back something 
reasonable here.

:  open(OURFILE, ">$OURFILE");

It would also be a VGI to check that your attempt to open the file was 
successful, and to print out the reason if it wasn't.

 :  foreach (keys %cgivars)
:  {
:          if ("$_" eq 'signature')          # signature is a field of the form
:          { print OURFILE ("$cgivars{$_}\n");  }
:  }

The *whole* *point* of using a hash is that you can directly access one 
of its elements without having to search for it.  The whole loop could be 
replaced with:

print OURFILE $cgivars{signature},"\n";

:   close(OURFILE);
:  `chmod 777 $OURFILE > /dev/null`;

Use Perl's internal chmod() function, and test to be sure it worked.

:  print <<"EOF";
[snip HTML to be printed]
:  EOF
:  exit;

No need to invoke exit at the end of a program.

: It works from the command line, but when the form is submitted the HTML is not
: returned to the client machine.  Any help would be greatly appreciated......

If it's not the potential header problem I mentioned earlier, it's 
probably a failure to open a file or run an external program, both of 
which can happen when your script is running as a different user and with 
a different working directory than you expect.  Perl provides plenty of 
facilities for informing you of run-time problems; use them.



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

Date: Tue, 08 Dec 1998 13:12:01 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: Jon Rifkin <jrifkin@mail.ims.uconn.edu>
Subject: Re: Redirecting STDIN
Message-Id: <366D7A01.72C6196A@email.sps.mot.com>

[posted to c.l.p.m and copy emailed]

Jon Rifkin wrote:
> 
> I want to my script to read an input file OR STDIN when the
> input file name is '-'.  How can I do that?
> 
> I tried
> 
> if ($ARGV[0] eq '-')
>         {
>         open (INFILE, STDIN);
[snip]

if you really want to you can try this:
          *INFILE = *STDIN;

however, you may find the angle brackets, <>, operator suit your need.
see 'perldoc perlop' for more info.

-TK


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

Date: Tue, 8 Dec 1998 20:47:09 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Redirecting STDIN
Message-Id: <ebohlmanF3nz2L.1A8@netcom.com>

Jon Rifkin <jrifkin@mail.ims.uconn.edu> wrote:
: I want to my script to read an input file OR STDIN when the 
: input file name is '-'.  How can I do that?

I think you want to read the section in the perlop (man page | HTML page 
|POD file) about the "diamond operator."  If you use it properly, the 
perl interpreter will take care of setting up the appropriate input 
source for you.



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

Date: 08 Dec 1998 13:03:50 -0700
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: shift.
Message-Id: <m3af0yxuxl.fsf@moiraine.dimensional.com>

om7@cyberdude.com writes:

> Can someone please tell me what the following does

Maybe.

> my $variablename = shift;
> 
> It's being called inside a sub routine.

Nope, nobody can tell you what this does.  In fact, nobody
here has ever even seen such a construct.  I think that it
is a completely new perl idiom, the person who originally
wrote it must have been some sort of internals guru to 
have figured this out.

Either that, or he read perlsub and perldoc -f shift.

dgris
-- 
Daniel Grisinger          dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print 
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'


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

Date: Tue, 08 Dec 1998 18:46:48 GMT
From: ptimmins@netserv.unmc.edu
Subject: Re: simple regular expression problem
Message-Id: <74js6o$9ft$1@nnrp1.dejanews.com>

In article <74jm6g$3oi$1@nnrp1.dejanews.com>,
  esiyuri@my-dejanews.com wrote:

[snip]
> it.  Here's a demo script...
> --------------------8<---------------------8<---------------------
> #!perl
> my $text = "Name: Fred Jones\nTel: 12345 6789\nFax: 34343 3434\n";
> print "=== before ===\n";
> print $text;
> (my $tel = $text) =~ s/^Tel: //m;
> print "=== after ===\n";
> print $tel;
> --------------------8<---------------------8<---------------------
>
> This produces:
>
> === before ===
> Name: Fred Jones
> Tel: 12345 6789
> Fax: 34343 3434
>
> === after ===
> Name: Fred Jones
> 12345 6789
> Fax: 34343 3434
>
> What I want is *just* the telephone number, ie "12345 6789".  Since the text
> is often in a different format (it is extracted from an HTML page using the
> rather excellent "HTML::TokeParser" module) the solution can only rely on the
> "Tel:" marker being on the same line...  the other fields may be absent.

This regex worked for me. Note the 's' modifier instead of the 'm':

(my $tel = $text) =~ s/.*Tel: (.*?)\n.*/$1/s;

so now '.' matches a newline, as well as any other character.

Hope that helps ... see perldoc perlre for more info

Patrick Timmins
$monger{Omaha}[0]

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Tue, 08 Dec 1998 15:38:05 -0500
From: Saima Zobair <saima@dkhollow.gsfc.nasa.gov>
Subject: Sorting Associative Arrays
Message-Id: <366D8E2D.EE230D8D@dkhollow.gsfc.nasa.gov>

Hello,

I have a question on sorting by value for an associative array.

I have a data structure that is defined using:

    foreach (@results) {
        my($tables) = {};
        $tables->{'archive'}     = shift(@columns);
        $tables->{'radius'}      = shift(@columns);
        $tables->{'mission'}     = shift(@columns);
        push(@ { $tablelist },$tables);
    }

I want to be able to sort array @ { $tablelist } by the values of
$tablelist->{'radius'}. I tried using something like:

   my(@sort) = sort {$a->{'radius'}<=>$b->{'radius'}} @{$tablelist};

But it does not work... I know I am going really wrong somewhere and I
dont
see why something like this should be hard to do?? Maybe it is not
possible
to sort associative arrays this way?



Thanks in advance for any help!
Saima




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

Date: 08 Dec 1998 11:35:08 +0000
From: Kin Cho <kin@symmetrycomm.com>
Subject: sub reference and name
Message-Id: <uvhjmdfyr.fsf@server3.symmetrycomm.com>

Is is possible to get the name of a sub via a reference to the sub?

For example, is there a nameof function/operator as follows?

$sub = \&mysub;
print nameof($sub);	# nameof returns name of sub referenced sub

Thanks.

-kin



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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 4381
**************************************

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