[7066] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 691 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 1 23:17:22 1997

Date: Tue, 1 Jul 97 20:00:20 -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           Tue, 1 Jul 1997     Volume: 8 Number: 691

Today's topics:
     Re: BIG databases <joel@uptimecomputers.com>
     Cannot run NT EXE's from CGI <roger@mantamedia.com>
     Re: CGI:downloading .exe with Perl xewj@odin.sunquest.com
     Compression in Perl <igorv@styx.or.fedex.com>
     Re: Exporting environment variables in CGI-script <xrcc0494@dcaca037.ca.boeing.com>
     Re: Forking process doesn't recognize EOF (Charles DeRykus)
     Re: help me...Perl save all messages again in my file.. (Tad McClellan)
     Re: Help w/newbie Perl runtime Error (Tad McClellan)
     Re: How to write a socket-based network server in perl? (Nathan V. Patwardhan)
     Re: Perl Scripts and forms (Tad McClellan)
     Re: Perl, PostgresQL, CGI (Michael Fuhr)
     Problem understanding how to dereference with File::Lis <abennett@stonehill.edu>
     recomended books <mlfbox@earthlink.net>
     recursion <gland@ccs.neu.edu>
     STAT command <mrski@gist-inc.com>
     updating tab deliminated data files using Perl iscape@access.digex.net
     use of sprintf and filehandles <otp@cyberservices.com>
     Re: using @_ (Clay Irving)
     Re: Y2K and Perl (was Re: Y2K problems??) (Stephen Frost)
     Re: Y2K and Perl (was Re: Y2K problems??) <rra@stanford.edu>
     Re: Y2K and Perl (was Re: Y2K problems??) <robatino@cnj.digex.net>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Tue, 1 Jul 1997 15:29:02 -0700
From: "Joel B. Stalder" <joel@uptimecomputers.com>
To: Patrick Verdon <patrick@Smallworld.co.uk>
Subject: Re: BIG databases
Message-Id: <Pine.LNX.3.95.970701150736.1912B-100000@rain.uptimecomputers.com>



On 26 Jun 1997, Patrick Verdon wrote:

> Hi all,
> 
> I'm needing to find a database, accessible from PERL, ideally free,
> that can cope with up to 2,000,000 records, consisting of user
> name, id and probably a couple of other fields. 
> 
> I don't really know where to start; I've read through some archives
> at www.dejanews.com, that refer to things like GDBM, or DS_file and
> I've also been recommended 'postgres 95'.
> 
> Can anyone make any other suggestions, or offer working examples?
> 
> What kind of lookup times (for a given user, say) can I expect from a 
> database of this size on perhaps a SPARCstation 20 or an UltraSPARC?
> 
> What do I need to do to optimise speed of access?
> 
> If you can offer any help I would be most grateful.
> 
> Cheers.
> 
> 
> 
> Patrick

Hi Patrick,

You may wish to peruse mySQL, which is an "almost-free" (check the
license) database that is quite snappy. As I understand it, speed is the
top objective of mySQL's on-going development. 

Additonally, mySQL has a DBD driver, which is what I use to access it from
perl. All of this is on the home page.

The home page can be found at http://www.tcx.se. The FAQ links are quite
helpful.

Hope you find this useful,


joel



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

Date: Tue, 01 Jul 1997 16:25:03 -0400
From: Roger Vernon <roger@mantamedia.com>
Subject: Cannot run NT EXE's from CGI
Message-Id: <33B9679F.4420@mantamedia.com>

I have a relatively simple mail script that I am trying to get to work. 
It is unable to execute any external EXE files without dieing.

I'm just about ready to shoot either myself or the server.  I
temporarily gave IUSR_INET (the anonymous user) all permissions to the
CGI-BIN directory the PERL\BIN directory and even the  WINNT directory.
So it doesn't appear to be a permissions problem.  The script runs from
the command line when I run it but the CGI script cannot run any
external EXE's (I tried blat, windmail, wsendmail...) they all die at
execution.  I am running on NT 4 and IIS 3 and the latest version of
PERL Win/32.  The script I am running is listed below.  Please HELP!!! 
Any suggestions could save a life!

