[7067] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 693 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 2 03:31:32 1997

Date: Wed, 2 Jul 97 00:01:45 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 2 Jul 1997     Volume: 8 Number: 693

Today's topics:
     Re: Perl Scripts and forms <rootbeer@teleport.com>
     Re: Problem understanding how to dereference with File: (Terje Bless)
     Re: Problems with HTTP_REFERER <stephen@asol.com>
     Sorting Array (TNguyen396)
     Re: STAT command (Tad McClellan)
     Re: use of sprintf and filehandles (Tad McClellan)
     Re: What is Perl syntax for SELECT CASE? (Tad McClellan)
     Re: When was PERL created? (Tad McClellan)
     Re: When was PERL created? <rootbeer@teleport.com>
     Win32::OBBC with Perl 5.004.01 on WinNT4.0 <jbkim@cnt.co.kr>
     Re: Y2K and Perl (was Re: Y2K problems??) (Abigail)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Tue, 1 Jul 1997 20:55:09 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Angel Rodgers <rodgeral@jmu.edu>
Subject: Re: Perl Scripts and forms
Message-Id: <Pine.GSO.3.96.970701204454.8754C-100000@kelly.teleport.com>

On Tue, 1 Jul 1997, Angel Rodgers wrote:

> I am trying to verify that all of the blanks
> in an html form I have created are filled in before I run the another
> program.  How would I write a perl script to verify that the text fields
> in my form are filled in?  

Perl doesn't know (or care) that you're processing a form. To Perl, it's
just data. So, read the form data into some variables and check those
variables to see that the have acceptable values. 

    $form_ok = 1;		# Innocent until proven guilty
    # $filename is supposed to be a filename. But I don't trust
    # those wacky users. (Even though I could have a filename with
    # return characters in it on my system, I don't want the
    # users to give me a filename like that!)
    unless ($filename =~ /^[a-z][a-z0-9_]{0,7}(?:\.[a-z0-9_]{0,3})?$/) {
	$form_ok = 0;
	# I should really find a way to tell the user what's wrong, 
	# with a message such as "Sorry, uppercase letters not 
	# allowed", or "/etc/passwd is not a valid filename for
	# this program", but I'm too lazy to put that in here. :-)
    }

> open (FILE, ">$file")

You're missing a semicolon and the check on the return value of open. 

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 02 Jul 1997 07:06:54 +0200
From: link@tss.no (Terje Bless)
Subject: Re: Problem understanding how to dereference with File::Listing
Message-Id: <link-0207970706550001@rte-pm.tss.no>

In article <33B93B5B.87471EEC@stonehill.edu>,
    abennett@stonehill.edu wrote:

>I think that the File::Listing module is the secret to writing a good
>recursive script, but I can't understand what to do with it's results.
>
>#!/usr/local/perl -w
>   use File::Listing;
>   $mydir = ".";
>
>   @list = parse_dir(`ls -l $mydir`);

If 'parse_dir' returns a reference to an array for each entry in the
directory, you have to loop over the list and dereference each one.

# Loop over the array of references
foreach $listref (@list) {
    my @File_Info = @{$listref}; # Take the array referenced by $listref
                                 # and copy it into @File_Info

    print "\n_____\n";           # Add a little spacer between each file

    print join "\n", @File_Info; # print out the various elements of
                                 # @File_Info separated by a newline.
}


>I've been reading the camel book on de-referencing, but I think I may
>just be too dense to get it.

Don't worry; this isn't too easy to understand the first time thru4.
You'll figure it out eventually.

HTH, TTFN.

-- 
Party? Party, lord? Yes, lord. Right away, lord.
        - Beopunk Cyberwulf


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

Date: Tue, 01 Jul 1997 20:57:16 -0800
From: Stephen Fraga <stephen@asol.com>
Subject: Re: Problems with HTTP_REFERER
Message-Id: <33B9DF8E.3C03@asol.com>

