[11595] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5195 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 22 02:07:24 1999

Date: Sun, 21 Mar 99 23:00:18 -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           Sun, 21 Mar 1999     Volume: 8 Number: 5195

Today's topics:
        "small" problem <syt@email*@sp\am|@|spa/m@*.com>
        array question (Mark P.)
    Re: displaying status. (Randal L. Schwartz)
    Re: FTP Recursive Directory Listing (John Stanley)
    Re: Help Needed Please!!! (Mark P.)
    Re: Help Needed Please!!! (Ronald J Kimball)
    Re: Here 's a good one !!! (Jim and Paula)
        How to take advantage of Win9X printer drivers. <advlach@teleport.com>
    Re: HTML in email (Ethan H. Poole)
        module export not working (Jim and Paula)
        Newbie perl/CGI question (Part II) q969@truman.edu
    Re: Newbie perl/CGI question (Part II) <kennerNOSPAM@xnet.com>
        Perl/Apache-1.3.4 Can't find library? <xeno@bigger.aa.net>
    Re: Problem with image display (Abigail)
    Re: Problem with image display (Ronald J Kimball)
    Re: Problem with image display (Larry Rosler)
    Re: Regex Question (Ronald J Kimball)
        round_off_error_help(newbieQ:) (Defacto)
    Re: round_off_error_help(newbieQ:) (Sam Holden)
    Re: round_off_error_help(newbieQ:) <ebohlman@netcom.com>
    Re: round_off_error_help(newbieQ:) (Tad McClellan)
    Re: round_off_error_help(newbieQ:) (Larry Rosler)
    Re: sending data to another server help please <ebohlman@netcom.com>
    Re: sending data to another server help please (Abigail)
        Sending/recieving scsi commands - DLT on Solaris <bobn@interaccess.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Mon, 22 Mar 1999 00:27:35 -0600
From: "Jim" <syt@email*@sp\am|@|spa/m@*.com>
Subject: "small" problem
Message-Id: <7d4nst$24s$1@news3.infoave.net>

I am just starting perl scripting and I have a small problem that I just
cant figure out how to do.  I need to read text from a file and put the text
into different categories according to their first value...
It may be easier to look at the example below

here's what I have now, I need to be able to put the file into different
arrays according to $prodcat(at least that's what i think i need to do)

sub start{
open(DATABASE, "$path/database.txt");
@datainfo = <DATABASE>;
close(DATABASE);
print "Content-type: text/html\n\n";
print "Stuff";
foreach $i (@datainfo)
{
($prodcat, $prodname, $prodprice) = split(/\|/, $i);
print "<h2>$prodcat $prodname $prodprice<br>\n";
}
exit ;
}

here's what that does if the text in the database is like below:

cd|big stuff|19.95
pillow|garbage|10.92
cd|black|1.83

it outputs this

Stuff
<h2>cd big stuff 19.95
<h2>pillow garbage 10.92
<h2>cd black 1.83

however I need it to do this without having to specify the categories
anywhere except in the database file itself.

cd
<h2>big stuff 19.95
<h2>black 1.83

pillow
garbage 10.92



Thanks for any help,
Jim

reply to the newsgroup or to:
syt {at} email {dot} com







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

Date: Mon, 22 Mar 1999 04:34:50 GMT
From: mag@imchat.com (Mark P.)
Subject: array question
Message-Id: <36f5c7d5.269147233@news.ionet.net>

I'm trying to do a match of file extensions listed in an array with an
uploaded file, but my stuff aint working. Can someone see whats going
wrong here?

$query -> import_names('Q');
$file_extension = $Q::file_to_upload-01;
$file_extension =~ /\.(.*)$/is;
   if ($file_extension) {
        foreach $extension (@extension) {
           if ($file_extension =~ m/$extension/i) {
                  $check_extension = 1;
                last;
            }
        }
    }
    else {
        $check_extension = 1;
    }
     if ($check_extension != 1) { &error2; }



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

Date: 21 Mar 1999 20:26:02 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: displaying status.
Message-Id: <m1g16y9mlh.fsf@halfdome.holdit.com>

>>>>> "Rahul" == Rahul K <rahulk@iname.com> writes:

Rahul> I am trying to implement something like what you see at
Rahul> www.metacrawler.com.
Rahul> If you type a query and hit enter, you will get something like this:

Rahul> -----snip---------------------------------------
Rahul> Getting results for query: test

Rahul> Yahoo!: 10 references returned.
Rahul> Infoseek: 10 references returned.
Rahul> Lycos: 8 references returned.
Rahul> WebCrawler: 10 references returned.
Rahul> Thunderstone: 10 references returned.
Rahul> finished sending hits....
Rahul> -----snip---------------------------------------
Rahul> and then the page changes to the result.

Rahul> how can I do that.

How about telnetting to the server and seeing what it spits out when
you enter a query, after first reading the source for the form to get
the fieldnames?

Any good CGI hacker should know how to do that. :-)

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: 22 Mar 1999 03:11:19 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: FTP Recursive Directory Listing
Message-Id: <7d4ccn$3oo$1@news.NERO.NET>

