[7481] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1107 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 30 22:07:33 1997

Date: Tue, 30 Sep 97 19:00:22 -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, 30 Sep 1997     Volume: 8 Number: 1107

Today's topics:
     [req] a procmail replacement in perl <nico@idnet.fr>
     Re: [req] a procmail replacement in perl <kjj@pobox.com>
     accessing permissions (rwx) (Dhiraj Raj)
     Re: accessing permissions (rwx) (Martien Verbruggen)
     Re: any faith in me? <rootbeer@teleport.com>
     Re: connect() and sockets (Martien Verbruggen)
     Re: Getopt::Long <rpsavage@ozemail.com.au>
     Re: I failed to install the Perl. Could you help me? (Martien Verbruggen)
     Multiple Simultaneous prints??? (Wolfgang Viechtbauer)
     Re: Multiple Simultaneous prints??? (brian d foy)
     Re: Newbie ques: How to concatenate two strings? <rootbeer@teleport.com>
     Re: NEWBIE: How  do you check for Non existance of a fi (Martien Verbruggen)
     problem with int() function? (v. 5.002) (Brandon Fagan)
     Re: problem with int() function? (v. 5.002) (brian d foy)
     Re: Recursive object reader <sriram@weblogic.com>
     Re: Regular Expressions: Negating bracketed strings (Jon Orwant)
     Script can't find module! (Rand Simberg)
     Re: Socket problems in 5.001, not in 5.003 (Neil Harkins)
     Re: splitting a tab delimited line <rootbeer@teleport.com>
     Re: splitting a tab delimited line (Jon Orwant)
     The Obfuscated Perl Contest Victors (Jon Orwant)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Wed, 01 Oct 1997 00:20:48 +0100
From: Nicolas MONNET <nico@idnet.fr>
Subject: [req] a procmail replacement in perl
Message-Id: <34318945.8CC9D173@idnet.fr>

    Honestly, I looked everypossiblewhere, and could not find that: a
procmail/deliver eqv writen in Perl.

    Quite surprising.

    Anyone has clue on how to setup a .forward that pipes into a perl
script -- well, that's not itself a problem -- but how to have the stuff
the script put the mail in the right, default place on some conditions
(and otherwise kill/forward the message)?

    Thanks!

nico@idnet.fr



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

Date: 30 Sep 1997 18:30:01 -0700
From: Kevin Johnson <kjj@pobox.com>
Subject: Re: [req] a procmail replacement in perl
Message-Id: <m2lo0enuca.fsf@pobox.com>

Nicolas MONNET <nico@idnet.fr> writes:

>     Honestly, I looked everypossiblewhere, and could not find that: a
> procmail/deliver eqv writen in Perl.
> 
>     Quite surprising.

mailagent

-- 
thx,
kjj@pobox.com   http://www.pobox.com/~kjj/


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

Date: 30 Sep 1997 23:49:25 GMT
From: draj@chronologic.com (Dhiraj Raj)
Subject: accessing permissions (rwx)
Message-Id: <60s365$428$1@viewlog.viewlogic.com>


how do i access the permissions (rwx) of a file in perl

thanks



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

Date: 1 Oct 1997 01:30:03 GMT
From: mgjv@mali.comdyn.com.au (Martien Verbruggen)
Subject: Re: accessing permissions (rwx)
Message-Id: <60s92r$6vk$1@comdyn.comdyn.com.au>

In article <60s365$428$1@viewlog.viewlogic.com>,
	draj@chronologic.com (Dhiraj Raj) writes:
> 
> how do i access the permissions (rwx) of a file in perl

perldoc -f stat

The 3rd return value (index 2), called 'mode' will hold that information, IF
your OS does provide it.
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | I took an IQ test and the results were
Commercial Dynamics Pty. Ltd.       | negative.
NSW, Australia                      | 


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

Date: Tue, 30 Sep 1997 16:26:03 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: BrAnCh <branchms@foto.infi.net>
Subject: Re: any faith in me?
Message-Id: <Pine.GSO.3.96.970930162500.26927H-100000@usertest.teleport.com>

On Tue, 30 Sep 1997, BrAnCh wrote:

>   I learned HTML form Laura Lemay's Teach yourself web publishing with
> HTML 3.2 in a week.  and now i'm working on Teach yourself CGI
> programming with perl5 in a week (Eric Herrmann)  is this enough for me
> to learn with, or would you suggest I read something else first?? 
> 
> thanks for your time,
> Mark shellard.
> with aspirations of being a web site developer in the next 3 months.

Why is it taking you three months? Are you reading ten other books? :-)

-- 
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/
              Ask me about Perl trainings!



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

Date: 1 Oct 1997 00:06:41 GMT
From: mgjv@mali.comdyn.com.au (Martien Verbruggen)
Subject: Re: connect() and sockets
Message-Id: <60s46h$6bn$2@comdyn.comdyn.com.au>

In article <3430BF84.3CB7@aimnet.com>,
	Khayman <tekman@aimnet.com> writes:
> 'lo there, I've been working with Perl and got myself a problem.  I
> wrote an IRC bot in Perl some months back, but my isp was hacked and all
> my files gone.  Unfortunately I cannot remember how to setup the

no backups, huh?

> connection with an IRC server.  Any and all help would be greatly
> appreciated, esp. if someone could provide me with a connection routine. 

You wrote the bot yourself, but you forgot how you did it? Curious.

Anyway,

go to www.botspot.com, and download one of the perl bots from there. Check how
they did it. 
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | 
Commercial Dynamics Pty. Ltd.       | What's another word for Thesaurus?
NSW, Australia                      | 


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

Date: Wed, 01 Oct 1997 08:40:29 +1100
From: Ron Savage <rpsavage@ozemail.com.au>
Subject: Re: Getopt::Long
Message-Id: <343171CD.4995@ozemail.com.au>

Johan Vromans wrote:
> 
> mathias@singapura.singnet.com.sg (Mathias Koerber) writes:
> 
> > To use the 'alternative' form of calling GetOptions, one cal define
> > the linkages like this:
> >[snip]

A simple alternative is my package, with test script at the end:

package Getopt::Simple;

# Name:
#	Getopt::Simple.
#
# Documentation:
#	POD-style documentation is at the end. Extract it with pod2html.*.
#
# Purpose:
#	Provide a simple wrapper around Getopt::Long.
#
# Parameters:
#	1. A hash specifying your options.
#	2. A heading string output by the -help option.
#	3. A Boolean passed to $Getopt::Long::ignorecase.
#		0 -> (Default) Don't ignore case. 1 -> Ignore case.
#	3. A Boolean indicating whether or not the -help option should also
#		terminate with exit(1).
#		0 -> Don't exit. 1 -> (Default) Exit.
#
#	Each entry in the hash looks like:
#	'remoteIP' =>
#		{
#		'Type'		=> '=s',
#		'Env'		=> '$REMOTEHOST',
#		'Default'	=> $ENV{'REMOTEHOST'} || 'myUnixBox',
#		'Order'		=> '5',
#		},
#	where:
#	'remoteIP'	The command line switch used by the user.
#					The user may abbreviate this text. Eg: -r 121.343.565.787.
#	'Type'		The argument specifier for the switch. '=s' means -remoteIP
#					is followed by a mandatory string. See Getopt::Long.
#	'Env'		The environment variable used as the default value. This text
#					is output by the -help option.
#	'Default'	The value of the default. Ie this text actually specifies the
#					value, whereas Env says where the value comes from.
#	'Order'		The sort order used by the -help option to make the output
#					pretty. Eg: To force username to appear before password in
#					the test script's -help message.
#
# Return value:
#	Upon return, you - as the caller - can access the user's command line
#	via the hash reference $switch.
#	Given: ...>perl testScript.pl -remote 111.222.333.444
#	Access: print "remoteIP: $$switch{'remoteIP'}. \n";
#	Note: $$ is used to dereference a hash reference.
#
# Warning:
#	Remember to use
#		$Getopt::Long::ignorecase = 0;
#	before calling getOptions() to get case-sensitive (mixed case) switches.
#
# Tabs:
#	4 spaces || die.
#
# Author:
#	Ron Savage	19-Aug-97	rpsavage@ozemail.com.au.
# --------------------------------------------------------------------------