bglenn@swanmedia.com wrote:
> 
> I am using a couple of PERL scripts to accomplish a task of checking user
> and password info to related fields in a database.  Once the user
> information is verified the first script spits out other information to
> an assigned variable which represents the URL that will be sent to the
> second script.  The first script spits out html that contains a "refresh"
> command that sends the request header of the second script.  My problem
> is that I am trying to make sure that the user's HTTP_REFERER is the URL
> of my first script.  However I did a little debugging and found that the
> $ENV{'HTTP_REFERER'} variable is blank when the referer is from a *.cgi
> file extension.  Why is this happening.  I have tested the HTTP_REFERER
> from .html file extentions and the HTTP_REFERER shows up.

I sent out an e-mail to a bunch of people with a solution. Below is the
e-mail:
**********
Many people seem to be having the same problem I did with passing the
HTTP_REFERER environmental variable to an indirectly-called CGI script
(invoked from within a <form> tag, for example). The variable is empty
or contains the URL of the page that called the CGI, instead of the
desired previous page.
 
I worked on this problem today and came up with a hack to do this.
If it were possible, it would be simplest to nest an SSI tag within
another tag, such as:

<form action="cgi-bin/log.cgi?prev_page=<!--#echo
var="HTTP_REFERER"-->">
or
<a href="<!--#echo var="HTTP_REFERER"-->">Go to Previous Page</a>

Unfortunately, though, you can't nest tags one within another.


Instead of trying to insert the HTTP_REFERER variable into the tag, you
can build the entire <form> tag on-the-fly using another Server Side
Include which calls UNIX commands: <!--#exec cmd="blah"-->. Using this
SSI, you can enclose the HTTP_REFERER variable within a tag; here is a
simple version, which just puts the referer variable in the html (still
useless to us, though):

<!--#exec cmd="echo $HTTP_REFERER"-->


We can expand on this use of the #exec SSI to build an entire tag which
contains the HTTP_REFERER address. Note the backslashing of sensitive
characters such as the quotes, less-than, more-than, &, and = symbols
(and any other likely troublesome characters).

<!--#exec cmd="echo \<form
action\=\"cgi-bin\/log.cgi\?prev_page\=$HTTP_REFERER\"\>"-->

I didn't try the above out, but it should work (pass the link origin to
the "log.cgi" script). Another use of this technique is to have an
automatic 'Back' button:

<!--#exec cmd="echo \<a href\=\"$HTTP_REFERER\"\>Go Back\<\/a\>"-->

The reason this works is that the HTTP_REFERER variable is parsed the
first time through, when the server is first sending out the web page,
and not parsed the second time, after a particular cgi script is
requested through the page.


Stephen Fraga
Arachne Internet Solutions

If this helped, you can return the favor by putting a link to my web
page on your page. The URL is http://www.asol.com


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

Date: 2 Jul 1997 05:20:09 GMT
From: tnguyen396@aol.com (TNguyen396)
Subject: Sorting Array
Message-Id: <19970702052000.BAA25024@ladder01.news.aol.com>

Hi Andrew:

I get your email address from comp.lang.perl.misc and I wonder if you
could help with my sorting problem?.  I have a text file with company
symbol and the trading volume for that symbol (Ex:  SDS 5000
                                          BELL 4000
                                          MSFT 3456 etc...)
To do the sorting, I have to split these data into two different fields: 
Company's Symbol and Trading Volume.  The problem is I only want to sort
these data by TRADING VOLUME (but I have to make sure the Company's Symbol
goes along with the Trading Volume),  I try many different ways, but I do
not get the result I want. 

      while ( $line = <>) {
              ($sym,$vol) = split /\s+/,$line;
              $listing($sym) = [$vol];
      }

      foreach $company ( sort {_____________________} keys %listing) {
            print "$company @{$sym{$vol}}\n";
      }

If you think of a way to solve it, please sent me an e-mail.

Thank you very much! 
THUY


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

Date: Tue, 1 Jul 1997 22:10:42 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: STAT command
Message-Id: <irgcp5.7v9.ln@localhost>

Mitch Duszynski (mrski@gist-inc.com) wrote:
: I am trying to write a script to read a file and its date from the
: directory so the info can be displayed on a web page.

: I have been using the STAT command but the number I get for the LAST
                        ^^^^^^^^^^^^

