[28443] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9807 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 5 14:06:05 2006

Date: Thu, 5 Oct 2006 11:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 5 Oct 2006     Volume: 10 Number: 9807

Today's topics:
        Archive::Zip - zip file has "invalid" format <lev.weissman@creo.com>
    Re: Archive::Zip - zip file has "invalid" format (reading news)
        Can't call method "mail" - w3mail/cascade soft broken <don@lizardhill.com>
    Re: Can't call method "mail" - w3mail/cascade soft brok <tadmc@augustmail.com>
        Find First Date of A Calendar Month\Year idgarad@gmail.com
    Re: Find First Date of A Calendar Month\Year <mritty@gmail.com>
    Re: Find First Date of A Calendar Month\Year <tadmc@augustmail.com>
        Hard or Easy? To find string, then grab criterion match samiam@mytrashmail.com
    Re: Hard or Easy? To find string, then grab criterion m usenet@DavidFilmer.com
    Re: LWP and 302 redirects <glex_no-spam@qwest-spam-no.invalid>
    Re: LWP and Unicode <dale.gerdemann@googlemail.com>
    Re: LWP and Unicode (reading news)
    Re: Please help me pass an array from VBA to Perl and p david.f.jenkins@usa.net
    Re: Please help me pass an array from VBA to Perl and p <rvtol+news@isolution.nl>
        Problems at writing multiple files vladimir.giron@gmail.com
    Re: question on File::Tail <tzz@lifelogs.com>
        Regarding numeric literals chaitask@yahoo.com
    Re: Regarding numeric literals <mritty@gmail.com>
    Re: Regarding numeric literals <peace.is.our.profession@gmx.de>
    Re: Regarding numeric literals <mritty@gmail.com>
    Re: Regarding numeric literals <tzz@lifelogs.com>
    Re: Regarding numeric literals <mritty@gmail.com>
    Re: Regarding numeric literals <wahab@chemie.uni-halle.de>
    Re: Regarding numeric literals <mritty@gmail.com>
    Re: Regarding numeric literals <wahab@chemie.uni-halle.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 5 Oct 2006 06:41:46 -0700
From: "MoshiachNow" <lev.weissman@creo.com>
Subject: Archive::Zip - zip file has "invalid" format
Message-Id: <1160055706.498790.159830@i3g2000cwc.googlegroups.com>

HI,

Files that I create using Archive::Zip work on some windows
stations,while on some I'm unable to open them neither with unzip nor
with WinZip - telling me the format is wrong...
What can be the problem ?
Thanks



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

Date: Thu, 05 Oct 2006 14:25:39 GMT
From: "Mumia W. (reading news)" <paduille.4058.mumia.w@earthlink.net>
Subject: Re: Archive::Zip - zip file has "invalid" format
Message-Id: <DB8Vg.10339$UG4.9911@newsread2.news.pas.earthlink.net>

On 10/05/2006 08:41 AM, MoshiachNow wrote:
> HI,
> 
> Files that I create using Archive::Zip work on some windows
> stations,while on some I'm unable to open them neither with unzip nor
> with WinZip - telling me the format is wrong...
> What can be the problem ?
> Thanks
> 

Did you read Ilya Zakharevich's message?

I'm just guessing here, but according to his message, zip files cannot 
contain files larger than 4GB (paraphrased and interpreted), so any such 
zip files you have created were automatically corrupted.


-- 
paduille.4058.mumia.w@earthlink.net
Posting Guidelines for comp.lang.perl.misc:
http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



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

Date: 5 Oct 2006 09:26:29 -0700
From: "Don O'Neil" <don@lizardhill.com>
Subject: Can't call method "mail" - w3mail/cascade soft broken
Message-Id: <1160065589.157221.325180@h48g2000cwc.googlegroups.com>

Until last night, my CascadeSoft w3mail webmail program was working
perfectly, now this morning, after a server crash, I'm getting the
error "The SMTP server responded: Can't call method "mail" on an
undefined value at
/var/shc/servers/lizardhill.com/root/webmail/cgi/sendmessage.cgi line
179" when I try to send an email message.... Anyone have any ideas what
could be going on? I reinstalled Net::Mail, but that didn't make a
difference.



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