use strict;
no strict 'refs';
use vars qw(@default @EXPORT @EXPORT_OK @ISA);
use vars qw($default $fieldWidth $helpText $helpThenExit $ignoreCase $switch $VERSION);

use Exporter();
use Getopt::Long;

@ISA		= qw(Exporter);
@EXPORT		= qw(getOptions $switch);
@EXPORT_OK	= qw(dumpOptions helpOptions);

# --------------------------------------------------------------------------

@default		= ();
$default		= {};
$fieldWidth		= 15;
$helpText		= '';
$helpThenExit	= 0;
$switch			= {};
$VERSION		= '1.00';

# --------------------------------------------------------------------------

sub byOrder
{
	$$default{$a}{'Order'} <=> $$default{$b}{'Order'};
}

# --------------------------------------------------------------------------

sub dumpOptions
{
	print 'Option', ' ' x ($fieldWidth - length('Option') ), "Value\n";

	for (sort byOrder keys(%$switch) )
	{
		print "-$_", ' ' x ($fieldWidth - (1 + length) ), "$$switch{$_}\n";
	}

	print "\n";

}	# End of dumpOptions.

# --------------------------------------------------------------------------
# Return:
#	0 -> Error.
#	1 -> Ok.

sub getOptions
{
	push(@_, 0) if ($#_ == 2);	# Default for $ignoreCase is 0.
	push(@_, 1) if ($#_ == 3);	# Default for $helpThenExit is 1.

	($default, $helpText, $ignoreCase, $helpThenExit) = @_;

	$Getopt::Long::ignorecase = $ignoreCase;

	for (keys(%$default) )
	{
		push(@default, "$_$$default{$_}{'Type'}");
	}

	my($result) = &GetOptions($switch, @default);

	if ($$switch{'help'})
	{
		&helpOptions();
		exit(1) if ($helpThenExit);
	}

	for (keys(%$default) )
	{
		$$switch{$_} = $$default{$_}{'Default'} if (! $$switch{$_});
	}

	$result;

}	# End of getOptions.

# --------------------------------------------------------------------------

sub helpOptions
{
	print "$helpText\n" if ($helpText);

	print 'Option', ' ' x ($fieldWidth - length('Option') ),
		'Default', ' ' x ( (2 * $fieldWidth) - length('Default') ), "Env var used\n";

	for (sort byOrder keys(%$default) )
	{
		print "-$_", ' ' x ($fieldWidth - (1 + length) ),
			"$$default{$_}{'Default'}" .
			' ' x ( (2 * $fieldWidth) - length($$default{$_}{'Default'}) ),
			"$$default{$_}{'Env'}\n";
	}

	print "\n";

}	# End of helpOptions.

# --------------------------------------------------------------------------

1;

__END__

=head1 NAME

C<Getopt::Simple> - Provide a simple wrapper around Getopt::Long.

=head1 SYNOPSIS

	use Getopt::Simple;

	# use Getopt::Simple qw(:DEFAULT dumpOptions helpOptions);

	my($options) =
	{
	'help' =>
		{
		'Type'		=> '',
		'Env'		=> '-',
		'Default'	=> '',
		'Order'		=> 1,
		},
	'username' =>
		{
		'Type'		=> '=s',			# As per Getopt::Long.
		'Env'		=> '$USER',			# Help text.
		'Default'	=> $ENV{'USER'} || 'RonSavage',	# In case $USER is undef.
		'Order'		=> 3,				# Help text sort order.
		},
	'password' =>
		{
		'Type'		=> '=s',
		'Env'		=> '-',
		'Default'	=> 'password',
		'Order'		=> 4,
		},
	};

	if (! getOptions($options, "Usage: testSimple.pl [options]", 1, 0) )
	{
		exit(0);	# Failure.
	}

	print "username: $$switch{'username'}. \n";
	print "password: $$switch{'password'}. \n";

=head1 DESCRIPTION

The C<Getopt::Simple> module provides a simple way of specifying:

=over 4

=item *

Command line switches

=item *

Type information for switch values

=item *

Default values for the switches

=item *

Help text per switch

=back

=head1 The C<getOptions()> function

The C<getOptions()> function takes three parameters:

=over 4

=item *

A hash defining the command line switches

=item *

A string to display as a help text heading

=item *

A Boolean. 0 = (Default) Use case-sensitive switch names. 1 = Ignore case

=item *

A Boolean. 0 = Return after displaying help. 1 = (Default) Terminate with exit(1)
after displaying help

=back

=head1 The C<$switch> hash reference

Command line option values are accessed in your code by dereferencing
the hash reference C<$switch>. Two examples are given above.

Alternately, you may print all values with C<dumpOptions()>.

=head1 The C<dumpOptions()> and C<helpOptions()> functions

You may choose to import from C<Getopt::Simple> these 2 functions,
as in the comment line at the start of the synopsis.
Normally, however, there is no need to do this.

C<dumpOptions()> prints all your option's keys and their current values.

C<helpOptions()> prints nicely formatted help text.

=head1 REQUIRED MODULES

=over 4

=item *

Exporter

=item *

Getopt::Long

=back

=head1 RETURN VALUES

=over 4

=item *

C<dumpOptions()> returns nothing

=item *

C<helpOptions()> returns nothing

=item *

C<getOptions()> returns 0 for failure and 1 for success

=back

=head1 AUTHOR

C<Getopt::Simple> was written by Ron Savage I<E<lt>rpsavage@ozemail.com.auE<gt>> in 1997.

=head1 LICENCE

This program is free software; you can redistribute it and/or modify it under
the same terms as Perl itself, as long as I'm identified as the original author.

=cut

----8x----snip----8x----

#!/usr/local/bin/perl -w
#
# Name:
#	test.pl.
#
# Purpose:
#	To test Getopt::Simple.
#
# Usage:
#	>perl test.pl -q -u User -p Pass -l 333.222.111.000
#
# Tabs:
#	4 spaces || die.
#
# Author:
#	Ron Savage	20-Aug-97	rpsavage@ozemail.com.au.
# --------------------------------------------------------------------------

use integer;

# The following line is used only because I want to demonstrate dumpOptions()
# and helpOptions().
# Without that requirement, I'd use 'use Getopt::Simple;'.
use Getopt::Simple qw(:DEFAULT dumpOptions helpOptions);

# --------------------------------------------------------------------------

sub init
{
	my($default) =
	{
	'help' =>
		{
		'Type'		=> '',
		'Env'		=> '-',
		'Default'	=> '',
		'Order'		=> 1,
		},
	'quiet' =>
		{
		'Type'		=> '',
		'Env'		=> '-',
		'Default'	=> '',
		'Order'		=> 2,
		},
	'username' =>
		{
		'Type'		=> '=s',
		'Env'		=> '$USER',
		'Default'	=> $ENV{'USER'} || 'RonSavage',
		'Order'		=> 3,
		},
	'password' =>
		{
		'Type'		=> '=s',
		'Env'		=> '-',
		'Default'	=> 'password',
		'Order'		=> 4,
		},
	'remoteIP' =>
		{
		'Type'		=> '=s',
		'Env'		=> '$REMOTEHOST',
		'Default'	=> $ENV{'REMOTEHOST'} || 'UnixBox',
		'Order'		=> 5,
		},
	'localIP' =>
		{
		'Type'		=> '=s',
		'Env'		=> '$HOST',
		'Default'	=> $ENV{'HOST'} || '123.321.123.321',
		'Order'		=> 6,
		},
	'myHome' =>
		{
		'Type'		=> '=s',
		'Env',		=> '$HOME',
		'Default'	=> $ENV{'HOME'} || 'C:',
		'Order'		=> 7,
		},
	'yourHome' =>
		{
		'Type'		=> '=s',
		'Env',		=> '-',
		'Default'	=> '~',
		'Order'		=> 8,
		},
	};

	if (! getOptions($default, "Usage: test.pl [options]") )
	{
		exit(0);	# Failure.
	}

}	# End of init.

# --------------------------------------------------------------------------

&init();

print "\n";

dumpOptions();

print "Access some command line switches: \n";
print "username: $$switch{'username'}. \n";
print "password: $$switch{'password'}. \n";
print "remoteIP: $$switch{'remoteIP'}. \n";
print "localIP:  $$switch{'localIP'}.  \n";

print "\n";

helpOptions();


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

Date: 30 Sep 1997 23:59:43 GMT
From: mgjv@mali.comdyn.com.au (Martien Verbruggen)
Subject: Re: I failed to install the Perl. Could you help me?
Message-Id: <60s3pf$6bn$1@comdyn.comdyn.com.au>

In article <342f5d03.24915509@news.dacom.co.kr>,
	fallings@cdi.cheongjo.co.kr writes:

> Os : Sun Unix and solaris 2.5.1
> system : spark station 20
> 
> and the c compiler of Sun Soft is installed.

pretty similar to what I have here.

> and typed "sh Configure -des".
> 
> then the process continued. but it stopped in here..
> 
>>>>>>>>>>>>>>>>>>>>>
> cat: cannot open .clist
> cat: cannot open .hlist
>>>>>>>>>>>>>>>>>>>>>
> 
> I suspect that there are two makefiles, 'Makefile' and 'makefile'.

This is confusing.. Those error messages are during configure or during make?

There are indeed a Makefile and a makefile. The make that comes with the Sun
compiler should however just warn you about that, and then continue.

Which make are you using? You should be able to use gnu make, if it's
installed, or /usr/xpg4/bin/make. Check which makefile is being executed.
Check to see if you have a make somewhere in your path that might be broken.

-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | A Freudian slip is when you say one
Commercial Dynamics Pty. Ltd.       | thing but mean your mother.
NSW, Australia                      | 


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

Date: Wed, 01 Oct 1997 00:57:15 GMT
From: wviecht@rs6000.cmp.ilstu.edu (Wolfgang Viechtbauer)
Subject: Multiple Simultaneous prints???
Message-Id: <34319e84.2566091@news.ilstu.edu>

What happens if two or more people at the same time submit their data
with a form, that has the following Perl script to write the data to a
text file?

open (DATA, ">>/data.txt")
	|| die ("Couldn't write to data file.\n");
&ReadParse;

print DATA (($in{question1} eq "") ? "9" : $in{question1});
print DATA " ",(($in{question2} eq "") ? "9" : $in{question2});
print DATA " ",(($in{question3} eq "") ? "9" : $in{question3}),"\n";
close DATA;

Maybe since there are only three pieces of data that are written to
the file, it would go quick enough that there would not be any messes.
But what if there were hundreds of questions on the form and it would
take a while to send them?

My main concern is: Will I still get a nice listing of the data in a
row for each person or will it write data from two or three people
into the same row?

Any comments or suggestions? (especially, if you have any suggestions
on how to improve the script if my concern is justified).

Wolfgang




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

Date: Tue, 30 Sep 1997 21:32:00 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Multiple Simultaneous prints???
Message-Id: <comdog-ya02408000R3009972132000001@news.panix.com>

In article <34319e84.2566091@news.ilstu.edu>, wviecht@rs6000.cmp.ilstu.edu (Wolfgang Viechtbauer) wrote:

>What happens if two or more people at the same time submit their data
>with a form, that has the following Perl script to write the data to a
>text file?

don't try to find out ;)  lock the file in some fashion (see the
Perl FAQs for more info).

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Tue, 30 Sep 1997 16:50:48 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Ben Reser <ben@reser.org>
Subject: Re: Newbie ques: How to concatenate two strings?
Message-Id: <Pine.GSO.3.96.970930163031.26927K-100000@usertest.teleport.com>

On Tue, 30 Sep 1997, Ben Reser wrote:

> Whenever you can avoid interpolation do so.  That means if you don't
> need to quote something with double quotes don't.  

Naw. You can _always_ avoid double-quote interpolation. But we interpolate
because it's the best way to tell Perl (and our maintenance programmer)
what we want. These are some examples of everyday statements which would
all be harder to write, read, and understand if they weren't using
double-quote interpolation. 

    open FILE, "+>> $filename"
	or die "Can't open file '$filename' for update: $!";

    print <<"END";
To: $to
From: $from
Subject: $subject

I'm writing to you because your $fruit, at a cost of $cost per $unit has
become too expensive for my family to eat.  
END

    $fullinfo = "$last, $first (age $age)";

    print "The players are: @players.\n";

On the other hand, you should avoid anything which is hard to read, write,
or maintain. This is bad, IMHO:

    $users = "The list of users at @{[ scalar localtime ]} is @{[ 
	eval { my @temp = `who`; for (@temp) { chomp; s/\s.*$// }; 
	qq{@temp} } ]}.\n";