There is no STAT in perl.

There is, however, a stat. Perl is case sensitive ;-)


: MODIFIED date is in need of translation to get the date.  Anyone know how
: to do that?


Yes. Everyone who has looked for 'time' in the Perl FAQ knows how
to do that.

------------------------
=head2 How do I get a file's timestamp in perl?

If you want to retrieve the time at which the file was last read,
written, or had its meta-data (owner, etc) changed, you use the B<-M>,
B<-A>, or B<-C> filetest operations as documented in L<perlfunc>.  These
retrieve the age of the file (measured against the start-time of your
program) in days as a floating point number.  To retrieve the "raw"
time in seconds since the epoch, you would call the stat function,
then use 
 .. 
to convert this into human-readable form.
------------------------



: Or is there an easier way to get dates and filenames from a directory?

There IS an easier and quicker way to get answers to Perl questions,
you use the docs like you are supposed to...


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Tue, 1 Jul 1997 22:36:52 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: use of sprintf and filehandles
Message-Id: <kcicp5.a3a.ln@localhost>


[ there is no need for that MIME stuff on Usenet. I used to
  killfile MIME postings. Guess I may have to put that back in...
]


[ there is DEFINITELY no need for that HTML crap. This in NOT
  the World Wide Web. This is Usenet. It got along fine for fifteen
  years before the WWW was even invented...
]


Ian Merkel (otp@cyberservices.com) wrote:

: --------------27845BF76209C4A243549793
: Content-Type: text/plain; charset=us-ascii
: Content-Transfer-Encoding: 7bit

: hi... i'm making a .pl script which will process information from a
: flatfile (pipe delimited) and place its output in three separate
: files... this is what i have so far... (any "excess coding" has been
: removed...)

: #-------------commence code

: #!/usr/bin/perl

: $sourcefile = $ARGV[0];


$sourcefile = shift;   # an alternative. Saves typing 3 characters ;-)


: open (SOURCE, $sourcefile);

Gak!

You are not really planning to ignore the return value from open(),
are you?

What if the open() did not succeed? (file does not exist, no permission...)


: @lines = <SOURCE>;


You are done with SOURCE now, so close it now rather than waaaay down
there at the bottom.


: foreach $line (@lines)
: {
:     chop $line;


chomp $line;  # 'safe' chop


:     ($indexfield, $field1, $field2, $field3, $field4) =
: split(/|/,$line);
        ^^^
        ^^^
This doesn't even work. You need to escape regex metachars if
you want their literal meaning.

split(/\|/,$line);


: #    $indexfield is a numeric field
: #    $field1 - $field4 are strings

:     $field1_list{$indexfield}       =~ crypt($field1_list{$indexfield},
: "SALT");
:     $field2_list{$indexfield}       =~ tr/ /_/;
:     $field3_list{$indexfield}       =~ tr/ /_/;
:     $field4_list{$indexfield}       =~ tr/ /_/;


:     open (PEOPLE, ">>file1.ext");


Check the return value!


:     print PEOPLE "%10s %25s %25s\n",
:                  $field1_list{$indexfield},
:                  $field2_list{$indexfield},;
:     close (PEOPLE);


:     open (PINFO, ">>uinfo.dat");

Check the return value!


:     print PINFO "%10s %25s %25s \n", $usernamelist{$clientnumber},
:                  $field2_list{$indexfield},
:                  $field3_list{$indexfield},
:                  $field4_list{$indexfield};
:     close (PINFO);

: }

: close (SOURCE);

: #-------------end of code


: am i doing anything wrong?  

Yes. You are not checking return values and you are not escaping
metacharacters.


: odds are that there are a better way of
: doing this?  can anyone out there help me?


Hope this helped!


[ you can pay me back by posting like everyone else does. In plain
  ASCII. That Fisher-Price HTML stuff has no place here.
]


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Tue, 1 Jul 1997 21:47:03 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: What is Perl syntax for SELECT CASE?
Message-Id: <7ffcp5.vq9.ln@localhost>

