[19282] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1477 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 9 14:05:48 2001

Date: Thu, 9 Aug 2001 11:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <997380312-v10-i1477@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 9 Aug 2001     Volume: 10 Number: 1477

Today's topics:
        -w option changes filename variable (Pete)
    Re: Advise on using perl to sort and give totals (Anno Siegel)
    Re: Advise on using perl to sort and give totals <rsherman@ce.gatech.edu>
    Re: Baiting Gozilla to obtain quality code for nothing! slash@dot.c.o.m.org
        Converting a string to an Integer <Pcmann1@btinternet.com>
    Re: Converting a string to an Integer <ilya@martynov.org>
        find the next Friday date in Perl (Larry S)
    Re: find the next Friday date in Perl (John J. Trammell)
    Re: How to get Mac and IP address of computers over a n (Fred)
    Re: how to get perlscript (Helgi Briem)
    Re: Is it a number? <jurgenex@hotmail.com>
    Re: Is it a number? <tzz@beld.net>
        Location: cgi problem <richard@sunsetandlabrea.com>
    Re: Location: cgi problem <flavell@mail.cern.ch>
    Re: Location: cgi problem <richard@sunsetandlabrea.com>
    Re: Location: cgi problem <richard@sunsetandlabrea.com>
    Re: Math::BigInt Doesn't Work!!!! (Anno Siegel)
    Re: mresolv2 and sockets on HP-UX 10.20 (Mike)
    Re: NET::FTP and other file operations <gnarinn@hotmail.com>
    Re: Not matching strings <bart.lateur@skynet.be>
    Re: q: converting strings (Tad McClellan)
    Re: q: converting strings <jasper@guideguide.com>
        reading Powerpoint with Win32::OLE?  <stefan.geissler@temis-group.com>
    Re: Sub that defaults to use $_ in callers context <mjcarman@home.com>
        Using TRUE constant in IF expression?? <miscellaneousemail@yahoo.com>
    Re: Using TRUE constant in IF expression?? <uri@sysarch.com>
    Re: Using TRUE constant in IF expression?? <miscellaneousemail@yahoo.com>
    Re: Variable reference prob - could u help? :) nobull@mail.com
        Where can I learn to do this? <viper16336@mindspring.com>
    Re: Why? <bart.lateur@skynet.be>
    Re: Write to middle of file nobull@mail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 09 Aug 2001 16:52:03 GMT
From: Peter@angeltec.fsnetNOTTHIS.co.uk (Pete)
Subject: -w option changes filename variable
Message-Id: <3b72be98.91662146@news.btinternet.com>

Hi,

when running perl with the -w option :
print $0 gives filename

without the -w it gives ./filename.

This means that the script works ok when I'm testing it but not when
run 'normally'.
Is there a work around please.

Pete 


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

Date: 9 Aug 2001 15:30:09 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Advise on using perl to sort and give totals
Message-Id: <9kuaa1$m06$2@mamenchi.zrz.TU-Berlin.DE>

According to sammy <sammy@bigpond.net.au>:
> 
> 
> Appreciate advise on following:
> 
> I have  a unix txt file containing ~ 800k records of ~ length 120 bytes.
> I would like to obtain a a sorted list of the total number of times the
> varying first field occurs in the file.
> 
> Using shell as below is okay but takes far too long/wasting resources ie

[snip shell code]

> DATA
> 
> 
> 800k file
> 
> 45.67.78.90 fred jones 19yrs London England
> 45.67.78.60 fred jones 19yrs London England
> 45.67.78.90 fred jones 19yrs London England
> 45.67.78.80 fred jones 19yrs London England
> 45.67.78.90 fred jones 19yrs London England
> 45.67.78.80 fred jones 19yrs London England
> ...
> 
> result I'm looking for is:
> 
> 45.67.78.90   total 3
> 45.67.78.80   total 2
> 45.67.78.60   total 1
> 
> 
> Welcome ways I can do this using perl to  speed things up
> appreciating any helpful comments on syntax.
> 
> Apparently below should work but tried running and recieved syntax
> errors allso no very little about perl
> 
> #!/usr/local/bin/perl -wl
> $_{(split)[0]}++ while (<>);
> print "$_\t$_{$_}" for sort { $_{$b} <=> $_{$a} } keys %_;

I wonder where you got that code...  It does work, expecting its input
either from STDIN or from a file named on the command line.  The code
certainly doesn't look like the work of a beginner, and its use of %_
besides $_ makes it pretty obfuscated.  It also contains a subtle
blunder: The parens around <> in the second line make it slurp the
whole file.

A more conventional way to code this is:

    my %count;
    $count{ ( split )[ 0]}++ while <>;
    print "$_\t$count{ $_}\n" for
        sort { $count{ $b} <=> $count{ $a} } keys %count;