But no good Perl programmer would ever do anything like that, right? :-) 

-- 
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/
              Ask me about Perl trainings!



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

Date: 1 Oct 1997 00:10:38 GMT
From: mgjv@mali.comdyn.com.au (Martien Verbruggen)
Subject: Re: NEWBIE: How  do you check for Non existance of a file.
Message-Id: <60s4du$6bn$3@comdyn.comdyn.com.au>

In article <slrn632nsb.l5o.spamtrap@greycloak.access.one.net>,
	spamtrap@greycloak.access.one.net (Grey Cloak) writes:

> #if exist $whatfile ;

	if (-f $whatfile)
	{

		#---It does great let hear that baby
 		exec "/usr/bin/sox ~/$whatfile -t .au - > /dev/audio";
	}
	else
	{
 		#---Bummer it doesn't let them know they need to get it.
 		print "[WARN] $whatfile doesn't exist" ; || die;
	}

also try 

perldoc perlsyn

to read up on the syntax of perl.

-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | That's not a lie, it's a terminological
Commercial Dynamics Pty. Ltd.       | inexactitude.
NSW, Australia                      | 


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

Date: 30 Sep 1997 21:29:12 GMT
From: bfagan@tejas.sps.mot.com (Brandon Fagan)
Subject: problem with int() function? (v. 5.002)
Message-Id: <60rqv8$bk0$1@newsgate.sps.mot.com>

