[19281] in Perl-Users-Digest
Perl-Users Digest, Issue: 1476 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 9 11:05:37 2001
Date: Thu, 9 Aug 2001 08: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)
Message-Id: <997369508-v10-i1476@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 9 Aug 2001 Volume: 10 Number: 1476
Today's topics:
Advise on using perl to sort and give totals <sammy@bigpond.net.au>
angle operator interaction with getopts? (Seymour J.)
error with signal handling (yawnmoth)
Re: error with signal handling <tinamue@zedat.fu-berlin.de>
Re: error with signal handling (Martien Verbruggen)
Re: error with signal handling <friedman@math.utexas.edu>
Re: How to get Mac and IP address of computers over a n <bowman@montana.com>
Re: how to get perlscript (Helgi Briem)
Re: Is it a number? <philippe.perrin@sxb.bsf.alcatel.fr>
list in scalar context: what's the expression to count (John Lin)
Math::BigInt Doesn't Work!!!! <Jeff@aetherweb.co.uk>
Re: NET::FTP and other file operations (Anno Siegel)
Re: NET::FTP and other file operations <gerhardpremovethis@inch.com>
Oracle: Inserting BLOBs. <bill.kemp@wire2.com>
Parsing a HTML page <Pcmann1@btinternet.com>
Re: perl - write text file to server help (Martien Verbruggen)
Re: perldoc is like Greek to a beginner?? <mjcarman@home.com>
Re: perldoc is like Greek to a beginner?? <joe+usenet@sunstarsys.com>
Re: q: converting strings <krahnj@acm.org>
Re: Sub that defaults to use $_ in callers context <ilya@martynov.org>
Re: Sub that defaults to use $_ in callers context <bjoern@hoehrmann.de>
Re: Sub that defaults to use $_ in callers context <joe+usenet@sunstarsys.com>
Re: Uppercasing extended characters <Francisco.Alcala@undcp.orgg>
Win32::eventlog -- Help!?!?! (JB Lewis)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 09 Aug 2001 14:01:38 GMT
From: "sammy" <sammy@bigpond.net.au>
Subject: Advise on using perl to sort and give totals
Message-Id: <6Jwc7.104678$Xr6.538189@news-server.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
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
------------------------------
Date: Thu, 09 Aug 2001 09:31:16 -0400
From: "Shmuel (Seymour J.) Metz" <spamtrap@library.lspace.org.invalid>
Subject: angle operator interaction with getopts?
Message-Id: <3b7290a4$13$fuzhry$mr2ice@va.news.verio.net>
I want to write a Perl script that accepts a list of files and also
accepts options. The camel doeswn't say whether getopts shifts out the
options as it parses them. If I call getopts prior to using <>, will
that ensure that the options aren't misinterpreted as file references?
--
-----------------------------------------------------------
Shmuel (Seymour J.) Metz, SysProg and JOAT
Atid/2
Team OS/2
Team PL/I
Any unsolicited commercial junk E-mail will be subject to legal
action. I reserve the right to publicly post or ridicule any
abusive E-mail.
I mangled my E-mail address to foil automated spammers; reply to
domain acm dot org user shmuel to contact me. Do not reply to
spamtrap@library.lspace.org
-----------------------------------------------------------
------------------------------
Date: 9 Aug 2001 07:05:25 -0700
From: terra1024@yahoo.com (yawnmoth)
Subject: error with signal handling
Message-Id: <a0d63404.0108090605.28039dd6@posting.google.com>
I wrote a script to test signal handling, and...
it doesn't seem to work (as in, when I hit a break key - crtl+c, or
whatever, it doesn't say ending, and it doesn't stop).
How can I fix this?
#!/usr/bin/perl
$SIG{INT} = \&end;
run();
sub run {
while (1) {
print "blah\n";
}}
sub end {
$SIG{INT} = \&end;
print "ending\n";
die;
}
------------------------------
Date: 9 Aug 2001 14:35:12 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: error with signal handling
Message-Id: <9ku730$6ecis$2@fu-berlin.de>
yawnmoth <terra1024@yahoo.com> wrote:
> I wrote a script to test signal handling, and...
> it doesn't seem to work (as in, when I hit a break key - crtl+c, or
> whatever, it doesn't say ending, and it doesn't stop).
> How can I fix this?
> $SIG{INT} = \&end;
> run();
> sub run {
> while (1) {
> print "blah\n";
> }}
> sub end {
> $SIG{INT} = \&end;
> print "ending\n";
> die;
> }
well, it works for me:
This is perl, version 5.005_03 built for sun4-solaris
--
http://www.tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
--- Warning: content of homepage hopelessly out-dated ---
------------------------------
Date: Fri, 10 Aug 2001 00:41:42 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: error with signal handling
Message-Id: <slrn9n5896.cq.mgjv@martien.heliotrope.home>
On 9 Aug 2001 07:05:25 -0700,
yawnmoth <terra1024@yahoo.com> wrote:
> I wrote a script to test signal handling, and...
> it doesn't seem to work (as in, when I hit a break key - crtl+c, or
> whatever, it doesn't say ending, and it doesn't stop).
Your program works absolutely fine for me on Linux and all versions of
Perl (>5) I have installed here (5.004_05, 5.005_03, 2 versions of
5.6.0, 5.6.1 and 5.7.0)
Are you sure your interrupt key is ctrl-c? Maybe its something else. If
you're on a unix-like system, try something like:
$ stty -a
and see what it says for intr. (your version of stty may require a
different argument to list all current settings)
If you're on another system, maybe you should mention it. it is probably
important.
Martien
--
Martien Verbruggen |
Interactive Media Division | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd. | make up 3/4 of the population.
NSW, Australia |
------------------------------
Date: Thu, 9 Aug 2001 09:49:56 -0500
From: "Chas Friedman" <friedman@math.utexas.edu>
Subject: Re: error with signal handling
Message-Id: <9ku7tr$cpi$1@geraldo.cc.utexas.edu>
yawnmoth <terra1024@yahoo.com> wrote in message
news:a0d63404.0108090605.28039dd6@posting.google.com...
> I wrote a script to test signal handling, and...
> it doesn't seem to work (as in, when I hit a break key - crtl+c, or
...
I works fine for me on Windows and Linux. However, I don't see why you
need to re set $SIG{INT}=\&end inside the definition of the sub end.
You might try putting a sleep statement inside your loop. Your machine
may be so busy executing the loop that it ignores the <CTRL>C. [That
has happened to me (on Windows.)]
cf
------------------------------
Date: Thu, 9 Aug 2001 07:22:12 -0600
From: "bowman" <bowman@montana.com>
Subject: Re: How to get Mac and IP address of computers over a network?
Message-Id: <a8wc7.99$h%3.119580@newsfeed.slurp.net>
"Helgi Briem" <helgi@NOSPAMdecode.is> wrote in message
news:3b727bba.1481552429@news.isholf.is...
>
> >
> I don't know what nmap is. It does not seem to exist
> on my Linux and Solaris systems.
it is a program that, among other things, will display the port usage (yours
or some other host) in a nicely formatted output. Nice tool to see what sort
of exploitable ports are open for business from your default installation.
well worth getting the tarball if you don't have it on your system.
------------------------------
Date: Thu, 09 Aug 2001 13:44:29 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: how to get perlscript
Message-Id: <3b729318.1487535182@news.isholf.is>
On Thu, 9 Aug 2001 09:28:16 +0100 , "Bell, Leslie"
<lbell@essex.ac.uk> wrote:
>I have perl installed on an NT server running IIS, which tells me that
>perlscript is not available (for .asp pages). I don't want to install
>ActiveState perl because you can't choose the directory, and I want it
>to stay in C:\winnt\local\perl\bin.
Move it. Then change your environment variables to reflect
the new path. Voila.
>Do you have to use ActiveState to get perlscript, or is there another
>way? And what is that other way, if there is one?
I don't know what a perlscript is. Doubtless an internet
search engine would help me find out if I were
remotely interested.
Regards,
Helgi Briem
------------------------------
Date: Thu, 09 Aug 2001 16:01:38 +0200
From: Philippe PERRIN <philippe.perrin@sxb.bsf.alcatel.fr>
Subject: Re: Is it a number?
Message-Id: <3B7297C2.897551F3@sxb.bsf.alcatel.fr>
for integers : $x =~ /^\d+$/;
for float : $x =~ /^(\d+)(\.?)(\d*)$/;
Terry wrote:
>
> Hello,
>
> 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?
>
> TIA
>
> Terry
> --
> remove nospam to reply
--
PhP
------------------------------
Date: 9 Aug 2001 07:44:06 -0700
From: johnlin@chttl.com.tw (John Lin)
Subject: list in scalar context: what's the expression to count its elements?
Message-Id: <a73bcad1.0108090644.2958afad@posting.google.com>
Dear all,
For a constant list sub:
sub foo { 6,7,8 }
I know the STATEMENT to count its elements:
my $count =()= foo; # result is 3
But what about the EXPRESSION?
For example, I use the following expression:
scalar @{[foo]} to count the elements, which is 3
Therefore, I can write
sub list { 0..@{[foo]} } # I want 0..3
sub add { @{[list]} + @{[foo]} } # I want 4 + 3
print list,add;
__END__
01237
Yes, the ugly code can get what I want.
But will perl stupidly construct an anonymous array to count?
Is there a better EXPRESSION for this?
Thank you very much.
John Lin
------------------------------
Date: Thu, 9 Aug 2001 15:35:09 +0100
From: "Jeff Snoxell" <Jeff@aetherweb.co.uk>
Subject: Math::BigInt Doesn't Work!!!!
Message-Id: <9ku74k$1ns$1@uranium.btinternet.com>
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?
TIA
Jeff
------------------------------
Date: 9 Aug 2001 13:08:38 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: NET::FTP and other file operations
Message-Id: <9ku20m$9el$4@mamenchi.zrz.TU-Berlin.DE>
According to Gerhard <gerhardpremovethis@inch.com>:
> 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?
No. Well, I don't know Net::FTP specifically, but I'd be very amazed.
What happens when you try to print to the log file? Do you see an
error? Have you tried 'print( ...) or die "print failed: $!\n";'?
Have you thought of buffering? (Try $| = 1 for the logfile).
Anno
------------------------------
Date: Thu, 9 Aug 2001 09:55:34 -0400
From: "Gerhard" <gerhardpremovethis@inch.com>
Subject: Re: NET::FTP and other file operations
Message-Id: <9ku4im$6bsjg$1@ID-35855.news.dfncis.de>
No error whatsoever. The actual behaviour is, it logs just fine when I
comment out the 'get' line, but once I enable the get, nothing is written to
the file. And I mean absolutely nothing. But the file will be created.
I'm just baffled. I'll try your suggestions when I'm back in the office.
Gerhard
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:9ku20m$9el$4@mamenchi.zrz.TU-Berlin.DE...
> According to Gerhard <gerhardpremovethis@inch.com>:
> > 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?
>
> No. Well, I don't know Net::FTP specifically, but I'd be very amazed.
> What happens when you try to print to the log file? Do you see an
> error? Have you tried 'print( ...) or die "print failed: $!\n";'?
> Have you thought of buffering? (Try $| = 1 for the logfile).
>
> Anno
------------------------------
Date: Thu, 9 Aug 2001 14:02:24 +0100
From: "W K" <bill.kemp@wire2.com>
Subject: Oracle: Inserting BLOBs.
Message-Id: <tUvc7.268$t97.2834@news.uk.colt.net>
OK. Read the man page, and I can and do Insert BLOBS/Longs into Oracle.
However, I can't find out if there is a nice way to insert large blobs.
By this I mean not putting the entire chunk of binary data in one go by
just doing one "insert", rather inserting it chunk by chunk.
It seems rather memory intensive to just put a full 1MB file in by this way,
and I could get away with it (just about), but there is the possiblity that
I might have to insert something that is even bigger than this.
------------------------------
Date: Thu, 9 Aug 2001 14:26:35 +0100
From: "Peter Mann" <Pcmann1@btinternet.com>
Subject: Parsing a HTML page
Message-Id: <9ku30p$jfu$1@uranium.btinternet.com>
Dear all,
I am writing a program that parses a html pages and extracts links and
performs validation of these links and generally reports the properties of
the page. However, I was wondering if there is any module avaialble to help
determine any embedded technologies within the html page such as javascript,
php, VBscript etc.
I need to automatically compile a report describing all relevant properties
of a particular html page.
Thanks in advance
Pete
------------------------------
Date: Fri, 10 Aug 2001 00:29:20 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: perl - write text file to server help
Message-Id: <slrn9n57i0.cq.mgjv@martien.heliotrope.home>
On 9 Aug 2001 05:59:26 -0700,
Charlie Abbott <charlie@disc7.com> wrote:
> hi folks,
>
> does anyone know of a free or pay perl script that will write and
> update a text file to a server? also it would need a redirect once the
> file has been updated.
Even if we knew what you were asking[1] we probably wouldn't help you.
To find programs, you should use searchengines and such. This newsgroup
tends to talk about Perl, the language. Not about all possible programs
that may happen to have been written in Perl[2].
If you're interested in solving your problem by actually writing a
program, please come back once you have written something and you are
stuck. When you do, make sure that you actually specify what you are
trying to do in a way that a programmer (most of us are) can understand.
Martien
[1] Your problem is totally underspecified. What do you mean with 'write
and update'? What do you mean by 'to a server'? What do you mean by
'need a redirect'? Are you talking about CGI? If so, make sure that you
first understand CGI (and NO, this is not the place to ask or learn
about CGI).
[2] I'm boldly assuming that you wanted a program written in Perl. If
not, then you are totally and utterly offtopic, and you should be
ashamed of yourself.
--
Martien Verbruggen |
Interactive Media Division | We are born naked, wet and hungry.
Commercial Dynamics Pty. Ltd. | Then things get worse.
NSW, Australia |
------------------------------
Date: Thu, 09 Aug 2001 08:01:45 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <3B7289B9.373123B7@home.com>
"Carlos C. Gonzalez" wrote:
>
> What I was referring to was the way computereese seems to be all
> over the place in the documentation. For someone like me from
> a non-CS background it's a bit tough. Not impossible. Just a
> bit tough and frustrating.
You've wandered into a computer field; you should expect to encounter
computerese. Every discipline has its own vocabulary. Within its circles
words take on slightly different meanings from their colloquial usage,
and usually very precise ones. This vocabulary allows us to have
effective conversations. The documentation is written by users for
users, so it reads the same way.
This is all very hard for beginners, but makes life a lot easier once
you get a grip on it.
-mjc
PS: For what it's worth, I don't have a CS background, either. My formal
training in programming is limited to a single semester of C. Hang in
there.
------------------------------
Date: 09 Aug 2001 10:22:52 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <m3hevhcnyb.fsf@mumonkan.sunstarsys.com>
Michael Carman <mjcarman@home.com> writes:
> You've wandered into a computer field; you should expect to encounter
> computerese. Every discipline has its own vocabulary. Within its circles
> words take on slightly different meanings from their colloquial usage,
> and usually very precise ones. This vocabulary allows us to have
> effective conversations. The documentation is written by users for
> users, so it reads the same way.
Yes- and a good book written at an appropriate level goes a long way
towards bridging the language gap. A google search of this ng should
turn up lots of recommendations. Also, last time I checked, I noticed
a few recommended authors hang out on the beginners mailing list at
http://learn.perl.org/
so you can get lots of great help there as well.
--
Joe Schaefer "Few things are harder to put up with than the annoyance of a
good example."
--Mark Twain
------------------------------
Date: Thu, 09 Aug 2001 14:39:26 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: q: converting strings
Message-Id: <3B72A09E.346EBFCA@acm.org>
Jasper McCrea 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, and you disagree. I find
> that extremely odd.
It looks like a _word_ to me.
> Would you say I was in a minority if I said that 'aebbc' looked like a
> number, too?
>
> All I should have said was that if you really want it to, perl will
> convert your string into something it can perform numerical operations
> on, if you ask it too. It's just that if your string contains anything
> other than digits, you mightn't get what you want, possibly quite
> rightly (up to Larry, I guess).
>
> 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";
You are confusing auto-increment with addition.
John
--
use Perl;
program
fulfillment
------------------------------
Date: 09 Aug 2001 17:06:34 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Sub that defaults to use $_ in callers context
Message-Id: <87pua5757p.fsf@abra.ru>
YO> Hi All,
YO> Just curious if anyone knows how to get access to the callers $_ so
YO> that it can be used as a default like so many keywords do?
YO> I tried to do it directly by
YO> sub func {
YO> my $param=shift || $_;
YO> }
YO> but obviously this doesnt work as $_ is automatically localized to the
YO> sub (at least im pretty sure I read that somwhere.) Either way though
YO> it didnt work.
At least in Perl 5.6.1 $_ is not automatically localized:
#!/usr/bin/perl -w
use strict;
$_ = 'test';
test();
sub test {
print $_;
}
prints 'test' for me.
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| 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: Thu, 09 Aug 2001 15:53:58 +0200
From: Bjoern Hoehrmann <bjoern@hoehrmann.de>
Subject: Re: Sub that defaults to use $_ in callers context
Message-Id: <3c02906c.71455277@news.bjoern.hoehrmann.de>
* Yves Orton wrote in comp.lang.perl.misc:
>Just curious if anyone knows how to get access to the callers $_
As
% perl -wmstrict -MData::Dumper -e "
sub x { print Dumper [ \@_, [caller], [\%::]] } sub t { x } t 10"
kindly demonstrates, you don't have access to the callers $_ unless you
pass it to the called sub routine or store it somewhere where the sub
routine has access to it.
But maybe I misunderstood your question...
--
print just another perl hacker q;s/^\w+_}/ #+--- regards, Björn Höhrmann
;;sub _{reverse split q=:+==>[caller${\1}] #| mailto:bjoern@hoehrmann.de
->[3]};;sub another::just{shift&&join q> > #| http://www.bjoernsworld.de
=>_,@_};package hacker;sub perl{_}$0=~m(_) #+ http://bjoern.hoehrmann.de
------------------------------
Date: 09 Aug 2001 09:55:35 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Sub that defaults to use $_ in callers context
Message-Id: <m3lmktcp7s.fsf@mumonkan.sunstarsys.com>
Ilya Martynov <ilya@martynov.org> writes:
> Yves Orton wrote:
> YO> Hi All,
> YO> Just curious if anyone knows how to get access to the callers $_ so
> YO> that it can be used as a default like so many keywords do?
>
> YO> I tried to do it directly by
>
> YO> sub func {
> YO> my $param=shift || $_;
> YO> }
>
> YO> but obviously this doesnt work as $_ is automatically localized to the
> YO> sub (at least im pretty sure I read that somwhere.) Either way though
> YO> it didnt work.
$_ isn't auto-localized for subs; but @_ is (for obvious reasons).
Assuming you're not trying to modify your sub's args, AFAICT the
only problem with the above is that
$_ = 1;
func(0);
will set $param=1 in the sub. You probably want 0 here, so a
conditional like
sub func {
my $param = @_ ? $_[0] : $_;
...
}
or
sub func {
my ($param) = (@_, $_);
...
}
might work better. If there's still a problem, perhaps a more
explicit example is appropriate.
> At least in Perl 5.6.1 $_ is not automatically localized:
Right. TMTOWTDI, but for subs that *modify* their arguments uniformly,
and default to act on $_, I often use the following idiom:
sub modify {
for (@_ ? @_ : $_) {
# code to modify $_ goes here
}
}
e.g.
sub increment {
++$_ for @_ ? @_ : $_;
}
HTH
--
Joe Schaefer "Sacred cows make the best hamburger."
--Mark Twain
------------------------------
Date: Thu, 9 Aug 2001 15:21:40 +0200
From: "Curro" <Francisco.Alcala@undcp.orgg>
Subject: Re: Uppercasing extended characters
Message-Id: <_7wc7.2$%X.117@stuart.coltnet.at>
"Ilya Martynov" <ilya@martynov.org> wrote in message
news:873d718kd8.fsf@abra.ru...
>
>
> C> Does this have anything to do with my locale? This is the only thing I
> C> haven't played around with.
>
> Short answer: add 'use locale' to your script. If you locale is
> configured your script will work. Read 'perldoc perllocale' for more
> info.
Actually I had tried this already yesterday, even POSIX::locale_h's
setlocale, but to no avail. 'perllocale' is good, but I don't really know
how to fix my operating system. Anybody on how to set my locale on Solaris
2.6? (Sorry about the bother, where to look will be enough...)
Curro
------------------------------
Date: 9 Aug 2001 07:55:09 -0700
From: jblewisoh@yahoo.com (JB Lewis)
Subject: Win32::eventlog -- Help!?!?!
Message-Id: <9387eabc.0108090655.2732955c@posting.google.com>
Has anybody been able to actually retrieve the message text of an
event log item?
Here's the code I'm trying to use, but it always comes back that the
GetMessageText failed.
#!/perl/bin/perl.exe
use strict;
use warnings;
use Win32::EventLog;
use Time::Local 'timelocal';
$Win32::EventLog::GetMessageText = 1;
my ($handle, $recs, $base, $hashRef);
my $x = 0;
$handle=Win32::EventLog->new("System", "\\\\stp-ras1")
or die "Can't open Application EventLog\n";
$handle->GetNumber($recs)
or die "Can't get number of EventLog records\n";
print "$recs\n";
$handle->GetOldest($base)
or die "Can't get number of oldest EventLog record\n";
print "$base\n";
#while ($x < $recs) {
while ($x < 10) {
$handle->Read(EVENTLOG_FORWARDS_READ|EVENTLOG_SEEK_READ,
$base+$x,
$hashRef)
or die "Can't read EventLog entry #$x\n";
print "$hashRef->{Category}\n";
if ($hashRef->{Source} eq "Router") {
Win32::EventLog::GetMessageText($hashRef) || die
"Unable to get message from event $x\n";
print "Entry $x: $hashRef->{Message}\n";
}
$x++;
}
Is it something I'm doing wrong, or not doing at all, or what?
TIA
JBLewis
------------------------------
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 1476
***************************************