In article <__PI2.396$P7.9080@typhoon.mbnet.mb.ca>,
Kevin S (xS) <xs@dmusic.com> wrote:
>Does anyone know how to get the a recursive listing off all the files and
>dirs on an ftp using Net::FTP? 

Retrieve a file named ls-R or similar. This is how an ftp site admin who
wants you to have a recursive listing of his site will provide it to
you.



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

Date: Mon, 22 Mar 1999 05:19:19 GMT
From: mag@imchat.com (Mark P.)
Subject: Re: Help Needed Please!!!
Message-Id: <36f5d1e8.271726842@news.ionet.net>

On Mon, 22 Mar 1999 00:26:29 +0000, On Line Auctions UK
<support@onlineauctions.co.uk> wrote:

>If any one could answer this for me i'd be eternally grateful.
>I've got a html form that sends three fields to a cgi script but the cgi
>script doesn't read the fields. It works on my own computer but when i
>upload it to the server it doesn't. here's a cut down version of the
>html code and below that is the cgi script.
>
Try using this instead of a broken print command.


>CGI Script,
>#!/bin/perl
>
>$count = 0;
>$type = "Sail";
>
>&readdata;
>
>sub readdata {
>
>  #read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>
>  $buffer = $ENV{QUERY_STRING};
>
>  @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;
>    $fromweb{$name} = $value;
>  }
>
>  $type = $fromweb{"type"};
>  $lenght = $fromweb{"lenght"};
>  $price = $fromweb{"price"};
>
>  print "Content-type: text/html\n\n";
>  print qq~
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">
>  <HTML>
>
>  <HEAD>
>   <META HTTP-EQUIV=\"Content-Type\"
>CONTENT=\"text/html;CHARSET=iso-8859-1\">
>   <META NAME=\"GENERATOR\" Content=\"Visual Page 1.1 for Windows\">
>   <TITLE>untitled</TITLE>
>  </HEAD>
>
>  <BODY>
>
>  <P>
>  <FRAMESET   COLS = \"18%,82% \"  >
>     <FRAME
>SRC=\"http://www.host.com/ucgi-bin/tyh/read.cgi?type=$type&lenght=$lenght&price=$price\"
>NAME=\"Frame8116318\" RESIZE>
>     <FRAME
>SRC=\"http://www.host.com/ucgi-bin/tyh/main.cgi?number=100015\"
>NAME=\"Frame8116332\" RESIZE>
>  </FRAMESET>
>
>  <NOFRAMES>
>
>  </BODY>
>
>  </NOFRAMES>
>
></HTML>~;
>
>
	Notice the print qq~ and the ending ~; Everything between will
print out with unescaped quotes. What killed your script was that the
print command has to be one unbroken line.


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

Date: Mon, 22 Mar 1999 01:26:16 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Help Needed Please!!!
Message-Id: <1dp1mko.1j0ensm1m7p6o8N@p38.block2.tc2.state.ma.tiac.com>