Suggestions that have been made or that I have found are: go into the
registry and add the CreateProcessWithNewConsole value.  This was
already done by the PERL installation, but I double checked it just to
make sure.  Many people have told me that it is a permissions problem. 
I appreciate the help a great deal (truly) however, if it's permissions
I'll be damned if I know what additional rights I'd have to give to the
IUSR_INET user to appease the net Gods.  Arrrg!


Thanks in advance for your help, please E-Mail your suggestions to me at
roger@mantamedia.com.  Thanks again!


#!/perl/perl.exe
$mailprog = "d:\\Perl\\bin\\windmail.exe";

#this is the send to e-mail address
$recipient = "rvprivate\@mantamedia.com";

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

@pairs = split(/&/, $buffer);

foreach $pair
(@pairs)                                                          
{
    ($name, $value) = split(/=/, $pair);

    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $FORM{$name} = $value;
}
		open (MAIL, "|$mailprog -t $recipient");
		print MAIL "$FORM{'NameField'} says that he works at \n";
		print MAIL "$FORM{'CompanyField'}\n";
		print MAIL "-------------------------------------------------\n";
		print MAIL ".\n";
		close (MAIL);
        print "HTTP/1.0 200 OK\n";
        print "Content-type: text/html\n\n";
        print "<HTML>\n";
        print "<HEAD>\n";
        print "<TITLE>Thanks!</TITLE>\n";
        print "<BODY BGCOLOR=\"#FFFFFF\">\n";
        print "Thanks $FORM{'NameField'} for running this test!";
        print "</BODY></HTML>\n";
        exit;


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

Date: 1 Jul 1997 17:18:44 GMT
From: xewj@odin.sunquest.com
Subject: Re: CGI:downloading .exe with Perl
Message-Id: <5pbe5k$sl8$1@iggy.sunquest.com>

In article <slrn5qqg4v.b0j.asfast@ljz.asfast.net>,
Lloyd Zusman <ljz@asfast.com> wrote:
>On Sun, 22 Jun 1997 08:51:55 -0600, sann0474@sable.ox.ac.uk <sann0474@sable.ox.ac.uk> wrote:
>> From discussions in this newsgroup and other sources I have some code (see
>> below) to allow a user to download an .exe file from an HTML page.  On
>> small-ish files (<1.5meg) this works just fine.  However, as the since of
>> file to be downloaded gets larger, it seems to take longer and longer
>> before the browser actually begins to download until files > 1.5 meg just
>> seems to hang.  Note that while I can't quite figure out what the server
>> is doing, it is doing something based on it's light and memory usage.
>> [ ... ]
>The statement I marked (above) reads the entire file into an array before
>it starts printing.  For large files, this has two side effects:
>(1) It may take a long time (on a slow machine) for the entire file to
>    get read in before printing.
>(2) You may run out of virtual memory before the file can get read in
>    completely, thereby causing your CGI to crash before it can send
>    anything back to you.
>A solution would be for you to replace that line with the following loop:
>   while (defined($line = <THEFILE>)) { print $line;   }

While this is a facet of the problem, there are other issues: a lot of the
web servers I've worked with buffer the output of a script.
Instead of the cgi talking directly with the browser, the httpd sits there,
reading in all the output of the cgi, making sure it's valid and performing
substitutions and such as directed, then sending it on to the browser.
So.... for a 5 meg file, you might end up taking about 10megs of swap space
under the original method (5 for the perl script reading into memory, 5 for
the httpd buffering it before sending it on).

A *much* more efficient method of sending back an exe is to not have the 
perl script or httpd buffer it at all. Store it external to the perl script
and then have the script do this:
########################snippeth here###########################
print <<FEOF;
Location: $URL_to_exe_file
Content-type: text/html

Your browser doesn't support redirection.<br>
Click <a href="$URL_to_exe_file">HERE</a> to go to the file.<br>

FEOF
########################snippeth here###########################

Of course, this limits elegant execution to those browsers which support
redirection. Most do, though.


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

Date: Tue, 01 Jul 1997 18:19:38 -0500
From: Igor Vulfson <igorv@styx.or.fedex.com>
Subject: Compression in Perl
Message-Id: <33B9908A.64F2@styx.or.fedex.com>

Does anyone have a code that would compress a string of upper case
characters into a shorter string? - will need to decompress later!