Date: Thu, 5 Oct 2006 12:18:05 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Can't call method "mail" - w3mail/cascade soft broken
Message-Id: <slrneiafid.8tm.tadmc@magna.augustmail.com>

Don O'Neil <don@lizardhill.com> wrote:

> Until last night, my CascadeSoft w3mail webmail program was working
> perfectly, now this morning, after a server crash, 


Have you determined what caused the crash?

A common cause of server crashing is being cracked, and Googling
shows that this program is an open invitation to crackers...

Have you contacted the author of the program for support?


> I'm getting the
> error "The SMTP server responded: Can't call method "mail" on an
> undefined value at
> /var/shc/servers/lizardhill.com/root/webmail/cgi/sendmessage.cgi line
> 179" when I try to send an email message.... Anyone have any ideas what
> could be going on? 


Maybe a bad guy is exploiting your insecure site.

Apart from that, the problem is that you are attempting to call
a method on an undefined value at line 179.

Go look at that line and see what values might be undefined, then
trace them back to figure out where they are getting that value.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 5 Oct 2006 09:35:43 -0700
From: idgarad@gmail.com
Subject: Find First Date of A Calendar Month\Year
Message-Id: <1160066143.115617.287190@i3g2000cwc.googlegroups.com>

Very simple in description but tricky to implement so far. What I am
after is given a year, say 2006, what is the First sunday's date on the
calendar (For January). For instance in 2006 this would be january 1st
2006. But in 2005 it would be Dec 26th 2004. Is there a simple module
for getting this kind of date?

Ken



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

Date: 5 Oct 2006 10:06:13 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Find First Date of A Calendar Month\Year
Message-Id: <1160067973.122025.248900@h48g2000cwc.googlegroups.com>

idgarad@gmail.com wrote:
> Very simple in description but tricky to implement so far. What I am
> after is given a year, say 2006, what is the First sunday's date on the
> calendar (For January). For instance in 2006 this would be january 1st
> 2006. But in 2005 it would be Dec 26th 2004. Is there a simple module
> for getting this kind of date?

I'm sure one of the hundreds of Date* modules available on CPAN can do
this, but if you don't feel like installing a non-standard module just
for this purpose, this seems to work for me:

#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw/strftime/;
use Time::Local;

for my $y (2004, 2005, 2006) {
  my $first = first_sunday($y);
  print "$y:  ", strftime("%C", localtime($first)), "\n";
}

sub first_sunday {
  my $y = shift;
  my $dow = strftime("%w", 0,0,0,1,0,$y-1900);
  my $time = timelocal(0,0,0,1,0,$y-1900);
  return $time - ($dow * 24 * 60 * 60);
}
__END__
2004:  Sun Dec 28 00:00:00 EST 2003
2005:  Sun Dec 26 00:00:00 EST 2004
2006:  Sun Jan  1 00:00:00 EST 2006

Basically, find the day of the week of the first of the year (as an
integer from 0 - 6).  Then take that date, and subtract that number of
days from it.

Paul Lalli



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

Date: Thu, 5 Oct 2006 12:30:50 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Find First Date of A Calendar Month\Year
Message-Id: <slrneiagaa.8tm.tadmc@magna.augustmail.com>

idgarad@gmail.com <idgarad@gmail.com> wrote:
> Very simple in description but tricky to implement so far. What I am
> after is given a year, say 2006, what is the First sunday's date on the
> calendar (For January). For instance in 2006 this would be january 1st
> 2006. But in 2005 it would be Dec 26th 2004. Is there a simple module
> for getting this kind of date?


-----------------------------
#!/usr/bin/perl
use warnings;
use strict;
use Date::Calc qw/ Nth_Weekday_of_Month_Year /;

my $year = 2006;
my $first_Sunday = sprintf '%4d-%02d-%02d', 
                           Nth_Weekday_of_Month_Year($year,1,7,1);