Mark P. <mag@imchat.com> wrote:

>   Notice the print qq~ and the ending ~; Everything between will
> print out with unescaped quotes. What killed your script was that the
> print command has to be one unbroken line.


~> perl
print qq~
Bullsh-t.
~;
__END__
Bullsh-t.


Please test your assertions before you post them.  Especially when
they're wrong.  ;-)

-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Mon, 22 Mar 1999 04:11:27 GMT
From: gemhound@gemhound.com (Jim and Paula)
Subject: Re: Here 's a good one !!!
Message-Id: <36f5c2eb.17040192@news.primeline.com>

On Sat, 20 Mar 1999 00:18:15 GMT, nospam@here.com wrote:

>If you're using  NT you can set a buffer size for your command prompt
>window.  Then all you have to do is scroll up to your first error.

The best solution for me was to discover Uedit, which lets you run
perl from the editor, then captures err or std output to a file that
it loads for your perusal.  I tried a few other editors and they did
fine on most compilers but gave me fits on Perl.  Uedit seems to have
no problems.

Jim Mooney


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

Date: Sun, 21 Mar 1999 20:01:54 -0800
From: Alan Vlach <advlach@teleport.com>
Subject: How to take advantage of Win9X printer drivers.
Message-Id: <36F5C0B2.1E322EC5@teleport.com>


Hello:

My customary way of producing printable hardcopy is to write perl code
that spits out a TeX file, process with TeX, and print with dvips.  This
all works fine on my Linux box with heavily customized LaTeX style files
and Ghostscript for my specially-purchased Postscript fonts, yielding
very sharp-looking tables and high-quality typeset text.

But how would I do this on the Win9X boxes of my clients?  It would be
unwieldy, to say the least, to duplicate my TeX setup on each of my
clients' Win boxes.

In short, what's the best way to use perl2exe and take advantage of the
Win9X printer drivers, using the TrueType or Postscript fonts that are
resident on the Win9X box?  I know nothing about how the typical Win
apps do their printing.