Anno


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

Date: Thu, 09 Aug 2001 12:39:27 +0500
From: Robert Sherman <rsherman@ce.gatech.edu>
Subject: Re: Advise on using perl to sort and give totals
Message-Id: <3B723E2F.2FF1E81F@ce.gatech.edu>

sammy wrote:
> 
> Appreciate advise on following:
> 
> I have  a unix txt file containing ~ 800k records of ~ length 120 bytes.
> I would like to obtain a a sorted list of the total number of times the
> varying first field occurs in the file.
> 
> Using shell as below is okay but takes far too long/wasting resources ie
> forks ...
> 
> awk '{print $1}' file_800k_lines |sort -nu  > 1st_field_only_sorted_unique
> 
> for i in `cat 1st_field_only`
> do
> echo " $i \c"
> grep -c $i 1st_field_only_sorted_unique    file_800k_lines
> done > total_occurances_of_each_first_field
> 
> DATA
> 
> 800k file
> 
> 45.67.78.90 fred jones 19yrs London England
> 45.67.78.60 fred jones 19yrs London England
> 45.67.78.90 fred jones 19yrs London England
> 45.67.78.80 fred jones 19yrs London England
> 45.67.78.90 fred jones 19yrs London England
> 45.67.78.80 fred jones 19yrs London England
> ...
> 
> result I'm looking for is:
> 
> 45.67.78.90   total 3
> 45.67.78.80   total 2
> 45.67.78.60   total 1
> 
> Welcome ways I can do this using perl to  speed things up
> appreciating any helpful comments on syntax.
> 
> Apparently below should work but tried running and recieved syntax
> errors allso no very little about perl
> 
> #!/usr/local/bin/perl -wl
> $_{(split)[0]}++ while (<>);
> print "$_\t$_{$_}" for sort { $_{$b} <=> $_{$a} } keys %_;
> 
> Ps have used
> 
> fgrep -cf  1st_field_only_sorted_unique  file_800k_lines
> 
> but c does not work as hoped
> 
> Thanks
> 
> Sammy

untested, but should give you ideas (this just totals...does not sort):

%hash = ();
open FILE, "bigfile";
while (<FILE>){
@array = split;
$hash{$array[0]}++;
}


--
robert sherman
css, cee
georgia institute of technology
atlanta, ga, usa


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

Date: Thu, 09 Aug 2001 18:07:36 GMT
From: slash@dot.c.o.m.org
Subject: Re: Baiting Gozilla to obtain quality code for nothing!!
Message-Id: <3b72d132.81629937@news.freeserve.co.uk>

On Sat, 04 Aug 2001 18:53:42 +1000, Walnut <walnut@froggy.com.au> wrote:

[... much wisdom...]

>Normally it would cost ++$75/hour for a piece of code to this quality

Wow, I really am undercharging. Jesus, I should be on $250ph at least...


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

Date: Thu, 9 Aug 2001 18:19:23 +0100
From: "Peter Mann" <Pcmann1@btinternet.com>
Subject: Converting a string to an Integer
Message-Id: <9kugl7$buf$1@neptunium.btinternet.com>

Dear all,
    I have some code that retrieves a string from a database but I need to
convert it into an integer. Could someone please tell me if a library and
function exists to do this, and where it is located!

Thanks in advance

Regards,
    - Pete





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

Date: 09 Aug 2001 21:24:27 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Converting a string to an Integer
Message-Id: <874rrh6t9w.fsf@abra.ru>


PM> Dear all,
PM>     I have some code that retrieves a string from a database but I need to
PM> convert it into an integer. Could someone please tell me if a library and
PM> function exists to do this, and where it is located!

my $int = int($str);

See 'perldoc -tf int' for more info.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: 9 Aug 2001 08:46:16 -0700
From: dime0000@yahoo.com (Larry S)
Subject: find the next Friday date in Perl
Message-Id: <8fd7acb0.0108090746.15e0e2ec@posting.google.com>

hey all. 
i'd like to know if anyone has a solution in finding the next Friday
date in Perl. for example, say i run the script on Tuesday August 7th
2001, i'd like Perl to tell me that Friday is the August 10th 2001.

thanks again!


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

Date: 09 Aug 2001 16:40:00 GMT
From: trammell@bayazid.hypersloth.invalid (John J. Trammell)
Subject: Re: find the next Friday date in Perl
Message-Id: <slrn9n4teg.2cd.trammell@haqq.hypersloth.net>

On 9 Aug 2001 08:46:16 -0700, Larry S <dime0000@yahoo.com> wrote:
> i'd like to know if anyone has a solution in finding the next Friday
> date in Perl.