print "the first Sunday of $year is $first_Sunday\n";
-----------------------------


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 5 Oct 2006 10:27:55 -0700
From: samiam@mytrashmail.com
Subject: Hard or Easy? To find string, then grab criterion matched lines above and below?
Message-Id: <1160069275.311891.244120@i42g2000cwa.googlegroups.com>



Hello,

I know this is a trivial parse / grep job for any Perl rake worth his
salt, but does anyone have guidance on how this Perl newbie might pull
a string from one file and use this string to pull the lines in another
file out, and also pull the first line before (matching criteria) and
the first line after (matching criteria.)

I have described this in detail below.

At first I thought to use VBScript, but then I realized that Perl is
portable, doesn't necessarily have to  be installed on the server, and
probably has MUCH better string processing power than VBScript.  I also
considered grep, but still thought I could reuse the Perl solution in
more places.

Any input is GREATLY appreciated!

L,
S

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

Summary: I need to find CSR numbers in FILE-A that map to registry key
entries in FILE-B, and report the pertinent surrounding info.

Detail:

I am looking to:

a.) find the lines in *.aud files with "Fail" in them
b.) Extract the Section number from the beginning of that same line.
I'll call this Section number a "CSR #"

Then use that CSR# to pull from a 2nd *.dsc file :

a.) Pull first line with CSR#
b.) Pull the first line above it with anything between two # signs,
which are section titles like this #Windows Messenger#
c.) Pull the SECOND registry key instance that is on any line below the
line with the CSR #
d.) Out put this data into a CSV file like this:

CSR#, 		Section Title, 			Registry Key

5.6.1.7.1, 	Windows Messenger Check, 	"HLM,
SOFTWARE\Policies\Microsoft\Messenger\Client,PreventRun,1,INTEGER"

Since there seem to be commas in the registry key entry, I suppose my
csv file would need to be delimited by another delimiter recognized by
Excel, which is where I ultimately want to display my data.

Below are two data samples like the data from which I will be culling.
The first sample is from a *.aud audit file.
The second is from the single DSC program file that either analyzes the
registry or can also write and change it.

Basically, I need to report the changes that our program will be making
to the registry. The audit files show the fail lines, which are lines
of a servers registry that needs to be brought into compliance.

server.aud file (audit file)
5.2.4~Local Printers Shared~NA~PASS~NA
5.8.1~FTP Server Installed~NA~PASS~NA
5.6.2~POSIX Subsystem Installed~PASS~PASS~
5.2.2~Posix Subsystem File Components - Posix.exe Not Found~NA~PASS~NA
5.2.2~Posix Subsystem File Components - Psxss.exe Not Found~NA~PASS~NA
5.2.2~Posix Subsystem File Components - Psxdll.dll Not Found~NA~PASS~NA
5.6.1.1~NetMeeting Disable Remote Desktop Sharing~FAIL~FAIL~
5.6.1.2~IE Security Zones are Local Only~FAIL~FAIL~
5.6.1.2.2~Allow User to Change IE Sec Policy~FAIL~FAIL~
5.6.1.2.3~IE Security Zones Map Editing~FAIL~FAIL~
5.6.1.2.4~IE Proxy Settings Set Per User~FAIL~FAIL~
5.6.1.2.5~IE Automatic Installs Disabled~FAIL~FAIL~
5.6.1.2.6~IE Software Update Check~FAIL~FAIL~

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

analyze.dsc (script for analyzing/writing to registry)

# Windows Messenger #
dialog set,text1,"5.6.1.7.1 Windows Messenger Check"
dialog set,text2,"5.6.1.7.1 Do Not Allow Windows Messenger to be Run"
%%before =
@REGREAD(HLM,SOFTWARE\Policies\Microsoft\Messenger\Client,PreventRun,)
REGISTRY
WRITE,HLM,SOFTWARE\Policies\Microsoft\Messenger\Client,PreventRun,1,INTEGER



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