I am having a problem using the int() function.

The following code fragment:

------- begin included text

#!/usr/local/bin/perl

 $a = 0.7;
 $b = 0.05;
 $a2 = 0.07;
 $b2 = 0.005;

 printf("PERL VERSION: %s\n",$]);
 printf(" 0.7/0.05  = %f .... INT(0.7/0.05)   = %d\n",$a/$b,int($a/$b));
 printf("0.07/0.005 = %f .... INT(0.07/0.005) = %d\n",$a2/$b2,int($a2/$b2));

------- end included text

produces the following output:

PERL VERSION: 5.002
 0.7/0.05  = 14.000000 .... INT(0.7/0.05)   = 13
0.07/0.005 = 14.000000 .... INT(0.07/0.005) = 14

This is a problem, since 0.7 is clearly an even multiple (14) or 0.05.
Note that the output is correct when 0.07 and 0.005 are used.

Any thoughts?

-brandon
 
bfagan@amcu-tx.sps.mot.com


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

Date: Tue, 30 Sep 1997 19:25:38 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: problem with int() function? (v. 5.002)
Message-Id: <comdog-ya02408000R3009971925380001@news.panix.com>

In article <60rqv8$bk0$1@newsgate.sps.mot.com>, bfagan@tejas.sps.mot.com (Brandon Fagan) wrote:

>I am having a problem using the int() function.

>produces the following output:
>
>PERL VERSION: 5.002
> 0.7/0.05  = 14.000000 .... INT(0.7/0.05)   = 13
>0.07/0.005 = 14.000000 .... INT(0.07/0.005) = 14

it's the best a binary computer can do with real numbers.  let's 
get rid of the whole number portion and look at what is left:

   #!/usr/bin/perl

   $number = 0.7/0.05 - 14;
   print $number, "\n";

   $number = 0.07/0.005 - 14;
   print $number, "\n";

   __END__
      
   -1.77635683940025e-15
   1.77635683940025e-15

in the first case (the same one with which you have problems), the
actual value is just a little bit under 14, so int() chops it to
13.  the second case is a bit over 14, so int() chops it to 14.

you'll have to decide how you want to interpret the data...

good luck :)

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Tue, 30 Sep 1997 15:20:40 -0700
From: Sriram Srinivasan <sriram@weblogic.com>
To: Mark Worsdall <jaydee@worsdall.demon.co.uk>
Subject: Re: Recursive object reader
Message-Id: <34317B38.2527475C@weblogic.com>

use File::Find;
find (\&tell_time, "."); # Call tell_time for every file under 
                         # current directory

sub tell_time {
   return if (-d $_);  # Not if it is a directory
   print "$File::Find::Dir/$_  ==> ", (-M $_), "\n";
}