[ ~ ] cat foo.pl
#!/usr/bin/perl -w
use strict;

for (my $i = 1; $i < 8; $i++)
{
    my $t = time() + $i * 24 * 3600;
    next unless (localtime($t))[6] == 5; # friday
    print scalar(localtime($t)), "\n";
    last;
}

[ ~ ] ./foo.pl
Fri Aug 10 06:35:12 2001
[ ~ ]

-- 
It's clear that the crew to send to Mars must be comprised of midget
eunuchs.


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

Date: 9 Aug 2001 10:42:49 -0700
From: flichtenfels@hotmail.com (Fred)
Subject: Re: How to get Mac and IP address of computers over a network?
Message-Id: <88a56672.0108090942.542fbaea@posting.google.com>

helgi@NOSPAMdecode.is (Helgi Briem) wrote in message news:<3b727bba.1481552429@news.isholf.is>...
> The command ipconfig /all can be used to get network info
> on a NT box so you can try:
> 
> my @network_info = qx/ipconfig \/all/ 
> or die "Cannot run ipconfig:$?\n";
> print @network_info;

Thanks Helgi that does work, but it only works for getting the info on
my machine.  I need to get the IP and Mac addresses of other machines
on the network as well.  It appears to me that ipconfig cannot be used
for this.  If I am overlooking something that you wrote and it can be
used for getting other's info or if you know of a way to get other's
info as well please let me know.
Thanks again,

Fred


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

Date: Thu, 09 Aug 2001 15:50:00 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: how to get perlscript
Message-Id: <3b72a183.1491226400@news.isholf.is>

On Thu, 09 Aug 2001 13:10:00 +0300, Roman Khutkyy
<sky@mail.lviv.ua> wrote:

>
>How do I configure Microsoft IIS 4.0 to support Perl for Win32?

This question is off topic in this newsgroup.  Ask
in a newsgroup devoted to the topic of web servers
and their configuration, for example:

comp.infosystems.www.servers.ms-windows

Despite being off-topic, this question has been 
asked about a 100 thousand million times in
this newsgroup and others and a quick search of
groups.google.com should turn up too many to handle.

Regards,
Helgi Briem



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

Date: Thu, 9 Aug 2001 10:22:55 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Is it a number?
Message-Id: <3b72c6f8$1@news.microsoft.com>

"Terry" <dcsnospam@ntlworld.com> wrote in message
news:Lmvc7.12678$e%3.1512312@news2-win.server.ntlworld.com...
> I'm just trying to check if a value entered into an input field in a form
is
> a number.
> Is there a function I'm missing?

The fifth entry in "perldoc -q number" will tell you how to do that
    "How do I determine whether a scalar is a number/whole/integer/float?"

jue




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

Date: Thu, 09 Aug 2001 13:24:50 -0400
From: Ted Zlatanov <tzz@beld.net>
Subject: Re: Is it a number?
Message-Id: <m3hevh404d.fsf@heechee.beld.net>

"Terry" <dcsnospam@ntlworld.com> writes:

> I'm just trying to check if a value entered into an input field in a
> form is a number.  Is there a function I'm missing?

perldoc perlfaq4 or perldoc -q number or 
http://www.perldoc.com/perl5.6/pod/perlfaq4.html

How do I determine whether a scalar is a number/whole/integer/float?

--
Teodor Zlatanov <tzz@iglou.com>
"Brevis oratio penetrat colos, longa potatio evacuat ciphos." -Rabelais


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


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

Date: Thu, 9 Aug 2001 17:20:23 +0000
From: Richard Chamberlain <richard@sunsetandlabrea.com>
Subject: Location: cgi problem
Message-Id: <MByc7.6158$tq.975280@news6-win.server.ntlworld.com>

Hi,

I'm using Location: to redirect to another cgi page but when I do I get the 
html of the page printed to the screen instead of actually seeing the page.

I presume it's a problem  with the Content-type: text/html?

Obviously if I view the page by typing the url in the browser it works fine.

Thanks,

Richard


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

Date: Thu, 9 Aug 2001 18:24:41 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Location: cgi problem
Message-Id: <Pine.LNX.4.30.0108091819200.9967-100000@lxplus023.cern.ch>

On Aug 9, Richard Chamberlain twiddled the eigenstates thus:

> I'm using Location: to redirect to another cgi page but when I do I get the
> html of the page printed to the screen instead of actually seeing the page.

Sounds like a problem that would be on-topic for
comp.infosystems.www.authoring.cgi

> I presume it's a problem  with the Content-type: text/html?

Location: doesn't have a Content-type:

> Obviously if I view the page by typing the url in the browser it works fine.

> Thanks,