For instance, if I were to print a file created by, say, WordPerfect or
Quicken, and intercept it after it left the application but before it
got to the printer driver, what language would it be in?  My
understanding is that the driver then converts *that* (whatever `that'
is) to something the printer understands, ususally PCL or PostScript.

There must be docs on this somewhere, but in the four Perl books I own,
index entries under `print' only deal with terminal or ASCII file
output.

Any pointers/references/resources would be appreciated.

Kindly please cc a copy of your reply to advlach@teleport.com

Thanks,
--Alan Vlach


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

Date: Mon, 22 Mar 1999 01:04:05 -0500
From: ehpoole@ingress.com (Ethan H. Poole)
Subject: Re: HTML in email
Message-Id: <0xTtKnCd#GA.172@rejz.ij.net>

[Posted and Emailed]  In article <36f5a7b4.33047619@news.pyro.net>, 
britts@pyro.net says...
>
>>
>>>      print MAIL 'Content-type: text/html\n\n';
>>
>>That just doesn't work. 
>>
>>A 5 second test would have shown that to you.
>
>Yeah, you're right.  This is the line that I have been using:
>
>        print "Content-type: text/html\n\n";
>
>Now, I realize that I am not printing to a pipe, but this line -- with
>double quotes -- does print a header for HTML.  I had ASS-umed that
>single quotes would work as well.  What is the discrepancy there???

Give it a try and see for yourself (you're more likely to remember if you 
*see* the difference).

Anything in single quotes is treated literally. So whereas the double quoted 
print "Content-type: text/html\n\n" prints "Content-type: text/html" followed 
by two line-feeds, print 'Content-type: text/html\n\n' will print 
"Content-type: text/html\n\n" with no line feeds (it literally prints '\n').

-- 
Ethan H. Poole              | Website Design and Hosting,
                            | CGI Programming (Perl & C)..
========Personal=========== | ============================
* ehpoole @ ingress . com * | --Interact2Day, Inc.--
                            | http://www.interact2day.com/



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

Date: Mon, 22 Mar 1999 04:11:19 GMT
From: gemhound@gemhound.com (Jim and Paula)
Subject: module export not working
Message-Id: <36f5c2e1.17030752@news.primeline.com>

I'm trying to learn how to make modules.  I used the standard h2xs
program and created one called cvthtml, that presently just says
"hello" for testing. I'm exporting and preloading the sub, as per
below -- the rest just being the autogenerated boilerplate, which
should be okay:

@EXPORT = qw( sayHello); 

$VERSION = '1.00';

# Preloaded methods go here.

sub sayHello { print "\nHello, sucker!\n"; }

I also ran makefile.pl as directed in the directory where cvthtml is,
and it returned a-okay, although I'm not quite sure whate makefile.pl
is for.

The trouble is, sayHello only works in the calling program when I
qualify it totally in my program. i.e. even if my program has 

use cvthtml; 

in it I have to say 

cvthtml::sayHello()

 to get sayHello() to work.  If I just use a bare sayHello()   I get a
subroutine undefined message.  Why isn't sayHello being exported into
my namespace?

I'm using ActivePerl for Win 32, which I think also does things a
little differently than the books I'm using.  I know I had to do
perl makefile.pl  which generated makefile.  I have a feeling there is
a step after that, since makefile is just sitting there, but I can't
find any exes that do anything with it.   I tried typing  Make, but
there is no such executable anywhere in the activestate dist that I
can find.  I'm a bit fuzzy on makefiles, as it's been thirty years
since I did any substantive programming and that was in cobol.



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

Date: Mon, 22 Mar 1999 06:04:01 GMT
From: q969@truman.edu
Subject: Newbie perl/CGI question (Part II)
Message-Id: <36f5dac6.119235311@news.truman.edu>

I'm trying to parse out newlines (using the =~ command) and replace
them with spaces (though any character would do).  The command I've
used is $value[$n] =~ tr/\n/ /;  But this never works (I've tried
changing the 'tr' to an 's').  I get the same output to the text file
whether I include this line or not.

Here's the relevant code:

open (LOG, ">>datafile");
$DataLen = $ENV{'CONTENT_LENGTH'};
read (STDIN, $QueryString, $DataLen);
@Pairs = split (/&/, $QueryString);
$n = 0;
print LOG "\n";
foreach $NameValue (@Pairs)
{
        ($Name[$n], $Value[$n]) = split (/=/, $NameValue);
        $Value[$n] =~ tr/+/ /;
        $Value[$n] =~ s/%([a-fA-F0-9][a-fA-F0-9])/ pack ("C", hex
($1))/eg;
        $value[$n] =~ s/%(\w\w)/pack("C",hex($1))/eg;
        $value[$n] =~ tr/\n/ /; # <---- line in question
        print LOG $Value[$n], "^";
        $n++;
}  

The script usually works except when the user enters multiple lines.
When this happens, the above script stores the newline, and then when
it later tries to read the datafile, it reads the newline as a record
delimeter.  So I want to replace the newlines with spaces (or
anything), but the line $value[$n] =~ tr/\n/ / doesn't do it.

If you care to know the background / purpose of it: it's a script made
to pull data from a form-enabled web page.  It then writes the data to
a text file.  It also has a feature by which the user can revise
previously entered data.  In this case, it reads data from the text
file and displays as a web page.

I'd appreciate any recommendations.

Nate Sternberg


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

Date: Mon, 22 Mar 1999 00:49:29 -0600
From: "Kenner" <kennerNOSPAM@xnet.com>
Subject: Re: Newbie perl/CGI question (Part II)
Message-Id: <7d4pb7$1kt$1@flood.xnet.com>

Nate:

Hi.  I've been away from Perl for a bit, but I saw that you were from
Truman, so I felt compelled to take a swing.  (I graduated from Truman when
it was still NMSU in '94 - you're q969, I was c341).

Anyway, one thing I noticed was here:

>         $Value[$n] =~ tr/+/ /;
>         $Value[$n] =~ s/%([a-fA-F0-9][a-fA-F0-9])/ pack ("C", hex
> ($1))/eg;
>         $value[$n] =~ s/%(\w\w)/pack("C",hex($1))/eg;
>         $value[$n] =~ tr/\n/ /; # <---- line in question
>         print LOG $Value[$n], "^";

You start out with $Value[$n] but your bottom substitutions are on
$value[$n], which is a different  (new) hash entirely because of the
difference in capitalization.  If you cut and pasted this from your program
that may be why it's failing.

There may be something else, or you may have simply mistyped when you were
posting, but that's what leapt out at me.
I hope this helps you get finished and you can go celebrate with a beer and
some onion rings at Bogie's.

--
Kenner
(Remove NOSPAM for e-mail success.)
________________________________
Q:  "These balloons blow up into funny shapes?"
A:  "Not unless round's funny."



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

Date: 22 Mar 1999 05:59:49 GMT
From: Xeno Campanoli <xeno@bigger.aa.net>
Subject: Perl/Apache-1.3.4 Can't find library?
Message-Id: <7d4m8l$7cc$1@slave2.aa.net>

This may be more of an Apache or Linux question.  I've got Apache 1.3.4,
plain, on Red Hat with 2.0.36 Linux Kernel.  I've got a Elogin.cgi script
that works on one machine with this configuration, but a newer, faster
machine with a more recent installation of the OS and Apache with the
same release numbers gives me the following diagnostic:

Can't locate Cfg.pm in @INC (@INC contains: /home/dbadmin/pmlib
/usr/lib/perl5/5.00502/i686-linux-thread /usr/lib/perl5/5.00502
/usr/lib/perl5/site_perl/5.005/i686-linux-thread
/usr/lib/perl5/site_perl/5.005 .) at /home/httpd/cgi-bin/SC/Elogin.cgi
line 17.
BEGIN failed--compilation aborted at /home/httpd/cgi-bin/SC/Elogin.cgi
line 17.
[Mon Mar 22 05:51:47 1999] [error] [client 192.168.100.34] Premature end
of script headers: /home/httpd/cgi-bin/SC/Elogin.cgi