- Sriram 

_______________________________________________________________________
Principal Engineer      WebLogic, San Francisco        www.weblogic.com 
"Advanced Perl Programming" : http://www.ora.com/catalog/advperl/


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

Date: 30 Sep 1997 20:29:20 GMT
From: orwant@fahrenheit-451.media.mit.edu (Jon Orwant)
To: John Edwards <jde@tomedii.demon.co.uk>
Subject: Re: Regular Expressions: Negating bracketed strings
Message-Id: <ORWANT.97Sep30162920@fahrenheit-451.media.mit.edu>


John Edwards <jde@tomedii.demon.co.uk> writes:

   I've had a good look round the FAQs, but I can't work this one out.

   I want to find every occurrence of ABC _not_ followed by XX\d+ (e.g.
   ABCXX123 is fine, ABCXY123 is not).  I tried using this:

[snip]

   Does anyone know how to do it in a single expression?

(?! ) specifies a zero-width negative lookahead, e.g.

/ABC(?!XX\d+)/

-Jon

------------------------------------
Jon Orwant            http://tpj.com
Editor & Publisher, The Perl Journal


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

Date: Tue, 30 Sep 1997 22:44:18 GMT
From: simberg@interglobal.org (Rand Simberg)
Subject: Script can't find module!
Message-Id: <343e7f24.103045927@nntp.ix.netcom.com>

I'm trying to get a CGI script running along with Cybercash, which
uses a special module called CCLib.pm

The script was running with the old version of the cash register, but
since I upgraded, I get the following message when I try to compile
it:

bash$ perl -c shop.test
Can't locate CCLib.pm in @INC at shop.test line 488.
BEGIN failed--compilation aborted at shop.test line 488.