No URL?  No code?  Wrong group?  With the greatest of respect, it's
very hard to help someone who doesn't seem to be trying very hard to
help their helpers.  The crystal ball is in the workshop right now,
and the initial diagnosis is usenet exhaustion.

all the best



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

Date: Thu, 9 Aug 2001 18:01:55 +0000
From: Richard Chamberlain <richard@sunsetandlabrea.com>
Subject: Re: Location: cgi problem
Message-Id: <Iczc7.6492$tq.991133@news6-win.server.ntlworld.com>

Alan J. Flavell wrote:

> On Aug 9, Richard Chamberlain twiddled the eigenstates thus:
> 
>> I'm using Location: to redirect to another cgi page but when I do I get
>> the html of the page printed to the screen instead of actually seeing the
>> page.
> 
> Sounds like a problem that would be on-topic for
> comp.infosystems.www.authoring.cgi
> 
>> I presume it's a problem  with the Content-type: text/html?
> 
> Location: doesn't have a Content-type:
> 
>> Obviously if I view the page by typing the url in the browser it works
>> fine.
> 
>> Thanks,
> 
> No URL?  No code?  Wrong group?  With the greatest of respect, it's
> very hard to help someone who doesn't seem to be trying very hard to
> help their helpers.  The crystal ball is in the workshop right now,
> and the initial diagnosis is usenet exhaustion.
> 
> all the best
> 
> 

Ouch,

I think that was a bit uncalled for. I realise that location doesn't have a 
Content-type, but it doesn't take a crystal ball to know that I'm talking 
about html headers and html has a content-type.

Sometimes I wonder why people expend so much energy insulting people if 
they post to the wrong group instead of just saying 'try posting here'. You 
first paragraph was perfect - the rest >> With the greatest of respect - 
was just annoying.

Richard


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

Date: Thu, 9 Aug 2001 18:05:17 +0000
From: Richard Chamberlain <richard@sunsetandlabrea.com>
Subject: Re: Location: cgi problem
Message-Id: <Rfzc7.6515$tq.992596@news6-win.server.ntlworld.com>

Richard Chamberlain wrote:

> Hi,
> 
> I'm using Location: to redirect to another cgi page but when I do I get
> the html of the page printed to the screen instead of actually seeing the
> page.
> 
> I presume it's a problem  with the Content-type: text/html?
> 
> Obviously if I view the page by typing the url in the browser it works
> fine.
> 
> Thanks,
> 
> Richard
> 
I've figured it out - my code wasn't outputting the header in certain 
circumstances.

Thanks,

Richard


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

Date: 9 Aug 2001 16:04:02 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Math::BigInt Doesn't Work!!!!
Message-Id: <9kuc9i$ngp$1@mamenchi.zrz.TU-Berlin.DE>

According to Jeff Snoxell <Jeff@aetherweb.co.uk>:
> Ahhhh
> 
> I can't get the Math::BigInt module to function. The available commands seem
> to cause my program to simply terminate unexpectedly. I'm trying to run the
> following code:
> 
> $public_key_pq = Math::BigInt->new('323');
> $public_key_e  = Math::BigInt->new('43');
> 
> sub EncryptChar
> {
>   my ($original) = @_;
>   my $encrypted = Math::BigInt->new('1');
>   my $bigorig   = Math::BigInt->new(ord($original));
>   my $i = Math::BigInt->new('1');
> 
>   # Do the following public_key_e times...
> 
>   while ($i->bcmp($public_key_e) ne '0')
>   {
>     $encrypted = $encrypted->bmul($bigorig);
>     $encrypted = $encrypted->bmod($public_key_pq);
>     $i = $i->badd('+1');
>   }
> 
>   return $encrypted;
> }
> 
> Calling EncryptChar('T');
> 
> The code seems to lock between the bmul and bmod lines, so I assume theres a
> problem with the bmod line... but what can it be?

No solution, just a data point.  When I run your code (5.6.1 on Linux),
after "$encrypted = $encrypted->bmul($bigorig);" $encrypted seems[1] to
be an ordinary string ("+84", not totally unexpected), but not a
Math::BigInt object.  So the next line bails out.  Something is fishy.

Anno

[1] Not sure about possible overload, so I'm a being careful.


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

Date: 9 Aug 2001 08:58:57 -0700
From: junkeater12@yahoo.com (Mike)
Subject: Re: mresolv2 and sockets on HP-UX 10.20
Message-Id: <43e24eb1.0108090758.6771d7af@posting.google.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<9ktq99$50k$1@mamenchi.zrz.TU-Berlin.DE>...
> In calls like bind(), Perl only passes things back and forth between
> your program and the operating system, so "Invalid argument" is
> really a message created by the corresponding system- (or library-)
> call.  The thing to do at this point is look up the error you get
> in the original man page, "man bind".  Look for EINVAL under ERRORS.  
> In my Linux system, there is only one possible cause: "The socket
> is already bound to an address", but you should check on HP-UX.
> I don't know where this may lead to, but that's the way to get
> started.
> 
> Anno