Thanks,
iv
-- 
Igor Vulfson                  |  Email: mailto:ivulfson@fedex.com
Senior Scientific Programmer  |  URL:   http://www.magibox.net/~unabest/
Operations Research, FedEx    |  Work:  (901)395-7358   Home: 
(901)624-0776


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

Date: Tue, 1 Jul 1997 23:02:00 GMT
From: "robert c. combs" <xrcc0494@dcaca037.ca.boeing.com>
Subject: Re: Exporting environment variables in CGI-script
Message-Id: <33B98C68.1D12@dcaca037.ca.boeing.com>

Try something like ...

use Env qw(ORACLE_HOME ORACLE_SID ORACLE_USER ORACLE_PASSWD);
$ORACLE_HOME = "blah";
$ORACLE_SID = "other blah";
etc.


Paul Jorstad wrote:
> 
> Hi!
> 
> I have a CGI-script which also use other modules.
> My problem is that a few of these modules need some environment
> variables to be set. I try to export the variables, but it doesn't
> seems that the modules get them
> In my case, the DBI/DBD library needs some variables so the Oracle
> driver can work.
> 
> RGDS Paul


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

Date: Wed, 2 Jul 1997 01:33:04 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Forking process doesn't recognize EOF
Message-Id: <ECo4B5.4o0@bcstec.ca.boeing.com>

In article <5pak4u$ajq$1@happy.informatik.uni-ulm.de>,
Martin Patzel  <patzel@happy.informatik.uni-ulm.de> wrote:
 > 
 > the program below creates a sub-process which works as an input filter
 > to the main perl program. All data transfer should be through stdin/stdout.
 > 
 > So the data pipe should look like this:
 > stdin -> perl-sub-process ----(pipe)----> perl-main-process -> stdout
 > 
 > The only problem now I have is: The perl main-process (father) doesn't
 > notice the EOF of it's stdin (which comes from the sub-process).
 > The sub-process dies, the father gets a SIGCHLD and does a wait, but
 > it doesn't recognize the EOF.
 > 
 > In the end the main process should also exec another (real) program,
 > but if I uncomment the exec-line below, the (real) program doesn't
 > recognize the EOF, too.
 > 
 > Another mysterious thing: if I uncomment the "close STDIN" in the
 > parent process, no data at all is copied to the file t1.log.
 > 
 > Where is the problem? Could someone help me please?
 > 
 > Thanks,
 > Martin
 > 
 > #!/usr/bin/perl
 > 
 > pipe P_RD, P_WR;
 > 
 > $SIG{CHLD} = sub { $child = wait; print "sigchld: $child\n"};
 > 
 > if ($pid = fork) # Parent reads from pipe (=stdin) and writes to stdout
 > {
 > 	# close STDIN;
 --->  	open(STDIN, "<&P_RD") or die $!;  ## add error checking 
 --->   close P_WR or die $!;      ##  close write end of pipe
 > 	open (T, ">t1.log") && do { while(<>) {print T}; close T};
 > 	# use the line above *or* below
 >   	# exec("cat -u >t1.log");
 > 	exit 1;
 > }
 > else # Child reads from stdin and writes to pipe (=stdout)
 > {
 --->  	open(STDOUT, ">&P_WR") or die $!;
 --->  	close P_RD or die $!;
 > 	select(STDOUT); $| = 1;
 > 	exec("cat -u");
 > 	exit 1;
 > }


The pipe reader will need to close the write handle and
the pipe writer should close the read handle as shown
above.  Some error checking thrown in gratis :)

Check the blue Camel pipe entry (pg 198) for details. 


HTH,

--
Charles DeRykus
ced@carios2.ca.boeing.UNLISTED.com


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