Now, the Cfg.pm is in /home/dbadmin/pmlib, in both places.  As near as I
can tell, the protections are the same in both places.  The only major
difference I see is that on the newer one I've got i686-linux-thread, and
on the older one I've got i586-linux thread.

Also, when I just execute Elogin.cgi from the command line, it goes just
fine, as I'd expect.

Anybody seen this kindof thing before?

Thanks for any feedback.

Sincerely, Xeno Campanoli


-- 
Xeno Campanoli
Email:	xeno@aa.net	(Web pages:  http://www.aa.net/~xeno)


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

Date: 22 Mar 1999 05:15:02 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Problem with image display
Message-Id: <7d4jkm$ouf$2@client2.news.psi.net>

Paul (psl1@home.com) wrote on MMXXIX September MCMXCIII in
<URL:news:36F5B0BA.A589797F@home.com>:
'' Hello all,
'' 
'' I am attempting to display an image (.gif) on a web page depending on
'' the time of day. When the script runs, instead of the gif image, I get a
'' broken image icon appearing in the web page.


So, it looks like your web page worked. There's no point in posting the
code that generates that web page. Of course, something went wrong in
creating/linking the images, we you don't tell us how the images are
generated. The code that generates the web pages however, suggest that
the images are fixed. Hence, it doesn't look like a Perl problem at all.



Abigail
-- 
perl -wle '(1 x $_) !~ /^(11+)\1+$/ && print while ++ $_'


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

Date: Mon, 22 Mar 1999 01:26:17 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Problem with image display
Message-Id: <1dp1n6h.rpc840bh8x04N@p38.block2.tc2.state.ma.tiac.com>

Paul <psl1@home.com> wrote:

> #!/usr/local/bin/perl
> #
> # test.pl
> #
> #
> #$| = 1;
> $base = "./cgi-bin/";
> $gif1 = "morning.gif";
> $gif2 = "noon.gif";
> $gif3 = "evening.gif";
> #print "Content-Type: text/html\n\n\n"; 
> chop ( $hour = `/bin/date '+%H'` ); 
> # display image depending on the time of day
> if ($hour < 12) { print "<CENTER><IMG SRC=\"$base$gif1\"></CENTER>\n"; }
> if ($hour > 11) { if ($hour < 17) { print "<CENTER><IMG
> SRC=\"$base$gif2\"></CENTER>\n"; }}
> if ($hour > 16) { print "<CENTER><IMG SRC=\"$base$gif3\"></CENTER>\n" }

If this script is run from the cgi-bin/ directory, then these URLs would
put your images in the cgi-bin/cgi-bin/ directory.  Is that really where
they are?


Other issues:

Why aren't you outputing the Content-type header?  Without that, the
browser doesn't know what to do with the data it gets. [*]

Use chomp() instead of chop().

Use localtime() instead of the `date` command.

Use logical-and instead of nested if statements.

Use elsif instead of consecutive if statements.

Use a quoting operator instead of backslashing double-quotes.
(print qq{<CENTER><IMG SRC="$base$gif3"></CENTER>\n)


[*] Probably because you're calling this script from within an IMG tag
on another HTML page.  In that, the Content-type is image/gif, and you
need to output the image data itself, not HTML containing an IMG tag.


HTH!

-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sun, 21 Mar 1999 22:23:06 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Problem with image display
Message-Id: <MPG.115f819fbae851d39897a2@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <36F5B0BA.A589797F@home.com> on Mon, 22 Mar 1999 02:54:35 
GMT, Paul <psl1@home.com >says...
 ... 
> I am attempting to display an image (.gif) on a web page depending on
> the time of day. When the script runs, instead of the gif image, I get a
> broken image icon appearing in the web page.
> Can anyone help this newbie to perl?  Below is the script:
> ...
> $base = "./cgi-bin/";

This is almost certainly the problem.  Your path is relative to the 
current directory, but you have not set that explicitly.  Why are your 
images in a directory called cgi-bin, anyway?  That should be for 
programs.

> #print "Content-Type: text/html\n\n\n";	

You need that line printed in your output, of course.

> chop ( $hour = `/bin/date '+%H'` );	

$hour = (localtime)[2]; # perl does it faster and better!

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personl/Larry_Rosler/
lr@hpl.hp.com


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

Date: Mon, 22 Mar 1999 01:26:24 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Regex Question
Message-Id: <1dp1niw.p5xh6h1rfxdabN@p38.block2.tc2.state.ma.tiac.com>

Abigail <abigail@fnx.com> wrote:

> Well, the regex didn't work because you were attempting to preserve
> blank days. As you've noticed, at the end of the month, there are not
> blanks. 
> 
> split works. You've just to take care of the cases with less than 7 days.
> 
> But you had to do that already, else you wouldn't have asked here.
> 
> 
> split is the way to go.

I disagree.  If you use split, then you have to go to the trouble of
putting the blank days back in that you tossed by splitting on
whitespace -- as in Jonathon Stowe's code.  The regex solution with /g
is about 10 lines shorter.

But, of course, TMTOWTDI.  :)

-- 
chipmunk (Ronald J Kimball) <rjk@linguist.dartmouth.edu>
perl -e 'print map chop, sort split shift, reverse shift
' 'j_' 'e._jP;_jr/_je=_jk{_jn*_j &_j :_j @_jr}_ja)_js$_j
~_jh]_jt,_jo+_jJ"_jr>_ju#_jt%_jl?_ja^_jc`_jh-_je|' -rjk-


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