Hello again,

I looked at the bind man page, and essentially the reasons are as
follows, but none of them seem to make sense:

* The socket is already bound to an address 
    --- Because the code isn't specifying a specific port, shouldn't
one be chosen that's available?

* the socket has been shut down
    --- How would this have happened??

* addrlen is a bad value
    --- The code isn't specifying this; isn't it implied?

* an attempt was made to bind() an AF_UNIX socket to an NFS-mounted
(remote) name.
    --- the source is 0.0.0.0 and the dest is in the remote name
server, so how would this be the case?

A stripped-down code example that acts the same would be such:

#!/usr/local/bin/perl -w
use IO::Socket;
use diagnostics;
use strict;
my $sock = IO::Socket::INET->new(Proto => "udp", Reuse => 1);
die "couldn't create socket: $!" unless $sock;
my $sockaddr_src = sockaddr_in("0", inet_aton("0.0.0.0"));
$sock->bind($sockaddr_src) or die "can't bind socket: $!";

Since 0 is being used as the source port and 0.0.0.0 as the source
address, shouldn't something sane be chosen?  The results don't change
if I choose a specific source address (there's only one on the machine
anyway).

So now what?


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

Date: Thu, 9 Aug 2001 17:12:43 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: NET::FTP and other file operations
Message-Id: <997377163.753419280052185.gnarinn@hotmail.com>

In article <9kt24u$6hdbo$1@ID-35855.news.dfncis.de>,
Gerhard <gerhardpremovethis@inch.com> wrote:
>I'm not sure if anyone else has come across this, but here it is:
>
>I have this short script that retrieves some files using Net::FTP.  In it I
>also want to do some logging to a text file.
>Seems that when I do a $ftp->get($file);   I can no longer log to a text
>file.  (print LOG "[$when] $script: $msg\n";)  LOG is of course the handle
>to that text file.
>
>Is there something about the $ftp->get() that knocks out other file handles?
>

I am sure it is just a bug in your code.

post a short complete script that exhibits your problem and we will
take a look at it. the odds are that just by doing that you will find the
problem yourself.

gnari


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

Date: Thu, 09 Aug 2001 15:28:55 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Not matching strings
Message-Id: <dqa5ntgpstp850q56ddd9uk66kg96jttj1@4ax.com>

Grunge Man wrote:

>The purpose of this is to allow passing of a variety of regular expressions
>on the command line to a complex report style program - some RE's are
>matching expressions, and some are non-matching.
>
>Hence "ne", "unless", and "!" solutions wouldn't help....

Perhaps they would.

If I need to search for all words in a query, with an option of
forbidden words, I first create a sub as text , eval it to compile it,
and call the coderef to do the search. Thus, if i want the words "abc"
and "def" but not "xyz", this can be achieved like:

	$search = eval 'sub {  /\babc\b/ && /\bdef\b/ && !/\bxyz\b/ }';
	@match = grep { &$search } @list;

Of course, the string will be constructed on the fly; and you can do the
search line by line, instead of going through an array.

-- 
	Bart.


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

Date: Thu, 9 Aug 2001 10:09:26 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: q: converting strings
Message-Id: <slrn9n56cm.qk9.tadmc@tadmc26.august.net>

Jasper McCrea <jasper@guideguide.com> wrote:
>Tad McClellan wrote:
>> Jasper McCrea <jasper@guideguide.com> wrote:
>> >Malcolm Dew-Jones wrote:
>> >> Oliver (ow22@nospam-cornell.edu) wrote:
>> >> : how do i convert a string to an int? thanks
>> >>
>> >> In perl, if the string looks like a number then it is a number.
>> >
>> >This is a little misleading.
>> 
>> Not nearly as misleading, IMO, as your comments that follow...
>> 
>> >$one = "twelve";
>> >$two = "12";
>> >
>> >both are strings, and look like numbers to me.
>>                                          ^^^^^
>> 
>> I suggest that perhaps you are in the minority then.
>
>Malcolm wrote 'if the string looks like a number then it is a number'.
>
>I suggest that 'twelve' looks like a number, 


All the world does not all speak English.

For a significant portion of the world's population, that does not
look like a number.

"12" looks like a number in (nearly?) all the world.


>and you disagree. 


Me and everyone in the world who does not speak English.


>Would you say I was in a minority if I said that 'aebbc' looked like a
>number, too?


Yes.