Jeff Motter (jmotter@fgi.net) wrote:
: Is there an equivalent (Perl 5 under Win NT) for Basic's "SELECT CASE", or
: C++'s "SWITCH"?  Or do I use a bunch of "IF" statements?


You search for 'switch' in the Perl FAQ:

"How do I create a switch or case statement?"



You're supposed to check the FAQ before posting you know.

Please don't be so rude again.


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Tue, 1 Jul 1997 22:20:50 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: When was PERL created?
Message-Id: <iehcp5.tv9.ln@localhost>

tim@hcirisc.cs.binghamton.edu wrote:
: Does anyone have info on when PERL was created?  Some idiot wrote a
: proposal to my company saying that PERL has no practical application
: outside of the WWW.  So I wanted to know by how much PERL pre-dates
: the web for a little extra oomph for my reply.  Thanks.


My Camel says 1986 ("History Made Practical"  chap. 8, p554)

[
  Anyone have a date for the invention of the WWW?
]


I would be very surprised if more than half of all the world's
Perl programming was for CGI stuff.

I make my living with it doing non-CGI stuff.


Perl is a general purpose programming language. There are plenty of
application areas other than CGI where Perl programming flourishes...


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Tue, 1 Jul 1997 21:12:26 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: tim@hcirisc.cs.binghamton.edu
Subject: Re: When was PERL created?
Message-Id: <Pine.GSO.3.96.970701205546.8754D-100000@kelly.teleport.com>

On Tue, 1 Jul 1997 tim@hcirisc.cs.binghamton.edu wrote:

> Does anyone have info on when PERL was created?  Some idiot wrote a
> proposal to my company saying that PERL has no practical application
> outside of the WWW.  So I wanted to know by how much PERL pre-dates
> the web for a little extra oomph for my reply.  

I don't have the exact date, but we're coming up on the ten year
anniversary. It was some time in 1987, I believe. 

Although the most popular tool on the web is Perl, most uses of Perl
aren't involved with the web.

Incidentally, if you can find a copy, the "Classic Camel" book would make
a good tool to show that Perl was in serious use in 1991, with no mention
of the web to be found from one pink cover to the other. Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 2 Jul 1997 15:08:08 GMT
From: "Kim jae-bong" <jbkim@cnt.co.kr>
Subject: Win32::OBBC with Perl 5.004.01 on WinNT4.0
Message-Id: <01bc86af$b8bd6530$64a77fd2@pitecus>

$)CHello? ^^

I'm very glad to your reading this acticle....

I have some problem with Win32::ODBC..

I have upgrade my perl deamon from 5.003_07 to 4.00_01.

Then I received Win32:ODBC Error..

That nodule conplict with config.pm & Dynaloader.pm..

Please anybody help me... who use Win32::ODBC and 5.004_01..

I'll wait for your kind help.... -_-;

Thanks....


					In Korea
					Kim, jae-bong
					jbkim@cnt.co.kr




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

Date: Wed, 2 Jul 1997 04:51:47 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Y2K and Perl (was Re: Y2K problems??)
Message-Id: <ECoDIC.4Eu@nonexistent.com>

M.J.T. Guy (mjtg@cus.cam.ac.uk) wrote on 1400 September 1993 in
<URL: news:5paqtk$7ma@lyra.csx.cam.ac.uk>:
++ Russ Allbery  <rra@stanford.edu> wrote:
++ >            /bin/date *does* have Y2K problems on some platforms.  For
++ >example, on SunOS /bin/date has no way of returning the full year rather
++ >than just the last two digits.
++ 
++ That's funny.   On my SunOS box:
++ 
++ % /bin/date
++ Tue Jul  1 12:47:07 BST 1997
++ % uname -a
++ SunOS nmg1.csi. 4.1.3 2 sun4c
++ 
++ So is my SunOS different from everyone else's?

No. 4.1.3_U1 and 4.1.4 seem to give 4 digit years too.


Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=new Math::BigInt+qq;$^F$^W783$[$%9889$^F47$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W98$^F76777$=56;;$^U=$]*(q.25..($^W=@^V))=>do{print+chr$^V%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.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 693
*************************************

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