Date: Mon, 22 Mar 1999 03:43:47 GMT
From: defactod@hotmail.com (Defacto)
Subject: round_off_error_help(newbieQ:)
Message-Id: <36f6be1d.8737869@news.accessv.com>

i have been using 'learning perl5' in 21 days, 
and came across this script:

$one = 14.3;
$two = 100 + 14.3 - 100; 
 if ($one == $two) {
	print ("the two ARE the same\n");
}else{
	print ("the two are NOT the same\n");
	}

 it says in the book that it will come up as 'NOT'. 
they are not the same numbers,
 O.K. Here's my question, how do i avoid such problems? rather,
how do i ensure that floating point addition (or sub,mult,whichever)
uses the same numbers in comparisons(==)? Is it that numbers like 
these must always be in hex or octal notation? 
thanks in advance....
                                   defacto


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

Date: 22 Mar 1999 04:50:26 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: round_off_error_help(newbieQ:)
Message-Id: <slrn7fbj0i.40h.sholden@pgrad.cs.usyd.edu.au>

On Mon, 22 Mar 1999 03:43:47 GMT, Defacto <defactod@hotmail.com> wrote:
>i have been using 'learning perl5' in 21 days, 
>and came across this script:
>
>$one = 14.3;
>$two = 100 + 14.3 - 100; 
> if ($one == $two) {
>	print ("the two ARE the same\n");
>}else{
>	print ("the two are NOT the same\n");
>	}
>
> it says in the book that it will come up as 'NOT'. 
>they are not the same numbers,
> O.K. Here's my question, how do i avoid such problems? rather,
>how do i ensure that floating point addition (or sub,mult,whichever)
>uses the same numbers in comparisons(==)? Is it that numbers like 
>these must always be in hex or octal notation? 
>thanks in advance....