>Perhaps I was being a little facetious (and I'll continue in that vein).
>  
>> Addition is defined for numbers. If you don't have numbers, then
>> you don't know what "addition" means.
>
>my $string = "a";
>++$string;
>print "$string\n";


That is not "addition". That is "auto-increment".

Next try please.

:-)


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


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

Date: Thu, 09 Aug 2001 16:58:16 +0100
From: Jasper McCrea <jasper@guideguide.com>
Subject: Re: q: converting strings
Message-Id: <3B72B318.B92E3A7C@guideguide.com>

"John W. Krahn" wrote:
> 
> Jasper McCrea wrote:
> >

snip
> >
> > I suggest that 'twelve' looks like a number, and you disagree. I find
> > that extremely odd.
> 
> It looks like a _word_ to me.

bu *cough* it.   :)

12
That looks like two arabic symbols set side by side.

To say that a word representation of a number looks any less like a
number than the arabic representation of the same number is nonsense.

Tad mentioned (and I'm unfortunately going to reply to a bit of his post
in here) 

"For a significant portion of the world's population, that does not
look like a number." referring to 'twelve'

To which I would posit that a significant portion of the world's
population does not program in perl, and of those that do, an
insignificant portion would not recognise 'twelve' as being a number (or
a representation of the same number that '12' represents :)  ). If you
_really_ think I'm wrong there, I shall argue no further.

snip
 
> > my $string = "a";
> > ++$string;
> > print "$string\n";
> 
> You are confusing auto-increment with addition.

I'll call uncle on this one (I really should have known all along, if
I'd remembered an earlier lesson with the auto-increment operator).

Jasper
_nearly_ fed up playing Devil's advocate.
-- 
      split//,'019617511192'.
      '17011111610114101114'.
      '21011141011840799901'.
            '17101174';
            foreach(0..
            $#_){$_[$_
            ++]^=$_[$_
            --]^=$_[$_
]^=$_[++    $_]if!($_%
2)}$g.=$_  ,chr($g)=~
 /(\w)/&&($o.=$1and
   $g='')foreach@_;
      print"$o\n"


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

Date: Thu, 9 Aug 2001 17:04:07 +0200
From: "Stefan Geißler" <stefan.geissler@temis-group.com>
Subject: reading Powerpoint with Win32::OLE? 
Message-Id: <QBxc7.6974$Yy2.53289@tengri.easynet.fr>

Hi,

I am looking for a little hint about how to use the Win32::OLE module

We'd like to get to the text in word or powerpoint files.

But while word is fine, we cannot open a ppt file in the same way.

$Doc = $OLEObject->Documents->Open({'FileName'         => $InFile
                                                              'ReadOnly'
=> 1}) ;

$Doc = $OLEObject->Presentations->Open({'FileName'         => $InFile,
                                                                  'ReadOnly'
=> 1}) ;


Perl complains "OLE exception from "Microsoft PowerPoint 2000":
Presentations.Open : Invalid request.  The PowerPoint Frame window does not
exist.

Does anyone know how to handle this? Any hints would be greatly appreciated.

Best,
Stefan
Stefan.Geissler@temis-group.com




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

Date: Thu, 09 Aug 2001 10:53:32 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Sub that defaults to use $_ in callers context
Message-Id: <3B72B1FC.6EB2DDA0@home.com>

Yves Orton wrote:
> 
> Just curious if anyone knows how to get access to the callers $_ so
> that it can be used as a default like so many keywords do?
> 
> I tried to do it directly by
> 
> sub func {
>     my $param=shift || $_;
> }

Works for me:

#!/usr/bin/perl -w
use strict;

$_ = 'beta';

foo('alpha');
foo();

sub foo {
    my $param = shift || $_;
    print "$x\n";
}
__END__
alpha
beta

Of course, if you want to be able to pass in false values, you should
change that to:

sub foo {
    my $param = (defined $_[0]) ? $_[0] : $_;
    #...
}
 
> but obviously this doesnt work as $_ is automatically localized to the
> sub (at least im pretty sure I read that somwhere.) Either way though
> it didnt work.

No, $_ is a global variable and is not automatically localized. I think
you are getting confused with the array @_ used to pass arguments to
functions. Did you initialize $_?

-mjc


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

Date: Thu, 09 Aug 2001 16:31:48 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Using TRUE constant in IF expression??
Message-Id: <MPG.15dc6902d4c6260d98971e@news.edmonton.telusplanet.net>

Hi everyone, 

In another thread Tassilo and Anno brought up the dangers of using TRUE 
and FALSE constants in Perl.

Anno stated:

> The reason for not using constants TRUE and FALSE is that people will
> be tempted to compare results to these constants directly, expecting
> "if ( <expr> )" to be the same thing as "if ( <expr> eq TRUE)" and
> "unless ( <expr>)" the same as "if ( <expr> eq FALSE)".  But the values
> that are true or false in boolean context are by no means unique[1], so 
> these equivalences don't hold in general, no matter which values you
> actually assign to TRUE and FALSE.