Here is the relevant part of the script.
*******************************************************
sub verify_card {  #1

# Require some libraries

push(@INC,'/usr/contrib/lib/perl5/i386-bsdos');

use CCLib qw(SetServer sendmserver);  (Line 488)
***********************************************************

Note that I added the push statement since I started having the
problem--the script used to run fine without it with the older version
of the cash register.  But adding does no good--I still get the
message above.

I know the module exists, because the cash register can use it.  I
found it as shown below.

bash$ locate CCLib.pm
/home/gen/members/giftsgalore/smps-2.1-bsdi/lib/perl-api/CCLib.pm
/usr/contrib/lib/perl5/i386-bsdos/CCLib.pm

The second one is the one in the perl library, which I am trying to
use.

Any ideas as to what the problem is?

************************************************************************
simberg.interglobal.org  * 310 372-7963 (CA) 307 739-1296 (Jackson Hole)  
interglobal space lines  * 307 733-1391 (Fax) http://www.interglobal.org 

"Extraordinary launch vehicles require extraordinary markets..."
Replace first . with @ to email me.  
Here's my email address for autospammers: postmaster@fbi.gov


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

Date: 1 Oct 1997 01:05:01 GMT
From: nharkins@also.hooked.net (Neil Harkins)
Subject: Re: Socket problems in 5.001, not in 5.003
Message-Id: <60s7jt$5tr$1@its.hooked.net>

Chuck May (may@ims.nci.nih.gov) wrote:
: I have a simple socket client which works fine under 5.003, but does not
: work under 5.001.  Does anyone know the differences?  Is there an older way
: to connect to a socket which is safe under both versions?  
:
: # set up host and port
: my $remote = 'localhost';
: my $port   = 2942;
: # set up and connect to the socket
: $iaddr = inet_aton($remote) or die "no host: $remote";
: $paddr = sockaddr_in($port, $iaddr);
: $proto = getprotobyname('tcp');
: socket(SOCK, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
: connect(SOCK, $paddr) or die "connect: $!";

I don't know where that script is failing, or whether this is true,
but I once came across the following comment in a perl script:

# sockaddr_in is undefined in Perl 5.001m

Which would answer your question. Try writing it without sockaddr_in(),
but rather: $paddr = pack('S n a4 x8',AF_INET,$port,$iaddr);

-Neil
_________________________________________________________________________
Neil Harkins                                            nharkins@well.com


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

Date: Tue, 30 Sep 1997 16:29:45 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Ernie Johnson <tcm@tcmd.com>
Subject: Re: splitting a tab delimited line
Message-Id: <Pine.GSO.3.96.970930162714.26927J-100000@usertest.teleport.com>

On Tue, 30 Sep 1997, Ernie Johnson wrote:

> Subject: splitting a tab delimited line

> I'd have no problem using split( ) but don't know what to tell split() to
> split on.

How about tabs? :-)  In the regular expression, you may either type \t to
mean a tab, or you can press the tab key once. That's gotta be easy. :-)
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/
              Ask me about Perl trainings!



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

Date: 30 Sep 1997 20:24:59 GMT
From: orwant@fahrenheit-451.media.mit.edu (Jon Orwant)
To: "Ernie Johnson" <tcm@tcmd.com>
Subject: Re: splitting a tab delimited line
Message-Id: <ORWANT.97Sep30162459@fahrenheit-451.media.mit.edu>


"Ernie Johnson" <tcm@tcmd.com> writes:

    Anyone have some thoughts on what I need to do to be able to split a tab
   delimited text file?

   It has a format of

   partnumber<tab>part description<tab>category<tab>stock<tab>price

   I'd have no problem using split( ) but don't know what to tell split() to
   split on.

\t, as in

split ( /\t/ , $line )

-Jon

------------------------------------
Jon Orwant            http://tpj.com
Editor & Publisher, The Perl Journal



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

Date: 30 Sep 1997 19:08:18 GMT
From: orwant@fahrenheit-451.media.mit.edu (Jon Orwant)
Subject: The Obfuscated Perl Contest Victors
Message-Id: <ORWANT.97Sep30150818@fahrenheit-451.media.mit.edu>


The 1st Annual Obfuscated Perl Contest, sponsored by The Perl Journal,
was a smashing success.  The judging committee has thrown in the
towel, and so the results are in.  The full writeup (including code)
is on the TPJ web site, http://tpj.com, but here are the winners:


                            MOST POWERFUL

1st place: Daniel Rinehart, self-uncompressing square root finder 
			    and custom bignum library

2nd place: Aaron Sherman, Perl-enabled spreadsheet

3rd place: Kalai Kandasamy, orbital fractal pixmap generator


                            MOST CREATIVE

1st place: Stephen McCamant, an 8-bit Apple ][-like virtual machine which 
			     runs opcodes that pretend to calculate pi

2nd place: Robert Klep, a curses-based graphics hack that rotates 
			the word 'Perl'

3rd place: David Powell, a curses-based real-time skiing game


                        BEST "THE PERL JOURNAL"

1st place: Joe Futrelle, a gorgeously formatted entry using the UNIX 
			 chargen service

2nd place: Jim Lawless, a self-uncompressing six-instruction virtual
		   	machine

3rd place: Frank Sheiness, a very alarming obfuscation 


                         BEST YEAR 2000 ERROR

First Place: Stephen McCamant


BEST OF SHOW: Stephen McCamant, for his Apple ][-like virtual machine 
in seven lines of Perl.


Congratulations to the winners, and thanks to all who entered!
The $100 cash prizes and trophies for the first place winners 
will be mailed shortly.

Special thanks to Felix "Robotron Poser" Gallo for organizing the contest.

-Jon

------------------------------------
Jon Orwant            http://tpj.com
Editor & Publisher, The Perl Journal


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

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

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