Date: 5 Oct 2006 10:34:15 -0700
From: usenet@DavidFilmer.com
Subject: Re: Hard or Easy? To find string, then grab criterion matched lines above and below?
Message-Id: <1160069655.420130.7860@i3g2000cwc.googlegroups.com>

sam...@mytrashmail.com wrote:

[snip multipost]

Please don't multipost. It's rude.

-- 
David Filmer (http://DavidFilmer.com)



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

Date: Thu, 05 Oct 2006 12:52:41 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: LWP and 302 redirects
Message-Id: <452545e4$0$25781$815e3792@news.qwest.net>

IanW wrote:
>  Hi
> 
> I'm having trouble with LWP and 302 redirects. I found the 
> "$ua->requests_redirectable" parameter in the LWP documentation but it still 
> doesn't work. Here's my code:

Define "doesn't work".  What is returned for the response or error?
> 
>     use LWP::UserAgent;
>     my $ua = new LWP::UserAgent;
>     push @{ $ua->requests_redirectable },'POST';
>     my $request = HTTP::Request->new(POST => 'http://blah.blah');
>     $request->content_type('application/x-www-form-urlencoded');
>     $request->content("LOGIN1=$action&Y=$Y&p=$P");
>     my $resp = $ua->request($request);
> 
> Any ideas what I'm doing wrong?
> 
> Ian 
> 
> 


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

Date: 5 Oct 2006 08:10:14 -0700
From: "Dale" <dale.gerdemann@googlemail.com>
Subject: Re: LWP and Unicode
Message-Id: <1160061014.149361.243900@b28g2000cwb.googlegroups.com>

How to read a web page containing partly utf8 and partly
percent-encoded utf8.

Assumption: We want, for whatever reason, to have "use encoding
'utf8'". It's not clear that this pragma helps, but this is the 21st
century and we just want to use Unicode.

Problem: The problem occurs in an unexpected place. Escape::unescape
does more than just decode the percent encoding. This doesn't seem to
be documented.

Alternatives: The obvious alternative is to parse more carefully and
apply the appropriate encoding/unencoding to the appropriate parts of
the document.

Questions: I still don't think I understand the difference between the
runtime switch -CIO and "use encoding 'utf8'". Okay, I know that
'encoding' allows you to put Unicode into your program. But beyond
that, there seems to be some difference in what happens with IO.


#!/afs/sfs/lehre/dg/perl-5.8.8/bin/perl

use encoding 'utf8';
use LWP;
use Encode qw(encode decode is_utf8);
use URI::Escape qw(uri_unescape);

my $browser = LWP::UserAgent->new;

## Tiny test web-page. Included just the line "h a h", where the h's
## are upside down (actually Cyrillic).
my $url
  =
'http://www.sfs.uni-tuebingen.de/iscl/Kursmaterialien/Gerdemann/foo.html';

my $response = $browser->get(encode("utf8", $url));

# raw_content is a byte sequence, containing some utf8 encoded bits
# and some percent encoded utf8 encoded bits
my $raw_content       = $response->content;

# $encoded_content adds a double utf8 encoding to the already utf8 bits
of
# raw_content
my $encoded_content   = encode("utf8", $raw_content);

# $unescaped_content is different from $encoded_content in two
respects.
# 1. The percent-encoded parts of $encoded_content are decoded into
utf8
# 2. The doubly utf-encoded bits of $encoded_content lose a layer of
utf
#    encoding. WARNING: This only happens if there are actually some
percent
#    encoded bits that get decoded. Is this documented somewhere???
my $unescaped_content = uri_unescape($encoded_content);

# After the previous step, everything was utf8, so now finally we turn
# it into Unicode.
my $decoded_content   = decode("utf8", $unescaped_content);

print "$decoded_content\n";

# Test: change $decoded_content to the level you want to see.
# while ($decoded_content =~ m/(.)/g) {
#  print ord $1, "\n";
# }



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

Date: Thu, 05 Oct 2006 16:37:58 GMT
From: "Mumia W. (reading news)" <paduille.4058.mumia.w@earthlink.net>
Subject: Re: LWP and Unicode
Message-Id: <GxaVg.3516$Lv3.2436@newsread1.news.pas.earthlink.net>

On 10/05/2006 10:10 AM, Dale wrote:
> How to read a web page containing partly utf8 and partly
> percent-encoded utf8.
> 
> [...]
> 'http://www.sfs.uni-tuebingen.de/iscl/Kursmaterialien/Gerdemann/foo.html';
> [...]

403 Forbidden


-- 
paduille.4058.mumia.w@earthlink.net
Posting Guidelines for comp.lang.perl.misc:
http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: 5 Oct 2006 07:46:06 -0700
From: david.f.jenkins@usa.net
Subject: Re: Please help me pass an array from VBA to Perl and populate it. Newbie at wits' end!
Message-Id: <1160059566.830414.300180@m73g2000cwd.googlegroups.com>

I'm aware of that.

I have created the Perl ActiveX control I need, and can safely travel
back and forth from VBA to Perl.  What I *need* is help on the
mechanics of getting String array information back from the called
control.  I am unable to figure out how to do this either through a
passed argument, or through VBA access of the control's poperties.

Right now, I'm pretty much dead in the water.  I just can't believe
that this is not a problem that myriads of others have already faced
and overcome.

Mark Clements wrote:
> Dr.Ruud wrote:
> > Michele Dondi schreef:
> >> david.f.jenkins:
> >
> >>> I can't execute an external program or shove files around, because of
> >>> performance implications, mostly.  I need a "sub" (but one written in
> >>> Perl) that I can call from VBA.
> >> (Un)fortunately I don't know enough VBA (namely, no VBA at all) to
> >> address your question. My naive answer would be along the lines that
> >> it's not possible, period. But indeed there may be some
> >> framework/technology that allows this. Hope someone will know better.
> >
> > VBA can call members of libraries, at least .dll.
> > So if there would be a perllib.dll or such, it would be possible.
> >
>
> Perl classes can be wrapped as COM components. See Windows Script
> Components.
> 
> Mark



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

Date: Thu, 5 Oct 2006 17:36:47 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Please help me pass an array from VBA to Perl and populate it. Newbie at wits' end!
Message-Id: <eg3g1a.1c0.1@news.isolution.nl>

david.f.jenkins@usa.net schreef:

> I'm aware of that.

Of what? Don't top-post.


> I have created the Perl ActiveX control I need, and can safely travel
> back and forth from VBA to Perl.  What I *need* is help on the
> mechanics of getting String array information back from the called
> control.  I am unable to figure out how to do this either through a
> passed argument, or through VBA access of the control's poperties.
>
> Right now, I'm pretty much dead in the water.  I just can't believe
> that this is not a problem that myriads of others have already faced
> and overcome.


Maybe this helps:

SOAP::Lite
http://search.cpan.org/src/BYRNE/SOAP-Lite-0.69/examples/COM/
("when you return an array reference from a subroutine, it is
automatically converted into an array in the host language")

Scriptlets
http://www.foo.be/docs/tpj/issues/vol3_4/tpj0304-0009.html

PDK:
http://www.foo.be/docs/tpj/issues/vol5_3/tpj0503-0011.html

(all from the first few hits of google: vba perl string return)

-- 
Affijn, Ruud

"Gewoon is een tijger."




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

Date: 5 Oct 2006 08:32:10 -0700
From: vladimir.giron@gmail.com
Subject: Problems at writing multiple files
Message-Id: <1160062330.276302.93430@k70g2000cwa.googlegroups.com>

I have a problem at writing multiple files. I have this code where I
write several XML files (the number of files it's dynamic). I use a
loop and in Linux works fine but the problem is Windows.

For example lets say that I want to write a long essay into 1 file,
Windows and Linux do it as it should be, the problem comes when I want
to write that same essay (divided into 5 parts) in 5 files. Linux works
fine but windows skips the first part (the first file is not written)
and the remaining parts are written well.. if I want to write the essay
into 10 files, the first three are not written and as the number of
files grows so does the number of files not written.

Does anyone knows why could this be? Next is the part of the code where
I write into the files.


local *FILE_X;
eval {
     if(substr($filename, length($filename) - 4) eq '.txt')
         { #this does nothing yet }
     else { my $success = open ::FILE, "> $filename";
         unless($success) { $output->Error("Can not open file:
$filename");
              return $False; }
         print ::FILE $FILE_HEADER;
         foreach my $line (@{$self->{_set}})
         { $line->WriteXML(*FILE_X{IO}); }
         print ::FILE $FILE_FOOTER;
         close ::FILE; } };
if($@) { $output->Fatal("Couldn't write out to file: $filename"); }
chmod(0644, $filename);


sub WriteXML {
		my($self, $file) = @_;

		if(!$self->{loc}){
			return;
		}
		my $out = $XML_PREFIX;

		foreach my $attribute (@__slots__){
			my $value = $self->{$attribute};
			if($value) {
				if(Encode::is_utf8($value)) {
				 	$value = $encoder->NarrowText($value, undef);
				}

				#Escape characters
				$value =~ s/&/&amp;/g;
				$value =~ s/'/&apos;/g;
				$value =~ s/"/&quot;/g;
				$value =~ s/</&lt;/g;
				$value =~ s/>/&gt;/g;
				$out .= "  <$attribute>$value</$attribute>\n";
			}
		}
		$out = $out . $XML_SUFFIX;
		if(0) {
			#nothing yet
		}
		else {
			print ::FILE $out;
		}
	}



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

Date: Thu, 05 Oct 2006 11:21:16 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: question on File::Tail
Message-Id: <g69d596wzyr.fsf@CN1374059D0130.kendall.corp.akamai.com>

On  5 Oct 2006, someone@example.com wrote:

> I was going to suggest using alarm() but File::Tail uses sleep() and those two
> functions may not be compatible so you might want to fork() off a child
> process that has a timer and either: sends a SIGUSR1 back to the parent which
> catches it and writes to the log file or; have the child write to the log file.

The latter would be safer.

If the parent and the child decided, before forking, on a shared
memory segment, the parent could write the file name to the shared
memory *when it changes* and the child could read it on every timer.

The parent could also open a pipe device and write the file name to it
whenever the name changes, then the child just does

loop:
 sleep
 if data in pipe, change log file name to the data
 write to log file
end

There are other ways to implement this, but for reliability the pipe
is probably the best way and most easily portable to other Unix
systems.  I've had problems with shared memory under Perl on older
Unices.

Ted


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

Date: 5 Oct 2006 07:31:33 -0700
From: chaitask@yahoo.com
Subject: Regarding numeric literals
Message-Id: <1160058693.752092.110020@i42g2000cwa.googlegroups.com>

Hi folks,

As part of some operation that fetches disk free space from a Windows
machine, I get numbers like 3,45,198 (comma-separated....you get the
idea right?). Since a comma is a list separator in Perl, I can't use a
number like that in my operations and so I decided to replace globally
all commas with underscores because Perl seems to OK it.

The result 3_45_198 works well in numeric comparison scenarios (less
than, greater than, etc) but not in any operations like addition,
multiplication, etc (it actualls adds/multiplies the other operand
to/with 3, the leading number in 3_45_198, and returns the value). Does
it mean that numerals like this don't function as "proper" numerals?

Do I really have to delete the underscores or is there a way to make
Perl understand that I want it to function like a normal numeral?

Thanks a million, 
Krish.



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

Date: 5 Oct 2006 07:47:41 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Regarding numeric literals
Message-Id: <1160059661.828311.21430@h48g2000cwc.googlegroups.com>

chaitask@yahoo.com wrote:
> As part of some operation that fetches disk free space from a Windows
> machine, I get numbers like 3,45,198 (comma-separated....you get the
> idea right?). Since a comma is a list separator in Perl,

The comma is the list separator in Perl *source code*, not in variables
or values read in or calculated.

> I can't use a
> number like that in my operations and so I decided to replace globally
> all commas with underscores because Perl seems to OK it.

No, it's not.

> The result 3_45_198 works well in numeric comparison scenarios (less
> than, greater than, etc)

No, it's not.  And if you were enabling warnings, it would tell you
that.  Why aren't you asking the computer for all the help you can get?

> but not in any operations like addition,
> multiplication, etc (it actualls adds/multiplies the other operand
> to/with 3, the leading number in 3_45_198, and returns the value).

Which is precisely what it's supposed to do.  '3_45_198' is not a
numeric value, it's a string value.  When you use a string value in a
numeric context, it converts to a number by starting at the first
character of the string, and going until the first character that makes
it not a numeric value.  In this case, that's the _.

> Does it mean that numerals like this don't function as "proper" numerals?

Yes.  You do not have numerals.  You have strings that happen to
contain digits, along with other characters.

> Do I really have to delete the underscores or is there a way to make
> Perl understand that I want it to function like a normal numeral?

Delete the underscores/commas.  Work with numbers in your code.  When
you want to display them, display them with your commas.  See the FAQ:
perldoc -q commas
Found in /opt2/Perl5_8_4/lib/perl5/5.8.4/pod/perlfaq5.pod
     How can I output my numbers with commas added?


So, read in your values from whatever the operation is, get rid of the
commas.  Do whatever numeric computations you need, and then when you
print your values out, commify them:

my $disk_size = get_disk_size();
$disk_size = tr/,//d;
#do stuff with $disk_size;
print "Disk size: ", commify($disk_size), "\n";


And please enable
use strict;
use warnings;
in all your code.

Paul Lalli



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

Date: Thu, 05 Oct 2006 16:47:42 +0200
From: Mirco Wahab <peace.is.our.profession@gmx.de>
Subject: Re: Regarding numeric literals
Message-Id: <eg366q$qbj$1@mlucom4.urz.uni-halle.de>

Thus spoke chaitask@yahoo.com (on 2006-10-05 16:31):
> The result 3_45_198 works well in numeric comparison scenarios (less
> than, greater than, etc) but not in any operations like addition,
> multiplication, etc (it actualls adds/multiplies the other operand
> to/with 3, the leading number in 3_45_198, and returns the value). Does
> it mean that numerals like this don't function as "proper" numerals?

Hmmm, there seems to be another factor involved,
at least here it works:

  $>perl -e "print 3 + 120300"
  120303

  $> perl -e "print 3 + 1_20_300"
  120303

  $> perl -e "print 3 + 1_20_30_0"
  120303

  $>perl -e "print 3 + 1_2_0_30_0"
  120303

  $>perl -e "print 3 + 1_2_0_3_0_0"
  120303


Can you post a real example, where
it bails with the wrong numbers?

What Perl version is it? How
"long" are the numbers?

Regards

Mirco


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

Date: 5 Oct 2006 08:01:10 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Regarding numeric literals
Message-Id: <1160060470.274986.107450@h48g2000cwc.googlegroups.com>

Mirco Wahab wrote:
> Thus spoke chaitask@yahoo.com (on 2006-10-05 16:31):
> > The result 3_45_198 works well in numeric comparison scenarios (less
> > than, greater than, etc) but not in any operations like addition,
> > multiplication, etc (it actualls adds/multiplies the other operand
> > to/with 3, the leading number in 3_45_198, and returns the value). Does
> > it mean that numerals like this don't function as "proper" numerals?
>
> Hmmm, there seems to be another factor involved,
> at least here it works:
>
>   $>perl -e "print 3 + 120300"
>   120303
>
>   $> perl -e "print 3 + 1_20_300"
>   120303

This is NOT what the op said.  In the original scenario, it was
indicated that the values are the result of a computation, not literals
typed into the code.  The distinction is all important.  Underscores
are allowed in numeric literals, not in string variables or values.

$ perl -lwe'
print 3 + "1_20_300";
'
Argument "1_20_300" isn't numeric in addition (+) at -e line 2.
4

> Can you post a real example, where
> it bails with the wrong numbers?
>
> What Perl version is it? How
> "long" are the numbers?

None of that is relevant.

Paul Lalli



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

Date: Thu, 05 Oct 2006 11:12:39 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Regarding numeric literals
Message-Id: <g69hcyix0d4.fsf@CN1374059D0130.kendall.corp.akamai.com>

On  5 Oct 2006, mritty@gmail.com wrote:

> So, read in your values from whatever the operation is, get rid of the
> commas.  Do whatever numeric computations you need, and then when you
> print your values out, commify them:
>
> my $disk_size = get_disk_size();
> $disk_size = tr/,//d;
> #do stuff with $disk_size;
> print "Disk size: ", commify($disk_size), "\n";

Would it perhaps be better to remove all \D characters?  Some locales
may use '.' to separate thousands, for example.

$disk_size =~ s/\D//g;

Ted


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

Date: 5 Oct 2006 08:43:57 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Regarding numeric literals
Message-Id: <1160063037.844648.165930@k70g2000cwa.googlegroups.com>

Ted Zlatanov wrote:
> On  5 Oct 2006, mritty@gmail.com wrote:
>
> > So, read in your values from whatever the operation is, get rid of the
> > commas.  Do whatever numeric computations you need, and then when you
> > print your values out, commify them:
> >
> > my $disk_size = get_disk_size();
> > $disk_size = tr/,//d;
> > #do stuff with $disk_size;
> > print "Disk size: ", commify($disk_size), "\n";
>
> Would it perhaps be better to remove all \D characters?  Some locales
> may use '.' to separate thousands, for example.
>
> $disk_size =~ s/\D//g;

The OP did not specify if the numbers read in contained things such as
decimals or even positive or negative signs.  All of those are valid
numbers, and would change the meaning of the number if they were
removed.  All the OP specified is that the strings have commas, which
are not valid (at least, not in this context).

Paul Lalli



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

Date: Thu, 05 Oct 2006 17:49:42 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Regarding numeric literals
Message-Id: <eg39r6$rcs$1@mlucom4.urz.uni-halle.de>

Thus spoke Paul Lalli (on 2006-10-05 17:01):
> Mirco Wahab wrote:
>> What Perl version is it? How
>> "long" are the numbers?
> 
> None of that is relevant.

Right, the '_' are only valid
in _string_literals_ defined
in the program (at compile?).

External sources are, of course,
treated as they look like ...

Sorry for bringing only additional confusion ;-)

Regards & thanks

Mirco


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

Date: 5 Oct 2006 09:06:29 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Regarding numeric literals
Message-Id: <1160064389.877501.197870@h48g2000cwc.googlegroups.com>

Mirco Wahab wrote:
> Thus spoke Paul Lalli (on 2006-10-05 17:01):
> > Mirco Wahab wrote:
> >> What Perl version is it? How
> >> "long" are the numbers?
> >
> > None of that is relevant.
>
> Right, the '_' are only valid
> in _string_literals_ defined
> in the program (at compile?).

No.  That's exactly the point.  Underscores are NOT valid numeric
characters in string literals.  They are only valid in *numeric*
literals.

my $x = 123_456;
my $y = "123_456";

$x is the number "one hundred, twenty-three thousand, four hundred
fifty-six".
$y is the string "one two three underscore four five six".

Values read or computed, of course, cannot contain the underscore no
matter how they were calculated.

Paul Lalli



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

Date: Thu, 05 Oct 2006 19:46:22 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Regarding numeric literals
Message-Id: <eg3glt$7g$1@mlucom4.urz.uni-halle.de>

Thus spoke Paul Lalli (on 2006-10-05 18:06):
> Mirco Wahab wrote:
>> Thus spoke Paul Lalli (on 2006-10-05 17:01):
>> > Mirco Wahab wrote:
>> >> How "long" are the numbers?
>> > None of that is relevant.
>> Right, the '_' are only valid
>> in _string_literals_ defined
> No.  ... They are only valid in *numeric* literals.

OK, I read the related paragraph again in
the Camel book and it says exactly that.
So I guess you are right here ;-)

So, this is what I learned today ...

Thanks

Mirco


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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.

#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 V10 Issue 9807
***************************************


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