Date: Tue, 1 Jul 1997 15:48:41 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: help me...Perl save all messages again in my file... :((
Message-Id: <9fqbp5.bp8.ln@localhost>

Sergio Stateri Jr (serginho@alpha.hydra.com.br) wrote:
: Hi again Perl Users!

: Now I'm having a terrible problem. I did a script that read a file of
: messages saved and get the lastest ID message and increment one. The
: problem is that when I save a new message (with this new id), Perl save all
: other messages again, or repeat all the messages in the file...But I'm
: saving only the new message...Here is the script that do this...


Do you want to wipe out the contents of the file, and replace them
with the new message?

If so, then see below.


: if (open(SAIDA,"+<mensag.dat"))
: {
:   $existe_from = 0;

:   if (open(LISTA,"<lista.txt"))
:   {
:     @lista_total = <LISTA>;
:     foreach $value(@lista_total)
:     {
:       $email    = substr($value,34,40) if
: (substr($value,4,length($in{'from'})) eq $in{'from'});
:       $cod_from = substr($value,0,4)   if
: (substr($value,4,length($in{'from'})) eq $in{'from'});
:     }
:     $existe_from = 1;
:   }

:   @tot_mensagens = <SAIDA>;
:   $msg_id = '000000';
:   foreach $value(@tot_mensagens)
:   {
:     if (substr($value,0,4) eq '!NM!') # i inmcio de registro
:       {  $msg_id = substr($value,4,6);  }
:   }
:   $msg_id++; # Soma 1 ao id da ultima mensagem


seek(SAIDA, 0, 0) || die "could not seek  $!";       # rewind to start of file
truncate(SAIDA, 0) || die "could not truncate  $!";  # zero out the file
 
OR

simply close() and reopen the SAIDA filehandle


:   print SAIDA "!NM!"; 				              # New Message ID
:   print SAIDA "0" x (6-length($msg_id)), $msg_id;             # Message ID
:   print SAIDA $cod_from, " " x (4-length($cod_from));         # Sender
:   print SAIDA $ip_remoto,      " " x (15-length($ip_remoto)); # IP 
:   print SAIDA "$mday/$mon/$year","$hour:$min:$sec";          
:   print SAIDA "\n";
:   print SAIDA $in{'subject'};
:   print SAIDA "\n";
:   print SAIDA $in{'message'},"\n";
:   
:   close(SAIDA);
: ----------------------------------------------------------------------------
: ------------------------------------------------------------

: What's happenning ? I save one time the new message, and Perl sve all other
: messages again...


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


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

Date: Tue, 1 Jul 1997 16:46:57 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Help w/newbie Perl runtime Error
Message-Id: <hstbp5.qu8.ln@localhost>

John Keller (jkeller@gridnet.com) wrote:

: I'm having a problem when running a PERL script I wrote (copied). I get the
: following error:

: Can't locate sys/socket.ph in @INC (did you run h2ph?) at recep.pl line 8.


But that is not a runtime error.

That is a compilation error...


: It is pointing to line 8 , which is:

: require 'sys/socket.ph';		<---- line 8
: require 'sys/errno.ph';
: require 'sys/wait.ph';
: require 'getopts.pl';

: I'm assuming I need some libraries that I managed to not install. I am

Yep.

Once you figure out how to get the required files (by applying h2ph
to your C code header files), then you can install them where perl
can find them.

To see where perl looks, you can do:

perl -e 'foreach (@INC) {print "$_\n"}'


: running PERL on a SunOS v4.1.4 Sparc 20. Any idea as to where I can get the
: missing files, 


http://www.perl.org/CPAN/


: or is my problem something else? 
: What is h2ph? 


I think the discussion in the Perl FAQ answers that.

What part of the discussion there are you unclear on?


: Help
: appreciated, send a reply to jkeller@gridnet.com, 


Ask it here, get the answer here.


: or reply to the
: newsgroup.

OK.


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


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

Date: 2 Jul 1997 00:58:05 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: How to write a socket-based network server in perl?
Message-Id: <5pc92t$55b@fridge-nf0.shore.net>

Rich Tsui (tsui@cbmi.upmc.edu) wrote:

:     Anyone has idea how to write a socket based network server in perl
: running on UNIX box?  It would be great if you could attach a simple
: version of server and client codes or direct me where to get those.

There's a simple client/server offered in the perlipc manpage.

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: Tue, 1 Jul 1997 16:39:39 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Perl Scripts and forms
Message-Id: <retbp5.0t8.ln@localhost>

Angel Rodgers (rodgeral@jmu.edu) wrote:
: I am new to Perl and CGI.  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?  So far I have tried:

: open (FILE, ">$file")
                       ^
                       ^ need a semicolon here

Better yet, how about checking to see if the file got opened successfully?

open (FILE, ">$file") || die "could not open '$file'  $!";


: if ($input{'title'} eq '') {
: 	print FILE "Please input title\n\n" ;
: } elsif ($input{'Designation'} eq '') {
: etc.

: However, I am getting the an error message of 
: syntax error at line 17 near "{"

: Any suggestions?
  ^^^^^^^^^^^^^^^
  ^^^^^^^^^^^^^^^


Fix the syntax error.


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


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

Date: 1 Jul 1997 19:25:00 -0600
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: Perl, PostgresQL, CGI
Message-Id: <5pcalc$7sa@flatland.dimensional.com>

Michael Yeung <michaely@pcm.com.au> writes:

> I'm currently working on a databasing project in which I'm designing an
> applications interface in HTML.  In order to interface with the database
> (Postgres), I need to write CGI scripts with embedded SQL., Does anyone
> know how this could be done with Perl5?

You could use DBI/DBD-Pg or pgsql_perl5; for writing CGI scripts you'll
also want CGI.pm.  You can get modules from the Comprehensive Perl
Archive Network (CPAN):

    http://www.perl.org/CPAN/

There's also a DBI page at:

    http://www.hermetica.com/technologia/perl/DBI/

Hope this helps.

-- 
Michael Fuhr
http://www.dimensional.com/~mfuhr/


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

Date: Tue, 01 Jul 1997 18:16:23 +0100
From: Aaron Bennett <abennett@stonehill.edu>
Subject: Problem understanding how to dereference with File::Listing
Message-Id: <33B93B5B.87471EEC@stonehill.edu>

I'm trying to write a perl script to automate some basic operations on all
files in a tree of directories.  

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.  When I
call parse_dir like this:

#!/usr/local/perl -w

   use File::Listing;

   $mydir=".";

@list=parse_dir(`ls -l $mydir`);
print @list;

The result is:

ARRAY(0xa472c)ARRAY(0xa46cc)ARRAY(0x10ca90)ARRAY(0xa55b8)ARRAY(0xa5618)ARRAY(0xa
5678)ARRAY(0xa56d8)ARRAY(0xa572c)ARRAY(0xa5780)ARRAY(0xa57e0)ARRAY(0x11e45c)ARRA
Y(0x11e4bc)ARRAY(0x11e51c)ARRAY(0x11e57c)ARRAY(0x11e5dc)ARRAY(0x11e630)ARRAY(0x1
1e684)ARRAY(0x11e6d8)ARRAY(0x11e72c)ARRAY(0x11e780)ARRAY(0x11e7d4)ARRAY(0x11fc50
)ARRAY(0x11fca4)ARRAY(0x11fcf8) etc. 

as the results.  Now I read in the documentation that parse_dir returns a
reference to an array of $filena,me, $filetype, etc., but I can't figure out
how to get at that stuff.  I've been reading the camel book on de-referencing,
but I think I may just be too dense to get it.  Could someone show me an
example of how to do this? 

Thanks, 

Aaron Bennett.

-- 
|	Aaron Bennett, 	Internet Services Coordinator,
|	Stonehill College Department of Academic Computing
| 	http://www.stonehill.edu 
|			"The most precious things remain unseen."


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

Date: Tue, 01 Jul 1997 15:06:38 -0700
From: Mildred Box <mlfbox@earthlink.net>
Subject: recomended books
Message-Id: <33B97F6E.6438@earthlink.net>

can any of you recommend any good books or web sites on the langauge...

if so email me at mlfbox@earthlink.net


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

Date: 1 Jul 1997 23:44:07 GMT
From: Greg Land <gland@ccs.neu.edu>
Subject: recursion
Message-Id: <5pc4o7$s37$1@camelot.ccs.neu.edu>

I would like to know if anyone can help me do two things...

1)Make the script "jump" through links as many levels as asked for by the user
2)The current setup requires you to type "http://www.xxx.xxx.xxx" instead of just "www.xxx.xxx.xxx"

						Thanks in advance

							Greg
Here is the script:

use LWP::Simple;
use HTML::Parse;
use HTML::Element;
use URI::URL;
$num = 1;

if ($ARGV[0] eq "") {
print ("Usage: http://<domain name>/<path>\n");
print ("use \"SHORT\" as the argumennt not to expand the path to images\n")
}

$html = get $ARGV[0];
$parsed_html = HTML::Parse::parse_html($html);

for (@{$parsed_html->extract_links()  })  {
$link = $_->[0];
$total = $num++;
print "$total ";
$url    = new  URI::URL $link;
$full_url = $url->abs($ARGV[0]);
print "$full_url\n";
}
print ("\nDo you want a copy of the full source? [y/n] ");
$source = <STDIN>;
chop($source);
if ($source eq "y"){
getprint($ARGV[0]);
} else {
print ("Good bye\n");
exit;
}
print ("\nDo you want to save the source? [y/n] ");
$save = <STDIN>;
chop($save);
if ($save eq "y"){
} else {
print ("Good bye\n");
exit;
}
print ("\nWhat file do you want to create? ");
$file = <STDIN>;
chop($file);
getstore($ARGV[0], $file);
if (-e $file && $file != "") {
print ("$file saved sucessfully\n");
} else {
print ("Good bye\n");
exit;
}


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

Date: 30 Jun 1997 18:01:56 GMT
From: "Mitch Duszynski" <mrski@gist-inc.com>
Subject: STAT command
Message-Id: <01bc857f$8ba1aa60$a3df94ce@mrski.gist-inc.com>

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
MODIFIED date is in need of translation to get the date.  Anyone know how
to do that?

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

-- 
Mitch "SKI" Duszynski
Global Information Systems Technology, Inc.


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

Date: Tue, 01 Jul 1997 18:11:49 -0600
From: iscape@access.digex.net
Subject: updating tab deliminated data files using Perl
Message-Id: <867797959.29490@dejanews.com>

Hello. As a slightly experienced Perl user, I am interested in adviec
from any of your pros/experts on how to best achieve the following
task.

I have a file of information that is being broadcast on the web. I am
going to need to update this web available information periodically
but I don't want to have to add the updates to the entire file myself.
Instead I plan to make a tab deliminated list of data into a 2nd file and
then I'll write a Perl script to compare the new information against the
old information, erasing, updating and adding the new information to the
existing "old" file. Basically just updating one big file from a smaller
file which contains only the changes, additions, etc.

Can anyone recommend the best Perl method for comparing the files and
updating them? Of course if you've done something similar, I'd enjoy your
stories on how you did it - else if you have some method suggestions
please send them to me at iscape@access.digex.net

Any help is appreciated.

Best Wishes!

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: Tue, 01 Jul 1997 20:45:41 -0500
From: Ian Merkel <otp@cyberservices.com>
Subject: use of sprintf and filehandles
Message-Id: <33B9B2BE.A30ED0E0@cyberservices.com>


--------------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];

open (SOURCE, $sourcefile);
@lines = <SOURCE>;

foreach $line (@lines)
{
    chop $line;
    ($indexfield, $field1, $field2, $field3, $field4) =
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");
    print PEOPLE "%10s %25s %25s\n",
                 $field1_list{$indexfield},
                 $field2_list{$indexfield},;
    close (PEOPLE);


    open (PINFO, ">>uinfo.dat");
    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?  odds are that there are a better way of
doing this?  can anyone out there help me?

thanks

ian!



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

<HTML>
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...)

<P><FONT FACE="Courier New,Courier"><FONT SIZE=-1>#-------------commence
code</FONT></FONT>

<P><FONT FACE="Courier New,Courier"><FONT SIZE=-1>#!/usr/bin/perl</FONT></FONT><FONT FACE="Courier New,Courier"><FONT SIZE=-1></FONT></FONT>

<P><FONT FACE="Courier New,Courier"><FONT SIZE=-1>$sourcefile = $ARGV[0];</FONT></FONT><FONT FACE="Courier New,Courier"><FONT SIZE=-1></FONT></FONT>

<P><FONT FACE="Courier New,Courier"><FONT SIZE=-1>open (SOURCE, $sourcefile);</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1>@lines = &lt;SOURCE>;</FONT></FONT><FONT FACE="Courier New,Courier"><FONT SIZE=-1></FONT></FONT>

<P><FONT FACE="Courier New,Courier"><FONT SIZE=-1>foreach $line (@lines)</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1>{</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp; chop
$line;</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp; ($indexfield,
$field1, $field2, $field3, $field4) = split(/|/,$line);</FONT></FONT><FONT FACE="Courier New,Courier"><FONT SIZE=-1></FONT></FONT>

<P><FONT FACE="Courier New,Courier"><FONT SIZE=-1>#&nbsp;&nbsp;&nbsp; $indexfield
is a numeric field</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1>#&nbsp;&nbsp;&nbsp;
$field1 - $field4 are strings</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1>&nbsp;</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp; $field1_list{$indexfield}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
=~ crypt($field1_list{$indexfield}, "SALT");</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp; $field2_list{$indexfield}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
=~ tr/ /_/;</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp; $field3_list{$indexfield}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
=~ tr/ /_/;</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp; $field4_list{$indexfield}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
=~ tr/ /_/;</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1></FONT></FONT>&nbsp;<FONT FACE="Courier New,Courier"><FONT SIZE=-1></FONT></FONT>

<P><FONT FACE="Courier New,Courier"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp; open
(PEOPLE, ">>file1.ext");</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp; print
PEOPLE "%10s %25s %25s\n",</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$field1_list{$indexfield},</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$field2_list{$indexfield},;</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp; close
(PEOPLE);</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1></FONT></FONT>&nbsp;<FONT FACE="Courier New,Courier"><FONT SIZE=-1></FONT></FONT>

<P><FONT FACE="Courier New,Courier"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp; open
(PINFO, ">>uinfo.dat");</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp; print
PINFO "%10s %25s %25s \n", $usernamelist{$clientnumber},</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$field2_list{$indexfield},</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$field3_list{$indexfield},</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$field4_list{$indexfield};</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1>&nbsp;&nbsp;&nbsp; close
(PINFO);</FONT></FONT><FONT FACE="Courier New,Courier"><FONT SIZE=-1></FONT></FONT>

<P><FONT FACE="Courier New,Courier"><FONT SIZE=-1>}</FONT></FONT><FONT FACE="Courier New,Courier"><FONT SIZE=-1></FONT></FONT>

<P><FONT FACE="Courier New,Courier"><FONT SIZE=-1>close (SOURCE);</FONT></FONT><FONT FACE="Courier New,Courier"><FONT SIZE=-1></FONT></FONT>

<P><FONT FACE="Courier New,Courier"><FONT SIZE=-1>#-------------end of
code</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1></FONT></FONT>&nbsp;<FONT FACE="Courier New,Courier"><FONT SIZE=-1></FONT></FONT>

<P><FONT FACE="Courier New,Courier"><FONT SIZE=-1>am i doing anything wrong?&nbsp;
odds are that there are a better way of doing this?&nbsp; can anyone out
there help me?</FONT></FONT><FONT FACE="Courier New,Courier"><FONT SIZE=-1></FONT></FONT>

<P><FONT FACE="Courier New,Courier"><FONT SIZE=-1>thanks</FONT></FONT><FONT FACE="Courier New,Courier"><FONT SIZE=-1></FONT></FONT>

<P><FONT FACE="Courier New,Courier"><FONT SIZE=-1>ian!</FONT></FONT>
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1></FONT></FONT>&nbsp;
<BR><FONT FACE="Courier New,Courier"><FONT SIZE=-1></FONT></FONT>&nbsp;</HTML>

--------------27845BF76209C4A243549793--



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

Date: 1 Jul 1997 19:30:10 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: using @_
Message-Id: <5pc3u2$rjl@panix.com>

In <33B80DCA.5E65@nu.com> gardipj@nu.com writes:

>In the following routine, I am trying to capture the $price variable
>locally (this is a shopping cart program) and then multiply that
>by 5% sales tax. Why won't the following work? Is it because I am
>using @_? If so, how can I get around that?

>When I run this, the MAtax output is 0.

>I am fairly new to Perl and cannot find the answer in any of my books.

>******************************
>sub cart_table_footer { 
>  local($price) = @_;
>  local($MAtax) = $price * 0.05;
>  print qq!
>    <P>
>    Pre-shipping, Pre-tax Total = $price
>    <P>
>    Price after MA tax = $MAtax
>    <P>!;
>}

>******************************

Running this program:
  
  #!/usr/local/bin/perl5.003 -w
  
  cart_table_footer(10.00);
  
  sub cart_table_footer {
    local($price) = @_;
    local($MAtax) = $price * 0.05;
    print qq!
      <P>
      Pre-shipping, Pre-tax Total = $price
      <P>
      Price after MA tax = $MAtax
      <P>!;
  }
  
Produces this outut:

      <P>
      Pre-shipping, Pre-tax Total = 10
      <P>
      Price after MA tax = 0.5
      <P>

What did you test with?

-- 
Clay Irving                                        See the happy moron,
clay@panix.com                                     He doesn't give a damn,
http://www.panix.com/~clay                         I wish I were a moron,
                                                   My God! Perhaps I am!


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

Date: 1 Jul 1997 23:21:01 GMT
From: frostbyt@shell02.ozemail.com.au (Stephen Frost)
Subject: Re: Y2K and Perl (was Re: Y2K problems??)
Message-Id: <5pc3ct$96t@proxy5.proxy.ozemail.net>

M.J.T. Guy (mjtg@cus.cam.ac.uk) wrote:
: 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?

It's not much different here:

dainfo% /bin/date
Wed Jul  2 09:16:45 EST 1997
dainfo% uname -a
SunOS dainfo 4.1.4 1 sun4c

Unless, of course, it's just *displaying* 1997 when internally it is
represented as just 97?  Haven't tested this theory ... just thinking
out loud.  I'd be surprised if that were true.

Steve


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

Date: 01 Jul 1997 15:24:47 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Y2K and Perl (was Re: Y2K problems??)
Message-Id: <m3pvt2s95c.fsf@windlord.Stanford.EDU>

In comp.lang.perl.misc, Jarkko Hietaniemi <jhi@alpha.hut.fi> writes:
> mjtg@cus.cam.ac.uk (M.J.T. Guy):

>> So is my SunOS different from everyone else's?

> box1 (74) >/bin/date
> Tue Jul  1 16:30:17 EET DST 1997
> box1 (75) >uname -a
> SunOS box1 4.1.4 2 sun4m
> box1 (76) >

> I have no idea what Russ is trying to say here:

> Russ Allbery <rra@stanford.edu>:
>> For example, on SunOS /bin/date has no way of returning the full year
>> rather than just the last two digits.

This:

sunos-image:~> /bin/date +%Y
date: bad format character - Y
sunos-image:~> /bin/date +%y
97
sunos-image:~> uname -a
SunOS sunos-ima 4.1.4 4 sun4m

If you're using the % format strings rather than just running date,
there's no format string under SunOS /bin/date that will give you the full
year.  Only the last two digits.  See the man page for confirmation.  And
using the % escapes is somewhat common in Perl scripts to get the date in
an easily parsable format.

(SunOS thankfully *does* have a working strftime that supports %Y.  But
apparently /bin/date doesn't use strftime or otherwise has additional
braindeath.)

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Tue, 01 Jul 1997 20:29:15 -0400
From: Evan Robatino <robatino@cnj.digex.net>
Subject: Re: Y2K and Perl (was Re: Y2K problems??)
Message-Id: <33B9A0DB.37D7@cnj.digex.net>

Stephen Frost wrote:
> 
> M.J.T. Guy (mjtg@cus.cam.ac.uk) wrote:
> : 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?
> 
> It's not much different here:
> 
> dainfo% /bin/date
> Wed Jul  2 09:16:45 EST 1997
> dainfo% uname -a
> SunOS dainfo 4.1.4 1 sun4c
> 
> Unless, of course, it's just *displaying* 1997 when internally it is
> represented as just 97?  Haven't tested this theory ... just thinking
> out loud.  I'd be surprised if that were true.
> 
> Steve

You may want to check out the Sun Year 2000 Compliance page:

http://www.sun.com/y2000/cpl.html

to see if your particular OS release is Y2K compliant.  It's possible
you're on a version that has to be upgraded or patched to get rid of
this type of glitch (if it IS a glitch).  Another possibility, I suppose
is that there's an environment variable that controls the formatting of
the output of this command (just an educated guess; please don't flame
me if I'm wrong, I don't have access to a Sun system at the moment to
check it out ;-) ).

Evan
-- 
-------------
Evan Robatino           |  No-frills signature
robatino@cnj.digex.net  |  http://www.cnj.digex.net/~robatino/index.html
Piscataway, NJ,  USA
Finger the above E-mail ID for public PGP
(Pretty Good Privacy encryption software) key.


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

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

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