You use integers or you put up with floating point rounding errors.

Never use '==' with floating point numbers (unless you really know 
what you are doing).

You should check that the numbers are 'close enough' for your purposes.

-- 
Sam

We prefer English to remain a rich language, quirky, sloppy, and full
of redundancy. Same for Perl. 
	--Larry Wall


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

Date: Mon, 22 Mar 1999 04:53:46 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: round_off_error_help(newbieQ:)
Message-Id: <ebohlmanF8zC9M.CnG@netcom.com>

Defacto <defactod@hotmail.com> wrote:
:  O.K. Here's my question, how do i avoid such problems? rather,
: how do i ensure that floating point addition (or sub,mult,whichever)
: uses the same numbers in comparisons(==)? Is it that numbers like 
: these must always be in hex or octal notation? 

Quite simply, you don't compare two floating-point numbers for exact 
equality.  This holds for any programming language.  You can test if 
their difference is less than an amount that you specify, or even test 
the percentage difference between them.



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

Date: Sun, 21 Mar 1999 19:06:07 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: round_off_error_help(newbieQ:)
Message-Id: <fh14d7.a54.ln@magna.metronet.com>

Defacto (defactod@hotmail.com) wrote:
: i have been using 'learning perl5' in 21 days, 
: and came across this script:

: $one = 14.3;
: $two = 100 + 14.3 - 100; 
:  if ($one == $two) {
: 	print ("the two ARE the same\n");
: }else{
: 	print ("the two are NOT the same\n");
: 	}

:  it says in the book that it will come up as 'NOT'. 
: they are not the same numbers,
:  O.K. Here's my question, how do i avoid such problems? 


   Don't use == on floating point numbers.


: rather,
: how do i ensure that floating point addition (or sub,mult,whichever)
: uses the same numbers in comparisons(==)? 


   That won't matter now, because you are not going to use 
   == on floating point numbers   :-)


: Is it that numbers like 
: these must always be in hex or octal notation? 


   Very close. Computer store numbers in binary (octal and hex
   are alternate ways to write the binary number).

   Some cannot be represented exactly in binary.

   Just as 1/3 cannot be represented exactly in base 10.

   This is really a number theory question rather than anything
   specific to Perl.



   There is more discussion in the Perl FAQ, part 4:

      "Why am I getting long decimals (eg, 19.9499999999999) 
       instead of the numbers I should be getting (eg, 19.95)?"


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


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

