[9656] in Perl-Users-Digest
Perl-Users Digest, Issue: 3250 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 24 21:07:13 1998
Date: Fri, 24 Jul 98 18: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 Fri, 24 Jul 1998 Volume: 8 Number: 3250
Today's topics:
Re: A little enervous trouble (Craig Berry)
chomp or other command to eliminate LF and or CR from l (Mark Thompson)
Re: chomp or other command to eliminate LF and or CR fr <minich@globalnet.co.uk>
Re: chomp or other command to eliminate LF and or CR fr (Ronald J Kimball)
Re: chomp or other command to eliminate LF and or CR fr (Larry Rosler)
Re: chomp or other command to eliminate LF and or CR fr <minich@globalnet.co.uk>
Re: Date Question... (M.J.T. Guy)
Re: Date Question... (M.J.T. Guy)
Re: Date Question... (Ronald J Kimball)
Re: Detecting Countries (Andre L.)
Re: extracting price from string (again) (Ronald J Kimball)
Re: extracting price from string (Ronald J Kimball)
fork strangeness <goodaci@mbs.gov.on.ca>
help with array problem please. <rmillar@sric.sri.com>
Nice Numbers <rets01@telapex.com>
Re: parsing question <minich@globalnet.co.uk>
Re: parsing question (Ronald J Kimball)
Re: parsing question <minich@globalnet.co.uk>
Re: perl as pseudocode (Ronald J Kimball)
Re: reference passing seems odd (Andre L.)
Re: regexp question (Ronald J Kimball)
Re: replacing characters with other characters, using r (Ronald J Kimball)
Re: Rounding (Tad McClellan)
Same code, diff machines, diff results (Harshal S. Chhaya)
Re: Same code, diff machines, diff results (Gary L. Burnore)
Re: Same code, diff machines, diff results (Larry Rosler)
Re: spss file format (Jack Ostroff)
Re: Y2K problem in PERL with localtime() (Ronald J Kimball)
Re: Y2K problem in PERL with localtime() (Michael J Gebis)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 24 Jul 1998 23:37:06 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: A little enervous trouble
Message-Id: <6pb5r3$i7g$1@marina.cinenet.net>
I R A Aggie (fl_aggie@thepentagon.com) wrote:
: Modern versions of perl will permit you to use the qq() quoting method,
: which clears things up a bit:
:
: if ($fond1 eq qq("#ffffff") ) {
Or, since you don't need interpolation:
if ($fond1 eq '"#ffffff"') {
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Fri, 24 Jul 1998 23:58:11 GMT
From: mark-lists@webstylists.com (Mark Thompson)
Subject: chomp or other command to eliminate LF and or CR from lines
Message-Id: <35b91eba.4916101@news.supernews.com>
Hi,
I have a database in a tab delimited format that I process once a month and
everything goes smoothly as long as the person remembers to upload it as
ASCII. The problem is that half the time it's uploaded in ASCII and half the
time it's uploaded as Binary (it's done from a Win 95 machine).
I know chomp will only get rid of the EOL character that's in $/ which varies
from time to time. Is there an easy way to get rid of all LF and CR (and
regular spaces for that matter)? It can't get rid of tabs though (the last
field might be blank but I need to differentiate that condition from the
condition of not having the right number of fields.)
Thanks,
Mark Thompson
------------------------------
Date: Sat, 25 Jul 1998 01:05:53 +0100
From: "Martin" <minich@globalnet.co.uk>
Subject: Re: chomp or other command to eliminate LF and or CR from lines
Message-Id: <6pb7i7$80h$1@heliodor.xara.net>
>I have a database in a tab delimited format that I process once a month and
>everything goes smoothly as long as the person remembers to upload it as
>ASCII. The problem is that half the time it's uploaded in ASCII and half
the
>time it's uploaded as Binary (it's done from a Win 95 machine).
>
>I know chomp will only get rid of the EOL character that's in $/ which
varies
>from time to time. Is there an easy way to get rid of all LF and CR (and
>regular spaces for that matter)? It can't get rid of tabs though (the last
>field might be blank but I need to differentiate that condition from the
>condition of not having the right number of fields.)
How about $value =~ s/\r//g;
This will remove all carriage returns.
$value =~ s/\n//g;
will remove all Line feeds.
Do these parses on the code as it's coming in.
Martin
------------------------------
Date: Fri, 24 Jul 1998 20:26:59 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: chomp or other command to eliminate LF and or CR from lines
Message-Id: <1dcotws.sjz41h1vxnvxsN@bay2-88.quincy.ziplink.net>
Martin <minich@globalnet.co.uk> wrote:
> How about $value =~ s/\r//g;
> This will remove all carriage returns.
> $value =~ s/\n//g;
> will remove all Line feeds.
Those would definitely work, but I think this would be more efficient:
tr/\r\n//d;
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Fri, 24 Jul 1998 17:21:19 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: chomp or other command to eliminate LF and or CR from lines
Message-Id: <MPG.1022c4d980e2489b989786@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and copy mailed.]
In article <35b91eba.4916101@news.supernews.com> on Fri, 24 Jul 1998
23:58:11 GMT, Mark Thompson <mark-lists@webstylists.com> says...
...
> I know chomp will only get rid of the EOL character that's in $/ which varies
> from time to time. Is there an easy way to get rid of all LF and CR (and
> regular spaces for that matter)? It can't get rid of tabs though (the last
> field might be blank but I need to differentiate that condition from the
> condition of not having the right number of fields.)
Is this way easy enough:
tr/\n\r //d;
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sat, 25 Jul 1998 01:39:58 +0100
From: "Martin" <minich@globalnet.co.uk>
Subject: Re: chomp or other command to eliminate LF and or CR from lines
Message-Id: <6pb9hv$a3i$1@heliodor.xara.net>
>tr/\r\n//d;
::As homer would say:: Duh!
Why didn't I think of that? Must be too late <g> (1.40am in UK)
Martin
------------------------------
Date: 24 Jul 1998 23:14:54 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Date Question...
Message-Id: <6pb4he$2jh$1@pegasus.csx.cam.ac.uk>
Larry Rosler <lr@hpl.hp.com> wrote:
>Richard Kim <rkim@temple.edu> says...
>> My problem may be easy for some, but I am having difficulty finding the
>> answer. I am interested in getting yesterday's date using the localtime
>> function. Any other method would be nice, but I am not interested in
>> writing a long drawn out program just to extract yesterday's date.
>
>print scalar localtime(time - 24 * 60 * 60); # aka 86400 :-)
Wrong.
You may well get away with that in practice, if you only use it during
working hours. But not all days are 24 hours long. Think about
daylight saving changes.
Mike Guy
------------------------------
Date: 24 Jul 1998 23:16:19 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Date Question...
Message-Id: <6pb4k3$2kd$1@pegasus.csx.cam.ac.uk>
Brent Michalski <perlguy@technologist.com> wrote:
>Try this:
>
>$yesterday = localtime((time-86400));
>print $yesterday;
Wrong. Not all days have 24 hours.
Mike Guy
------------------------------
Date: Fri, 24 Jul 1998 20:20:02 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Date Question...
Message-Id: <1dcorsg.1jmge5eq79fv4N@bay2-88.quincy.ziplink.net>
Richard Kim <rkim@temple.edu> wrote:
> I am interested in getting yesterday's date using the localtime
> function.
www.dejanews.com
That question was already answered this week.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Fri, 24 Jul 1998 20:44:49 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: Detecting Countries
Message-Id: <alecler-2407982044490001@dialup-802.hip.cam.org>
In article <6pb16o$5ps$1@news1.epix.net>, "Chris" <nexes@epix.net> wrote:
> Hello,
>
> I have an encryption program that may not be exported except to Canada. It
> may only be sold in the US and Canada.
>
> I want the perl script to check if the user is the US or Canada, and if they
> are not - tell them that they must be from the US or Canada.
>
> So far I have written a perl script that checks by using
> $ENV{'HTTP_ACCEPT_LANGUAGE'}. I looks for a the match "en-us". Is this the
> best way to do this? Can someone point me to a list of
> 'HTTP_ACCEPT_LANGUAGE' so I can find all the ones for US and Canada?
Language does not seem to be a great criterium for determining the
country. For one thing, the official languages in Canada are Engligh *and*
French.
I don't know what you can do to ensure that you are selling to the right
country, except ask customers to be so kind as to tell you what country
they live in.
Andre
------------------------------
Date: Fri, 24 Jul 1998 20:20:04 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: extracting price from string (again)
Message-Id: <1dcos70.xrt7bx1h04e7vN@bay2-88.quincy.ziplink.net>
<dwiesel@my-dejanews.com> wrote:
> The string could either look like this
>
> $string = "add_|9163604728|author_name|book_tile||400.00|V";
>
> or like this
>
> $string = "add_|9163604728|author_name|book_tile|||400.00|V";
>
> I want $1 to be '400.00' or '400' (it doesn't matter)
>
> This is what I've tried
>
> $string =~ /\|{2,3}(.+?)\|V/;
> $string =~ /\|\|+(\d{3,4}).00\|V/; # Always ends with '.00'
>
> but it doesn't work.
In what way does it not work?
DB<1> $string = "add_|9163604728|author_name|book_tile|||400.00|V"
DB<2> x $string =~ /\|{2,3}(.+?)\|V/
0 400.00
DB<3> x $string =~ /\|\|+(\d{3,4}).00\|V/
0 400
DB<4> $string = "add_|9163604728|author_name|book_tile||400.00|V"
DB<5> x $string =~ /\|{2,3}(.+?)\|V/
0 400.00
DB<6> x $string =~ /\|\|+(\d{3,4}).00\|V/
0 400
DB<7>
As far as I can tell, both regexes work perfectly in both cases.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Fri, 24 Jul 1998 20:20:03 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: extracting price from string
Message-Id: <1dcorv1.sir51e4dwqkgN@bay2-88.quincy.ziplink.net>
- <root.noharvest.\@not_even\here.com> wrote:
> $string =~ /\|{2,3}(.*)\|+/;
>
> now, if it sees two or three pipes, it'll pick up everything between
> the 2nd or 3rd pipe and the next pipe
I think you meant to say, it'll pick up everything between the 2nd or
3rd pipe and the *last* pipe.
$string =~ /\|{2,3}([^|]*)\|+/;
would do what you intended.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Fri, 24 Jul 1998 19:49:25 -0400
From: Ian Goodacre <goodaci@mbs.gov.on.ca>
Subject: fork strangeness
Message-Id: <35B91D85.9A367625@mbs.gov.on.ca>
I am running perl5.00404 on Digital Unix 4.0b and the strangest thing is
happening:
My program is:
#!/usr/local/bin/perl5.00404 -w
#
$| = 1;
print "start $$\n";
unless(open(SRC,"<./input")) {
die "./input: $!";
}
$SIG{CHLD} = sub {
wait;
};
while(defined($record = <SRC>)) {
print "$$: $record";
unless(defined($pid = fork)) { die "fork: $!"; }
if($pid) { # parent
print "$$ spawned $pid\n";
} else { # child
print "child $$\n";
exit;
}
}
The input file is:
line 1
line 2
line 3
line 4
line 5
line 6
line 7
And I get output like:
start 6962
6962: line 1
child 26309
6962 spawned 26309
6962: line 2
6962 spawned 17806
6962: line 3
6962 spawned 4690
6962: line 4
6962 spawned 2063
6962: line 5
child 17806
child 4690
child 2063
child 23037
6962 spawned 23037
6962: line 6
6962 spawned 593
6962: line 7
6962 spawned 29545
6962: line 2
child 593
child 29545
child 21474
6962 spawned 21474
6962: line 3
6962 spawned 8066
6962: line 4
6962 spawned 15005
6962: line 5
child 8066
child 15005
child 27111
6962 spawned 27111
6962: line 6
6962 spawned 273
6962: line 7
6962 spawned 23944
6962: line 2
child 273
child 23944
child 28223
6962 spawned 28223
6962: line 3
6962 spawned 5230
6962: line 4
And so on until I run out of processes (per user process limit).
It's probably something silly, but I can't see what the problem is. I
expect the program to read each line in the input file once only. Why
does it keep jumping back to the second line?
Any help would be much appreciated.
Thanks,
Ian Goodacre
Ian.Goodacre@mbs.gov.on.ca
------------------------------
Date: Fri, 24 Jul 1998 17:08:10 -0700
From: Rick Millar <rmillar@sric.sri.com>
Subject: help with array problem please.
Message-Id: <35B921EA.BB0661A7@sric.sri.com>
I am having a heck of a time getting my script to successfully call the
NET::LDAP::Entry->modify method. I can bind to the LDAP directory and
search for a user no problem, but trying to update the values of
attributes of an entry yields the following error:
"not an array reference at /usr/local/lib/perl5/site_perl/net/ldap.pm
line 312."
I did my best using the ref operator to figure out what was going on
and, to the best of my limited ability, it seems that the method call is
sending a hash to ldap.pm and the module was expecting an scalar array
instead of the associative array.
I have included snippets of myscript below as well as a snippet from
LDAP.pm that contains line 312.
Can any of you help me figure out what is going wrong? Any help would
be greatly appreciated. Is there a way to modify my code so that an
array is sent?
I am running on Solaris 5.x
The Directory Server is Netscape's Directory Server 3.x
Perl is version 5.004
LDAP.pm is version perl-ldap-0.06 with Convert-BER-1.15
=============
my script
=============
...snip
>use Net::LDAP;
>$ldap = new Net::LDAP("$server_host");
>
> #Bind to the Directory Server.
> # $o resolves to "o=Int Info Int Inst"
>
>
> $ldap->ldapbind("$server_host",
> '-dn' => "uid=$remote_user, $o",
> '-password' => "$old_passwd"
> ) or die $@;
>
> #Search Directory for user's entry.
>
> $msg = $ldap->search ('-base' => "$o",
> '-filter' => "uid=$remote_user",
> '-attrs' => ['password']
> ) or die $@;
>
> #Update user's entry with new password.
>
> $msg2 = $ldap->modify (-dn => "uid=$remote_user,$o",
> -replace => { password => [$new_passwd] } ### I think that this
is
> ) or die $@;
# where the problem is.
snip...
============
LDAP.pm
============
...snip
>sub modify {
> my $ldap = shift;
> my $arg = &_options;
> my $dn = $arg->{'-dn'};
>
> my @ops;
> my $i = 0;
> my $op;
>
> foreach $op (qw(-add -delete -replace)) {
> next unless exists $arg->{$op};
> my $k = 0;
> while($k < @{$arg->{$op}}) { # Line 312!!!
> my $attr = ${$arg->{$op}}[$k++];
> my $val = ${$arg->{$op}}[$k++];
> push @ops, [ $i, $attr, $val ];
> }
snip...
Sincerely,
Rick Millar
------------------------------
Date: Fri, 24 Jul 1998 19:00:38 -0500
From: "Kenneth A. Holm III" <rets01@telapex.com>
Subject: Nice Numbers
Message-Id: <35B92026.D5A0F141@telapex.com>
Just a thought. Most comments appreciated:
#################
sub nice_number {
my $number = shift; # number to be nice-ified
my $places = shift; # places to round to
Error ("nice_number",
"No value passed [NUMBER]",
1) unless $number;
$places = $places || 2; # defaults to 2 places (US currency)
my $remain = 1 / ( 10 ** int( $places + 1 ) );
$remain *= 5;
$number += $remain;
$number = int ($number * (10 ** int( $places ) ) );
$number = $number / (10 ** int( $places ) );
($integer, $decimal) = split(/\./, $number);
$decimal .= "0" x $places;
$decimal = substr($decimal, 0, $places);
$number = join ".", $integer, $decimal;
return $number;
}
This has a call to my own error function. It automatically rounds up to
the $places decimal places.
-K
------------------------------
Date: Sat, 25 Jul 1998 00:48:28 +0100
From: "Martin" <minich@globalnet.co.uk>
Subject: Re: parsing question
Message-Id: <6pb6hd$6t4$1@heliodor.xara.net>
> Both are reported as equal.
>
> Executes fine with or without the double quotes.
What about:
$num = 123/3; # number
$nummy = "123/3"; # string
print "ha\n" if $num eq $nummy;
print "ho\n" if $num == $nummy;
Exit(0);
$num equates to 41 but $nummy remains as 123/3
so the "s are crucial.
Martin
------------------------------
Date: Fri, 24 Jul 1998 20:27:02 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: parsing question
Message-Id: <1dcou09.2xwi8h1c2wm5xN@bay2-88.quincy.ziplink.net>
Martin <minich@globalnet.co.uk> wrote:
> > Both are reported as equal.
> >
> > Executes fine with or without the double quotes.
>
>
> What about:
>
> $num = 123/3; # number
> $nummy = "123/3"; # string
>
> print "ha\n" if $num eq $nummy;
> print "ho\n" if $num == $nummy;
>
> Exit(0);
>
> $num equates to 41 but $nummy remains as 123/3
> so the "s are crucial.
Which has nothing to do with the original point. Assigning a variable
to another variable by putting it in quotes is superfluous, as in:
$string = "$string2";
That's just silly. You should do
$string = $string2;
instead.
But maybe you're just being purposely obtuse?
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Sat, 25 Jul 1998 01:42:03 +0100
From: "Martin" <minich@globalnet.co.uk>
Subject: Re: parsing question
Message-Id: <6pb9m0$a7e$1@heliodor.xara.net>
>But maybe you're just being purposely obtuse?
How acute <g>
OK, so it strayed a bit from the original point and I guess I
should probably reread perlstyle but the program WORKED!
Martin
------------------------------
Date: Fri, 24 Jul 1998 20:20:05 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: perl as pseudocode
Message-Id: <1dcot41.ljluy310g9k6sN@bay2-88.quincy.ziplink.net>
Adam Atkinson <ghira@mistral.co.uk> wrote:
> while ($j!=undef) {
This is exactly equivalent to ($j != 0), except one of them will give a
warning under -w, and one won't. I'll let you figure out which is
which. ;-)
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Fri, 24 Jul 1998 20:15:24 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: reference passing seems odd
Message-Id: <alecler-2407982015240001@dialup-802.hip.cam.org>
You have made the script work, but by accident it seems. It's important
you understand what's going on.
Look at the sub without the my() statement:
sub foo {
$pointer=@_;
print "@$pointer\n";
}
In this case, $pointer is _not_ a proper reference. It is just the value
1, which is the number of elements in array @_. That's what happens when
you assign an array to a scalar.
In the case where you wrote my($pointer) = @_, you decided to use
parentheses to hold the argument to my(). By so doing, you correctly
assigned @_ to a list containing one element: ($pointer).
To sum up:
$scalar = @array; # $scalar is the nb of elements in @array
($scalar1, $scalar2) = @array; # assignment to a list
($scalar) = @array; # also an assignment to a list
See the difference?
To answer your question, the my() is not needed, but it's always a good
idea to use it anyway.
Tip: you could have written:
sub foo {
$pointer = shift;
print "@$pointer\n";
}
Andre
========================
In article <01bdb72e$0c54bae0$c1620c8a@lnxcompaq.lexis-nexis.com>, "Sabre
Taylor" <nonspammers.cut.after.the.period.hot_redox@hotmail.com> wrote:
> Got some odd results (at least to me). Can anybody explain
> why the "my" is needed?
>
> % quick <- running my script without the "my"
>
> % quick <- after "my" added
> jan feb mar
> %
>
>
> Sabre
>
>
> -------------here's the script-------------
>
> #!/usr/local/bin/perl5
>
> @barney= qw (
> jan
> feb
> mar
> );
>
> &foo (\@barney);
>
> sub foo {
> my($pointer)=@_; # first run, this line was $pointer=@_;
> print "@$pointer\n";
> }
------------------------------
Date: Fri, 24 Jul 1998 20:20:06 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: regexp question
Message-Id: <1dcota8.gv7u8919h1iebN@bay2-88.quincy.ziplink.net>
William Wueppelmann <william@host.ott.igs.net> wrote:
> : Why doesn't this expression
> : m/<font.*?\s(SIZE=.*?)[>\s]/
>
> : match this string?
> : <font COLOR="#006600" SIZE="+1">
>
> Is '*?' supposed do something? (It may, but it seems to me like an error.)
Hopefully, it will make you read the documentation for perlre, since it
seems to me like you are unfamiliar with perl's regular expressions.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Fri, 24 Jul 1998 20:20:07 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: replacing characters with other characters, using regexp
Message-Id: <1dcotcj.vj8ecgnrtwt1N@bay2-88.quincy.ziplink.net>
Bjorn Malmberg <news@NOSPAM.gb-design.com> wrote:
> and I have to search for the funny characters and replace them ..
You probably want to use tr///.
tr/edv/aao/;
It might be safer to write it like this:
tr/\x8C\x8A\x9A/aao/;
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Fri, 24 Jul 1998 18:42:21 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Rounding
Message-Id: <t46bp6.a6p.ln@localhost>
Ollie Cook (oliver.cook@bigfoot.com) wrote:
: I've just written a Web Cart perl script for a client and I'm now
: stuck at what seems the simplest part of the script. How can I round
: the amount to pay to 2 dp? Current the value in the scalar is, say,
: 1839.12864 , due to complex VAT arithmetic. I'd like it to round to
: 1839.13. How can I achieve this?
You can achieve it as described in the Perl FAQ, part 4:
"Does perl have a round function? What about ceil() and floor()?"
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 24 Jul 1998 23:27:33 GMT
From: chhahar@charlie.cns.iit.edu (Harshal S. Chhaya)
Subject: Same code, diff machines, diff results
Message-Id: <6pb595$7r4$1@condor.cns.iit.edu>
Hi,
I am completely stumped by this one. I have a script running on
two different machines and perl code that seems to work just great one
one setup works in strange ways on the other machine.
for eg. to change the time zone in a script, I modify the TZ env. var. The
following snippet shows the two times:
$date = `/bin/date`;
$ENV{"TZ"} = "Asia/Calcutta";
$date1 = `/bin/date`;
print $date, $date1;
On machine1 (FreeBSD, perl 5.004_01) this prints:
Fri Jul 24 19:18:13 EDT 1998
Sat Jul 25 04:48:13 IST 1998
(as expected)
and on the other machine (Solaris 2.5, perl 5.003) it prints:
Fri Jul 24 18:17:12 CDT 1998
Fri Jul 24 23:17:12 Asia/Calcutta 1998
Anyone know why the results are different? Are the diff versions the reason
for this behavior?
Any enlightenment much appreciated...
Thanks,
- 'shal
hchhaya@pair.com
------------------------------
Date: Fri, 24 Jul 1998 23:40:02 GMT
From: gburnore@databasix.com (Gary L. Burnore)
Subject: Re: Same code, diff machines, diff results
Message-Id: <35b91b16.12972891@nntpd.databasix.com>
On 24 Jul 1998 23:27:33 GMT, in article <6pb595$7r4$1@condor.cns.iit.edu>,
chhahar@charlie.cns.iit.edu (Harshal S. Chhaya) wrote:
>On machine1 (FreeBSD, perl 5.004_01) this prints:
>and on the other machine (Solaris 2.5, perl 5.003)
DUH!!! The difference isn't the machine, it's the perl.
--
for i in databasix primenet ; do ; gburnore@$i ; done
---------------------------------------------------------------------------
How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore | ][3:]3^3:]33][:]3^3:]3]3^3:]3]][3
| ][3:]3^3:]33][:]3^3:]3]3^3:]3]][3
DOH! | ][3:]3^3:]33][:]3^3:]3]3^3:]3]][3
| ][3 3 4 1 4 2 ]3^3 6 9 0 6 9 ][3
spamgard(tm): zamboni | Official Proof of Purchase
===========================================================================
------------------------------
Date: Fri, 24 Jul 1998 17:18:57 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Same code, diff machines, diff results
Message-Id: <MPG.1022c44a29403831989785@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and copy mailed.]
In article <6pb595$7r4$1@condor.cns.iit.edu> on 24 Jul 1998 23:27:33 GMT,
Harshal S. Chhaya <chhahar@charlie.cns.iit.edu> says...
...
> $date = `/bin/date`;
> $ENV{"TZ"} = "Asia/Calcutta";
> $date1 = `/bin/date`;
> print $date, $date1;
>
> On machine1 (FreeBSD, perl 5.004_01) this prints:
> Fri Jul 24 19:18:13 EDT 1998
> Sat Jul 25 04:48:13 IST 1998
>
> (as expected)
>
> and on the other machine (Solaris 2.5, perl 5.003) it prints:
> Fri Jul 24 18:17:12 CDT 1998
> Fri Jul 24 23:17:12 Asia/Calcutta 1998
>
>
> Anyone know why the results are different? Are the diff versions the reason
> for this behavior?
There is no Perl issue here whatsoever. Perl has launched the commands,
set the environment variable, and returned the results.
All of them seem consistent except the last, which indicates that the
date(1) command on that machine doesn't recognize the locution
'Asia/Calcutta' for TZ, and has simply reported UTC (GMT). This is an
implementation issue in the Unix command.
[But I learned that some implementations accept descriptive strings
for TZ instead of, e.g., PST8PDT. That was a surprise in itself.]
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 24 Jul 1998 17:14:34 GMT
From: jack_h_ostroff@groton.pfizer.com (Jack Ostroff)
To: "S.R.M. Walsh" <u7srmw@csc.liv.ac.uk>
Subject: Re: spss file format
Message-Id: <6pafdq$a1h1@mascagni.pfizer.com>
In article <35B88413.2F01@csc.liv.ac.uk>, "S.R.M. Walsh" <u7srmw@csc.liv.ac.uk> writes:
> I am a computer science student at the University of Liverpool (U.K)
> and I am currently engaged in a project involving spss.
> I have created web pages that include an online form which is then
> processed by a cgi program (written in Perl5). The data is saved in
> files using name=value,(value),etc.. pairs. I now wish to write another
> perl program that will read in each of these files and convert them into
> spss files. However I do not know what has to be included in these
> files and the exact syntax of the contents. I would be very grateful if
> anyone can point me to relevant sources of information.
It seems you are asking about the format of spss files. We do this sort of
thing with SAS frequently - and the easy way is write the data as plain
ascii, and then have your spss program read it in.
If you really want to use perl to create spss data files, then you need
the internal format of such, which may well be proprietary. In any case,
you should be asking in an spss group, not a perl group, and certainly not
in the perl modules or tk groups. I'll leave teh pl1 folks to flame for
themselves. Follow-ups set to clpm only.
------------------------------
Date: Fri, 24 Jul 1998 20:20:08 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Y2K problem in PERL with localtime()
Message-Id: <1dcotlk.or14k61rsd44bN@bay2-88.quincy.ziplink.net>
Erdem Ozsaruhan <EOZSARUH@nsf.gov> wrote:
> When I run the following perl program:
>
> #! /usr/local/bin/perl
>
> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
> chop($date = sprintf ("%02d-%02d-%02d\n",$mon+1,$mday,$year));
>
> print "Date: $date\n";
> exit;
>
>
> I get:
>
> Date: 02-29-100
And there is a problem because...?
> When I run a date command from the command line on each platform I ran
> the script, I get:
>
> # date +"%m-%d-%y"
> 02-29-00
Hmm... And perl is the one with the Y2K problem??? (Is that 2000 or
1900?)
> The date on all my machines is "Tue Feb 29 18:14:28 EST 2000".
>
> Any ideas?
Yes. Read the documentation for localtime, or go to dejanews and read
the responses to the previous 100 times this question was asked this
month.
Idiot.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 25 Jul 1998 00:23:32 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: Y2K problem in PERL with localtime()
Message-Id: <6pb8i4$2ji@mozo.cc.purdue.edu>
Keywords: y2k localtime()
EOZSARUH@nsf.gov (Erdem Ozsaruhan) writes:
}When I run the following perl program:
}#! /usr/local/bin/perl
} ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
} chop($date = sprintf ("%02d-%02d-%02d\n",$mon+1,$mday,$year));
} print "Date: $date\n";
}I get:
}Date: 02-29-100
}When I run a date command from the command line on each platform I ran
}the script, I get:
}# date +"%m-%d-%y"
}02-29-00
}The date on all my machines is "Tue Feb 29 18:14:28 EST 2000".
Waitasecond. I'm admittedly confused here, but one of the
possiblities is that you're concerned because perl DOES NOT return
only two-digits for the year.
I'm not sure if I should laugh or cry.
--
Mike Gebis gebis@ecn.purdue.edu mgebis@eternal.net
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 3250
**************************************