In light of what Anno stated above can someone suggest a better way to 
write the if statement in the code below without having to say if 
(valid($string) eq "1") type of thing?  Writing it as "if 
(valid($string))" is much clearer IMO, especially to non-Perl programmers 
looking at my code.  But it would seem that this is problematic since any 
string value would evaluate to TRUE.  

#!/usr/bin/perl -w
use CGI::Carp qw(carpout fatalsToBrowser);
use diagnostics;
use strict;

use constant TRUE  => "1";  #any value other than "0" or "" is true!
use constant FALSE => "0";

my $string = "San Jose";
if (valid($string)) {
  print "[$string] was valid.";
}
else {
  print "[$string] was invalid.";
}   

sub valid
{
  my $string = $_[0];
  # if $string contains characters other than those in regexp...
  if ($string =~ /[^a-zA-Z ]/) {
    return FALSE;
  }
  else {
    return "Hello there"; #this evaluates to TRUE also!
  }	 
}

Any comments would be appreciated.  Thanks.

-- 
Carlos 
www.internetsuccess.ca


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

Date: Thu, 09 Aug 2001 17:03:46 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Using TRUE constant in IF expression??
Message-Id: <x77kwd9nd9.fsf@home.sysarch.com>

>>>>> "CCG" == Carlos C Gonzalez <miscellaneousemail@yahoo.com> writes:

  CCG> use constant TRUE  => "1";  #any value other than "0" or "" is true!
  CCG> use constant FALSE => "0";

that is a very bad idea in perl. it will cause confusion and problems
later on even if they seem to work now. just use normal perl boolean
values and behavior.

one big failure of those is when you assign the sub to an array. then
the array is ALWAYS true as it has one element (whose boolean value will
not be checked. the best way to return a flase value is with a plain
return. it will return undef to a scalar and the empty list () to an
array. both of those are false in a boolean context.

  CCG> my $string = "San Jose";
  CCG> if (valid($string)) {
  CCG>   print "[$string] was valid.";
  CCG> }
  CCG> else {
  CCG>   print "[$string] was invalid.";
  CCG> }   

  CCG> sub valid

choose a better name for that sub. valid WHAT? valid name? valid identifier?

  CCG> {
  CCG>   my $string = $_[0];

not many people use $_[0] and copy it. that style is mostly used for
direct access (as @_ has aliases) to the params. use shift or @_

	my ($string) = @_ ;

  CCG>   # if $string contains characters other than those in regexp...
  CCG>   if ($string =~ /[^a-zA-Z ]/) {
  CCG>     return FALSE;
  CCG>   }
  CCG>   else {
  CCG>     return "Hello there"; #this evaluates to TRUE also!
  CCG>   }	 
  CCG> }

learn to use perl's statement modifiers as it will clean up your
code. one big win for them is reducing the unneeded braces and indents
of simple conditionals like that.

sub valid_string {

	my ($string) = @_ ;

# see if any bad chars are in the string

	return if $string =~ /[^a-zA-Z ]/ ;

# the string is ok

	return 1 ;
}

isn't that much clearer? notice that the test has an empty return which
will be correctly false in all contexts.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs  --------------------------  http://jobs.perl.org


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

Date: Thu, 09 Aug 2001 17:58:41 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Re: Using TRUE constant in IF expression??
Message-Id: <MPG.15dc7cf65a88edf989721@news.edmonton.telusplanet.net>

In article <x77kwd9nd9.fsf@home.sysarch.com>, Uri Guttman at 
uri@sysarch.com says...

> choose a better name for that sub. valid WHAT? valid name? valid identifier?

Good point Uri.  Definitely not the way I would normally name this 
function (boy I can't get away with anything here =:).  It was just a 
snippet of code that I was playing with to better understand what others 
were saying.

> learn to use perl's statement modifiers as it will clean up your
> code. one big win for them is reducing the unneeded braces and indents
> of simple conditionals like that.

Statement modifiers?  I will have to look that one up in the 
documentation.  I have a general idea of what you mean but I don't 
exactly know what these are or how to use whatever they are.  No need to 
respond to this Uri.  I will look it up.

> 
> sub valid_string {
> 
> 	my ($string) = @_ ;
> 
> # see if any bad chars are in the string
> 
> 	return if $string =~ /[^a-zA-Z ]/ ;
> 
> # the string is ok
> 
> 	return 1 ;
> }
> 

Very interesting.  You have given me some meat to chew on Uri.  Thanks. 

-- 
Carlos 
www.internetsuccess.ca


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

Date: 09 Aug 2001 17:57:51 +0100
From: nobull@mail.com
Subject: Re: Variable reference prob - could u help? :)
Message-Id: <u9bslp6ui8.fsf@wcl-l.bham.ac.uk>

cool133@hotmail.com (^CooL^) writes:

> Please consider the following code snippet:

I think it would be better to consider actual code since in
trascription you have apparently fixed the misplaced my.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 9 Aug 2001 10:46:50 +0100
From: "Stephen Edelblut" <viper16336@mindspring.com>
Subject: Where can I learn to do this?
Message-Id: <9kubf2$48d$1@slb7.atl.mindspring.net>

I know nothing about Perl/CGI. What I wanted to do is have a form on my site
that had two text field and  send button. One text-box would be 'name' and
the seond would be 'message'. What I want it to do is send the contents to a
*.txt file on the server as 'name':'message' line-by-line in the text file.
Where can I learn how to do this. Every example I've found involved very
complex forms and I could never figure out if they saved the info to a file
on the server. Thanks




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

Date: Thu, 09 Aug 2001 15:17:30 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Why?
Message-Id: <v295ntg5cosv7nhqj0mmal2d5m8e5ta0ep@4ax.com>

Paul Fortescue wrote:

>Thanks, Bart. I did RTFM but it is not easy for me to understand. I did not
>understand that while ($line=<HTML>) is the same thing as
>$line=readlne(*HTML). I think I will recode it like you say, but I still
>don't understand the difference between HTML and *HTML. I think it is
>something to do with referencing or typeglobs but I am new to Perl so I will
>struggle!

"New to perl"? Yet, typeglobs etc. are pretty advanced topics in my
view. I would have stayed away from them for at least the first few
months.

But, anyway, filehandles look like barewords. Ordinarily (unless
"strict" forbids it), if barewords are not keywords or (already defined)
user defined subs, Perl treats these as strings. I think that is what
happens. Only some built-ins expect a file handle for a parameter, and
recognize file handles as such. I think readline() is not amonst them,
but <...> is. In fact, I'm a bit surprised that readline() is even in
perlfunc (the keyword glossary), as I would have thought it is actually
a method belonging to the IO::Handle module. Er... which it isn't...?
Anyway: treating a bareword (string) as a handle actually often works as
a form of symbolic reference. So I do think 

	readline HTML

is interpreted as

	readline "HTML"

which may succeed, or fail, depending on, er, the phases of the moon or
something. It's all pretty vague and unchartered territory. I wouldn't
go there. Anyway, it WILL fail if you try to use it in another package.

But a typeglob, or even a reference to a typeglob ( \*HTML ) can always
be used, passed, and interpreted as a filehandle. I think.

BTW the "<HANDLE>" syntax instead of the function call is invented as a
handy shortcut, because I/O is used so very often. It may look a bit
weird at first, but it is indeed very handy.

>If the manual was like Windows instead of like UNIX :) ...