Date: Sun, 21 Mar 1999 22:30:32 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: round_off_error_help(newbieQ:)
Message-Id: <MPG.115f8363f23cfebe9897a3@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <36f6be1d.8737869@news.accessv.com> on Mon, 22 Mar 1999 
03:43:47 GMT, Defacto <defactod@hotmail.com >says...
 ...
> how do i ensure that floating point addition (or sub,mult,whichever)
> uses the same numbers in comparisons(==)? 

You should *NEVER* use == in comparing floating-point numbers!  Asking 
if two floaing-point numbers are equal is like asking if two piles of 
sand have the same number of grains.  Decide on an interval that means 
'equal' and test accordingly.

For example (assuming $b is not zero):

   if (abs($a/$b - 1) < 1e-10) { # $a and $b are 'equal' # }

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personl/Larry_Rosler/
lr@hpl.hp.com


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

Date: Mon, 22 Mar 1999 04:50:12 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: sending data to another server help please
Message-Id: <ebohlmanF8zC3o.CHv@netcom.com>

Gary Mayor <support@onlineauctions.co.uk> wrote:
: Hello i need urgent help on this please. I need to send data from a cgi
: script to another cgi script on another server. I've got a script on the
: recieving server that can read data through a normal browser process
: such as http://www.recieving host.com/cgi-bin/read.cgi?var1=data but how
: do i code this in perl any ideas?

You almost certainly want to use the LWP module.  If you don't already 
have it, get it from CPAN and read the excellent documentation (including 
the _LWP Cookbook_) that comes with it.



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

Date: 22 Mar 1999 05:18:45 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: sending data to another server help please
Message-Id: <7d4jrl$ouf$3@client2.news.psi.net>

Gary Mayor (support@onlineauctions.co.uk) wrote on MMXXIX September
MCMXCIII in <URL:news:36F594C2.EF8FEA3F@onlineauctions.co.uk>:
\\ Hello i need urgent help on this please. I need to send data from a cgi
\\ script to another cgi script on another server.

Why is it that everyone scatters their cgi programs over various server?

Here's a simple, trivial solution:
   copy the cgi program from the other server to your server.

\\                                                 I've got a script on the
\\ recieving server that can read data through a normal browser process
\\ such as http://www.recieving host.com/cgi-bin/read.cgi?var1=data but how
\\ do i code this in perl any ideas?


Just open a socket to the other server, and write the appropriate info.
The LWP module might help you.

Still, copying the cgi program is much, much, *MUCH* simpler and faster.




Abigail
-- 
perl -wleprint -eqq-@{[ -eqw\\\\- -eJust -eanother -ePerl -eHacker -e\\\\-]}-


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

Date: Fri, 19 Mar 1999 23:29:56 -0600
From: bobn <bobn@interaccess.com>
Subject: Sending/recieving scsi commands - DLT on Solaris
Message-Id: <36F33253.D3C9C7BA@interaccess.com>

I'm trying to retrieve information from a DLT drive (not the tape in the
drive, but registers/pages inside the controller) connected to a Sun Ultra-2
box running Solaris 2.5.1.  These pages have information regarding compression
ratios, error logs, etc.

Sun states there is no utility to do this that they know of.  Quantum has one,
but i only runs on DOS (barf).

I have doc from Quantum (who actually makes the tape drive) giving frame
formats for various inquiry and response frames.

I'm at something of a loss as what device to open (using normal utilities such
as ufsdump, the device name is /dev/rmt/0) and how to send data so that the
system sends it as scsi commands (or DLT commands?) rather than as data to go
to tape.

I've actually tried read/write to /dev/rmt/0 - the write of an inquiry frame
doesn't faile, but attempting to read the response does.

I've tried severla searches of CPAN and found nothing.  Any help in
understanding how to do this. either from the Unix or Perl point of view,
would be highly appreciated.

- Bob N.


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

Date: 12 Dec 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 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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