If you have a perl for Windows, then the docs are on your disk as html
as well. Now, search for a HTML file in perl's file tree, whose bare
name is "perlop" (perl operators), and go to the section on
IO-operators.  Skip the paragraph on backticks (I wonder why *that* is
there upfront?), and start reading.

-- 
	Bart.


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

Date: 09 Aug 2001 17:49:24 +0100
From: nobull@mail.com
Subject: Re: Write to middle of file
Message-Id: <u9d7656uwb.fsf@wcl-l.bham.ac.uk>

"Sean Hamilton" <sh@planetquake.com> writes:

> I have a fairly large (50+mb) file, into which I wish to write.
> 
> I'd rather not read the whole thing into memory, modify, clear, write, for
> obvious reasons.
> 
> The logical thing to do seems to be:
> 
> Open file A for reading.
> Apply shared lock onto A.
> Open temp file B for writing.
> Apply exclusive lock onto B.
> Write A into B until arriving at the point at which stuff needs to be
> written.
> Write new stuff to B.
> Write A into B until eof.

Yes that is more or less the logical approach, provided the name of
file B is always the same so that you can't have two processes
simulateously writing two different file Bs.  Also you must not open A
until after you open and lock B as there would otherwise be a race
condition allowing you to undo a previous change.

This is independant of your choice of language and has nothing to do
with Perl.

> Now here is the problem: I should then delete A and rename B to A. However,
> I fear the brief period of time in which A is absent will break
> things.
>
> Ideas?

Don't delete A.  If your OS can't atomically to rename B to A
implictly deleting the old A in the process (but allowing any
processes already reading the old A to continue to do so) then that's
a deficiency of your OS.  You'll need some sort of external semaphore
that all processes that read A agree to consult before they try to
read A.

This is independant of your choice of language and has nothing to do
with Perl.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

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.  

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


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