[23922] in Perl-Users-Digest
Perl-Users Digest, Issue: 6123 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 12 14:10:51 2004
Date: Thu, 12 Feb 2004 11:10:12 -0800 (PST)
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, 12 Feb 2004 Volume: 10 Number: 6123
Today's topics:
Perl Sockets Parent/Child Problem (Ken Browning)
Re: Perl Sockets Parent/Child Problem <nobull@mail.com>
Re: Perl Sockets Parent/Child Problem <kenbrow@bellsouth.net>
Re: Perl Sockets Parent/Child Problem <usenet@morrow.me.uk>
Perl Sort Routine (Arthur)
Re: Perl Sort Routine <tony_curtis32@_SPAMTRAP_yahoo.com>
Re: Perl Sort Routine <ittyspam@yahoo.com>
Re: Perl usage these days? <nobody@somewhere-else.com>
Re: Perl usage these days? <minter@lunenburg.org>
Perl.exe Question (IBaker)
Re: Perl.exe Question <ben@liddicott.com>
Re: Regular Expression Help Needed (Deja User)
Re: Regular Expression Help Needed (Deja User)
Re: Regular Expression Help Needed <bruce-news@hartweg.us>
Re: Regular Expression Help Needed <Chris@Sonnack.com>
Re: Regular Expression Help Needed <barmar@alum.mit.edu>
Replacing unicode characters <eriks@operamail.com>
Re: Replacing unicode characters <usenet@morrow.me.uk>
Re: RFC: utils.pm <tore@aursand.no>
Re: RFC: utils.pm <noreply@gunnar.cc>
Re: strange behaviour with map inside a hash <nospam@nospam.org>
Re: strange behaviour with map inside a hash <nospam@nospam.org>
Re: strange behaviour with map inside a hash <nospam@nospam.org>
Test message, please ignore. (zak zebrowski)
Test message, please ignore. (zak zebrowski)
Re: Test message, please ignore. <1usa@llenroc.ude>
tying hashes <yshtil@cisco.com>
Re: tying hashes <usenet@morrow.me.uk>
Re: Using Tie::IxHash order a hash reference (Darius)
Re: Why is Perl losing ground? (Randal L. Schwartz)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 12 Feb 2004 09:25:06 -0800
From: kenbrow@bellsouth.net (Ken Browning)
Subject: Perl Sockets Parent/Child Problem
Message-Id: <113d29a5.0402120925.381a9e9a@posting.google.com>
(Source at end of question)
Given this source, I am able to connect to the server, but when I try
to send data to the child process, it never seems to get there...any
suggestions?
use IO::Select;
use IO::Socket;
##############################################################
my ($host, $port, $kidpid, $handle, $line);
unless (@ARGV == 2) { die "usage: $0 host port" }
($host, $port) =@ARGV;
$handle=IO::Socket::INET->new (Proto => "tcp",
PeerAddr => $host,
PeerPort => $port)
or die "can't connect to $port on $host: $!";
$handle->autoflush(1);
print STDERR "[Connected to $host:$port]\n";
#die "can't fork: $!" unless defined($kidpid=fork());
$kidpid = open (KID_TO_WRITE, "|-");
unless (defined $kidpid) {
die "can't fork: $!"
}
if($kidpid){ #parent process
print $handle "0=1.3\n";
printf("sent: 0=1.3\n");
while (defined ($line = <$handle>)) {
chomp($line);
printf("RECV: %s\n",$line);
printf( KID_TO_WRITE "test %s\n",$line);
print KID_TO_WRITE "[this is a test]" ;
printf( "printed to child process...: %s\n",$line);
}
kill ("TERM" => $kidpid);
}else{ #child process
printf( STDERR "Inside child process...\n");
while (defined ($line = <STDIN>)) {
print STDERR "Inside loop : $line";
print STDERR "SEND: $line";
}
printf( STDERR "Exiting child process...\n");
exit;
}
exit;
------------------------------
Date: 12 Feb 2004 17:45:29 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Perl Sockets Parent/Child Problem
Message-Id: <u9hdxwkx8m.fsf@wcl-l.bham.ac.uk>
kenbrow@bellsouth.net (Ken Browning) writes:
> Subject: Re: Perl Sockets Parent/Child Problem
I don't think sockets are relevant. You should always try to reduce
your problem to it's mimimal form. Did you try just the parent/child
part on it's own?
> Given this source, I am able to connect to the server, but when I try
> to send data to the child process, it never seems to get there...any
> suggestions?
I suggest not killing the child before the data gets there.
> $kidpid = open (KID_TO_WRITE, "|-");
> while (defined ($line = <$handle>)) {
> chomp($line);
> printf("RECV: %s\n",$line);
> printf( KID_TO_WRITE "test %s\n",$line);
> print KID_TO_WRITE "[this is a test]" ;
> printf( "printed to child process...: %s\n",$line);
> }
> kill ("TERM" => $kidpid);
You never unbuffered KID_TO_WRITE so at this point all the data is
probably in a buffer.
You should simply close KID_TO_WRITE once you've written the data to it.
------------------------------
Date: Thu, 12 Feb 2004 12:05:55 -0600
From: Ken Browning <kenbrow@bellsouth.net>
Subject: Re: Perl Sockets Parent/Child Problem
Message-Id: <1rfn20pp1mhvr2tb4r00kbcgm3scbn0cu2@4ax.com>
On 12 Feb 2004 17:45:29 +0000, Brian McCauley <nobull@mail.com> wrote:
>kenbrow@bellsouth.net (Ken Browning) writes:
>
>> Subject: Re: Perl Sockets Parent/Child Problem
>
>I don't think sockets are relevant. You should always try to reduce
>your problem to it's mimimal form. Did you try just the parent/child
>part on it's own?
>
>> Given this source, I am able to connect to the server, but when I try
>> to send data to the child process, it never seems to get there...any
>> suggestions?
>
>I suggest not killing the child before the data gets there.
>
>> $kidpid = open (KID_TO_WRITE, "|-");
>
>> while (defined ($line = <$handle>)) {
>> chomp($line);
>> printf("RECV: %s\n",$line);
>> printf( KID_TO_WRITE "test %s\n",$line);
>> print KID_TO_WRITE "[this is a test]" ;
>> printf( "printed to child process...: %s\n",$line);
>> }
>> kill ("TERM" => $kidpid);
>
>You never unbuffered KID_TO_WRITE so at this point all the data is
>probably in a buffer.
>
>You should simply close KID_TO_WRITE once you've written the data to it.
Thank you for your input....I agree that sockets have nothing to do
with it, but my program is a socket program, thus the title...
I tried close(KID_TO_WRITE) (after writing to it) and that flushed the
buffer and the child process received the data. What I need to do is
keep that open until I have received a close indication from the
server. Is there a way to flush that buffer _without_ closing
KID_TO_WRITE?
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
------------------------------
Date: Thu, 12 Feb 2004 18:20:11 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Perl Sockets Parent/Child Problem
Message-Id: <c0gg4r$f34$3@wisteria.csv.warwick.ac.uk>
Ken Browning <kenbrow@bellsouth.net> wrote:
> Thank you for your input....I agree that sockets have nothing to do
> with it, but my program is a socket program, thus the title...
But your problem is not a socket problem, hence the subject was wrong.
> I tried close(KID_TO_WRITE) (after writing to it) and that flushed the
> buffer and the child process received the data. What I need to do is
> keep that open until I have received a close indication from the
> server. Is there a way to flush that buffer _without_ closing
> KID_TO_WRITE?
Put
select((select(KID_TO_WRITE), $|=1)[0]);
before you do the print.
Ben
--
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~ Jorge Luis Borges, 'The Babylon Lottery'
------------------------------
Date: 12 Feb 2004 08:45:25 -0800
From: amerar@iwc.net (Arthur)
Subject: Perl Sort Routine
Message-Id: <8b622eae.0402120845.1caabba3@posting.google.com>
Hi All,
I pulled this sort routine off from one of the postings. It works
well, but I was hoping someone could actually explain to me exactly
what it is doing:
@in = qw(one two two four seven four five one six);
@out = sort grep(!$saw{$_}++, @in);
print "@out";
I'm lost with this line: @out = sort grep(!$saw{$_}++, @in);
What is !$saw($_)++ ???
Thanks,
Arthur
------------------------------
Date: Thu, 12 Feb 2004 10:46:56 -0600
From: Tony Curtis <tony_curtis32@_SPAMTRAP_yahoo.com>
Subject: Re: Perl Sort Routine
Message-Id: <87ptck5jpb.fsf@limey.hpcc.uh.edu>
>> On 12 Feb 2004 08:45:25 -0800,
>> amerar@iwc.net (Arthur) said:
> I'm lost with this line: @out = sort grep(!$saw{$_}++, @in);
"perldoc -q duplicate"
hth
t
------------------------------
Date: Thu, 12 Feb 2004 11:51:50 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Perl Sort Routine
Message-Id: <20040212114647.M23965@dishwasher.cs.rpi.edu>
On Thu, 12 Feb 2004, Arthur wrote:
> Hi All,
>
> I pulled this sort routine off from one of the postings. It works
> well, but I was hoping someone could actually explain to me exactly
> what it is doing:
>
> @in = qw(one two two four seven four five one six);
> @out = sort grep(!$saw{$_}++, @in);
> print "@out";
>
> I'm lost with this line: @out = sort grep(!$saw{$_}++, @in);
>
> What is !$saw($_)++ ???
>
> Thanks,
>
> Arthur
>
The line is sorting and returning elements of @in for which !$saw{$_}++ is
true. The grep goes through each element of @in, assigning each one to $_.
The first time each individual element is encountered, it is inserted as
the key to a hash %saw. It is inserted by taking advantage of
autovivification. That is, $saw{'one'}++ both creates the key 'one' in
the hash %saw, and immediately increments the value of that key. Since
'one' was previously not in the hash, the value was originally undef
(which gets treated as 0 by the ++ operator), and gets inremented to 1.
However, because the postfix form of ++ is being used, the expression
returns the value before incrementation - which is undef. The ! then
swaps that boolean, to make the entire !$saw{$_}++ expression return true.
The second and subsequent times the same value is seen, the position in
the hash already exists with a value of (at least) 1, and so the
expression returns a false value.
Therefore, the whole line is returning a sorted list of unique values from
the array @in.
Paul Lalli
------------------------------
Date: Thu, 12 Feb 2004 16:04:37 -0000
From: "Pope Bob" <nobody@somewhere-else.com>
Subject: Re: Perl usage these days?
Message-Id: <102n90ldjlj3ca8@corp.supernews.com>
Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de> wrote:
>Pope Bob wrote:
>> Brad Baxter wrote:
>>>Perl isn't declining. It's the most-used language in the world, and its
>>>market share increases daily.
>> What do you base your statement upon?
>>
>> All such generalizations are wrong, including this one....
> ^^^
> nice one! :-) Was the joke intentional (no smiley) ?
Joke. Though its probably true... :-)
------------------------------
Date: Thu, 12 Feb 2004 16:51:45 GMT
From: "H. Wade Minter" <minter@lunenburg.org>
Subject: Re: Perl usage these days?
Message-Id: <BaOWb.1339$%d3.283438@twister.southeast.rr.com>
thumb_42@yahoo.com wrote:
> Just a curious question:
>
> What is perl being used for these days?
>
> Seems almost everything web related I see is PHP or Java. (mostly PHP)
>
> My own experience is that Perl is wonderful for batch processing, command
> line stuff, cron and specialized servers but compared to what is available
> today, really doesn't seem suitable for serious web applications anymore.
>
> So... what are people doing with it? is it still alive? Do people actually
> get paid to work in perl, or is it strictly a labor of love?
I wrote a frontend for the audio system at an improv comedy club in Perl/Tk.
It interfaces between a MySQL backend and an XMMS frontend, and runs under
X11 or Win32.
http://www.lunenburg.org/mrvoice/
The great GUI bindings, combined with the vast module selection and Perl's
ease of use, let me get a very useful and functional app up and running in
a short period of time.
--Wade
------------------------------
Date: 12 Feb 2004 03:32:48 -0800
From: ian.baker@pncl.co.uk (IBaker)
Subject: Perl.exe Question
Message-Id: <d8b01f10.0402120332.1063b17a@posting.google.com>
Hello,
On a Windows 2000 Server box, perl.exe is using a high amount of
memory usage. Is there a way to find out which script is doing this as
there seem to be no obvious way through the task manager or the like.
Many thanks for any help in advance.
IB.
------------------------------
Date: Thu, 12 Feb 2004 13:36:53 +0000 (UTC)
From: "Ben Liddicott" <ben@liddicott.com>
Subject: Re: Perl.exe Question
Message-Id: <c0fvhk$60i$1@titan.btinternet.com>
If you download SysInternals' Process Explorer tool, it will allow you =
to see open files, including the current working directory of the =
script. This may help you to discover which script it is.
http://www.sysinternals.com/ntw2k/freeware/procexp.shtml
--=20
Cheers,
Ben Liddicott
"IBaker" <ian.baker@pncl.co.uk> wrote in message =
news:d8b01f10.0402120332.1063b17a@posting.google.com...
> Hello,
> On a Windows 2000 Server box, perl.exe is using a high amount of
> memory usage. Is there a way to find out which script is doing this as
> there seem to be no obvious way through the task manager or the like.
> Many thanks for any help in advance.
------------------------------
Date: 12 Feb 2004 06:58:30 -0800
From: dejauser@safe-mail.net (Deja User)
Subject: Re: Regular Expression Help Needed
Message-Id: <ba74bae9.0402120658.20b5feb7@posting.google.com>
Thanks for the help. Just to clear things up, this is NOT a homework
question.. I already graduated from collge in 94. I am just new to
regular expressions. I already did some research on the web and read
some tutorials.. but still having trouble.
------------------------------
Date: 12 Feb 2004 07:02:51 -0800
From: dejauser@safe-mail.net (Deja User)
Subject: Re: Regular Expression Help Needed
Message-Id: <ba74bae9.0402120702.99c5bdb@posting.google.com>
Here is my input and I am testing it in UltraEdit.. but your
suggestions don't seem to work. Am I doing anything wrong? I was
hoping that UltraEdit would highlight the matched lines.
INPUT
-----
32000806-001
91000883-xxx
64000343-394
20032043-001
31091003-003
90384334-092
10903103-033
20932002-934
This is my cat
cat is good
Test Point, DNI
TP, DO NOT INSTALL
DNI
34000000-343
------------------------------
Date: Thu, 12 Feb 2004 11:48:07 -0600
From: Bruce Hartweg <bruce-news@hartweg.us>
Subject: Re: Regular Expression Help Needed
Message-Id: <r%OWb.7$Uj6.4@dfw-service2.ext.ray.com>
Deja User wrote:
> Here is my input and I am testing it in UltraEdit.. but your
> suggestions don't seem to work. Am I doing anything wrong? I was
> hoping that UltraEdit would highlight the matched lines.
>
> INPUT
> -----
>
> 32000806-001
> 91000883-xxx
> 64000343-394
> 20032043-001
> 31091003-003
> 90384334-092
> 10903103-033
> 20932002-934
> This is my cat
> cat is good
> Test Point, DNI
> TP, DO NOT INSTALL
> DNI
> 34000000-343
There was a typo in the 2nd RE (had NO instead of DO) but other than that
the REs work (run the following:)
set RE1 {^(?!(90|91|31|32))}
set RE2 {DNI|DO NOT INSTALL}
set input {
32000806-001
91000883-xxx
64000343-394
20032043-001
31091003-003
90384334-092
10903103-033
20932002-934
This is my cat
cat is good
Test Point, DNI
TP, DO NOT INSTALL
DNI
34000000-343
}
foreach line [split $data \n] {
puts "Checking >> $line << :"
if {[regexp $RE1 $line]} {puts " Does NOT start with 90,91,31 or 32"}
if {[regexp $RE2 $line]} {puts " Contains DNI or DO NOT INSTALL"}
puts ""
}
Note that this is Tcl (since thats the newsgroup I read your question on)
and I don;t know Ultraedit, so the RE syntax could be slightly different
(as well as supoort for negative lookaheads) - so either the REs need
tweaked for Ultraedit, or there is something else in the settings beyaond
the RE for UltraEdit to highlight.
Bruce
------------------------------
Date: Thu, 12 Feb 2004 11:30:16 -0600
From: Programmer Dude <Chris@Sonnack.com>
Subject: Re: Regular Expression Help Needed
Message-Id: <402BB828.EA6D922C@Sonnack.com>
Deja User wrote:
> I am new to regular expressions and I can't seem to figure out
> following.
>
> (1) Regular expression should find a match, if the given string
> does NOT start with 90, 91, 31, or 32.
A pity about that "NOT". To find strings that match, you can just
do:
^((3[12])|(9[01])).*$
This is worth exploring if you're not too familiar with REs.
^((3[12])|(9[01])).*$ - the whole thing
^ - anchors RE to start of line
( ) - groups the two possible sub-patterns
( )|( ) - sub-pattern A *OR* sub-pattern B
3[12] - a "3" followed by a "1" or "2"
9[10] - a "9" followed by a "0" or "1"
.* - anything (i.e. rest of the line)
$ - anchors RE to end of line
NOTE: some systems require you to escape the grouping parentheses
and the "either/or" delimiter:
^\(\(3[12]\)\|\(9[01]\)\).*$
But the combination of the NOT and the double-digit prefixes makes
it a little harder. Something like this, perhaps:
^((9[^01])|(3[^12])|[^39]).*$
Broken out a bit:
^( (9[^01]) | (3[^12]) | [^39] ) .* $
This works by allowing lines that don't match.
^((9[^01])|(3[^12])|[^39]).*$ -
^( | | ).*$ - SOL, prefix, rest of line, EOL
(9[^01]) - "9" + NOT "0" or "1"
(3[^12]) - "3" + NOT "1" or "2"
[^39] - anything BUT NOT "3" or "9"
> (2) Find a match, if the string contains DNI or 'DO NOT INSTALL'
> anywhere in the string.
Easy:
(DNI)|(DO NOT INSTALL)
--
|_ CJSonnack <Chris@Sonnack.com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL |
|_____________________________________________|_______________________|
------------------------------
Date: Thu, 12 Feb 2004 13:09:03 -0500
From: Barry Margolin <barmar@alum.mit.edu>
Subject: Re: Regular Expression Help Needed
Message-Id: <barmar-CB1A94.13090312022004@comcast.ash.giganews.com>
In article <ba74bae9.0402120702.99c5bdb@posting.google.com>,
dejauser@safe-mail.net (Deja User) wrote:
> Here is my input and I am testing it in UltraEdit.. but your
> suggestions don't seem to work. Am I doing anything wrong? I was
> hoping that UltraEdit would highlight the matched lines.
Different programs use different regular expression matchers, and they
often have different advanced features. I believe the suggestions were
intended for TCL, since you cross-posted to comp.lang.tcl.
Which language are you really planning to use? Post just to that group,
and you should get an answer most appropriate to your needs.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
------------------------------
Date: Thu, 12 Feb 2004 19:13:32 +0100
From: Erik Sandblom <eriks@operamail.com>
Subject: Replacing unicode characters
Message-Id: <BC5180DC.1487C%eriks@operamail.com>
Hi
I'm trying to replace double quotation marks in a UTF-8 document:
$string =~ s#\x{201D}#”#g;
My script is in latin-1. Otherwise I would just try putting in the
characters literally.
I'm using Perl 5.8. Replacing windows characters works beautifully:
$string =~ s/\x93/“/g;
I thought using the character codes \x{201D}, meant you don't have to worry
about telling Perl what character encoding is being used. Is this not true?
Erik Sandblom
------------------------------
Date: Thu, 12 Feb 2004 18:26:59 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Replacing unicode characters
Message-Id: <c0gghj$f34$5@wisteria.csv.warwick.ac.uk>
Erik Sandblom <eriks@operamail.com> wrote:
>
> I'm trying to replace double quotation marks in a UTF-8 document:
>
> $string =~ s#\x{201D}#”#g;
How have you read in $string? If the file is UTF8, you need to tell
Perl so, or it will assume Latin1:
open my $FH, '<:utf8', $filename or die...;
or, better
open my $FH, '<:encoding(utf8)', $filename or die...;
as this will be more resiliant if the file isn't actually utf8.
Ben
--
Every twenty-four hours about 34k children die from the effects of poverty.
Meanwhile, the latest estimate is that 2800 people died on 9/11, so it's like
that image, that ghastly, grey-billowing, double-barrelled fall, repeated
twelve times every day. Full of children. [Iain Banks] ben@morrow.me.uk
------------------------------
Date: Thu, 12 Feb 2004 14:37:25 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: RFC: utils.pm
Message-Id: <pan.2004.02.12.13.22.23.14108@aursand.no>
On Thu, 12 Feb 2004 07:24:44 +0000, Uri Guttman wrote:
>> Do you mean that they should be the same? Just a reminder for you:
>> These functions ('now_*') does nothing else than grabbing the current
>> time, formatting it and returning it. How can values be skewed? I
>> only grab the time value once for each of them...!?
> my $now1 = now_day() ;
>
> midnight happens NOW!!!
>
> my $now2 = now_hour() ;
>
> my $timestamp = "$now1:$now2" ;
>
> that is not the value you expect. a bug. not a likely bug but
> effectively similar to a race condition.
Yeah, but wouldn't this actually be the same as doing:
my $date1 = strftime( 'whatever', localtime() );
# midnight occurs
my $date2 = strftime( 'whatever', localtime() );
The solution, of course, is to let the 'now()' function do the formatting
for you (ie. you only need to call it once):
my $format = '%DD%:%hh%';
my $timestamp = now( $format );
> yes, you did. you didn't understand the possibility of time changing
> between now*() calls.
Actually, I did. But as a programmer I'm aware of the possibilities of
race conditions, so I avoid them.
--
Tore Aursand <tore@aursand.no>
"I know not with what weapons World War 3 will be fought, but World War
4 will be fought with sticks and stones." -- Albert Einstein
------------------------------
Date: Thu, 12 Feb 2004 15:03:32 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: RFC: utils.pm
Message-Id: <c0g1bc$16pmpb$1@ID-184292.news.uni-berlin.de>
Tore Aursand wrote:
>
> my $date1 = strftime( 'whatever', localtime() );
> # midnight occurs
> my $date2 = strftime( 'whatever', localtime() );
Better done like:
my $time = time;
my $date1 = strftime( 'whatever', localtime($time) );
# midnight occurs
my $date2 = strftime( 'whatever', localtime($time) );
That takes care of the 'midnight problem' and is also more efficient,
since time() is only called once. Think Uri meant that also your
date/time functions should better take a time string as an argument.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 12 Feb 2004 08:46:31 -0500
From: "Christian Caron" <nospam@nospam.org>
Subject: Re: strange behaviour with map inside a hash
Message-Id: <c0g03n$sbv4@nrn2.NRCan.gc.ca>
"Michele Dondi" <bik.mido@tiscalinet.it> wrote in message
news:6q8l20hh08so5knkj3gllmq45perorqqvv@4ax.com...
> On Wed, 11 Feb 2004 16:14:13 -0500, "Christian Caron"
> <nospam@nospam.org> wrote:
> line and the last quoted line above suggest that you may want
> something like
>
> my %conversion = ('%W' => [ map { whatever } @whatever ],
> # ^ ^
> ...
>
That would return a hash of arrays for the first item, which is not exactly
what I was looking for. But thanks anyway!
Christian
------------------------------
Date: Thu, 12 Feb 2004 08:48:56 -0500
From: "Christian Caron" <nospam@nospam.org>
Subject: Re: strange behaviour with map inside a hash
Message-Id: <c0g089$sbv5@nrn2.NRCan.gc.ca>
"Uri Guttman" <uri@stemsystems.com> wrote in message
news:x73c9h702b.fsf@mail.sysarch.com...
> >>>>> "CC" == Christian Caron <nospam@nospam.org> writes:
>
>
> '%W' => do { my $woy = (Week_of_Year($y,$m,$d))[0] ;
> $woy =~ /^\d{1}$/ ? sprintf('%02d', $woy) : $woy },
>
>
Thanks! That's what I was looking for! Just learned something new today...
Christian
------------------------------
Date: Thu, 12 Feb 2004 09:39:58 -0500
From: "Christian Caron" <nospam@nospam.org>
Subject: Re: strange behaviour with map inside a hash
Message-Id: <c0g37u$sm02@nrn2.NRCan.gc.ca>
"Uri Guttman" <uri@stemsystems.com> wrote in message
news:x73c9h702b.fsf@mail.sysarch.com...
> >>>>> "CC" == Christian Caron <nospam@nospam.org> writes:
>
> '%W' => do { my $woy = (Week_of_Year($y,$m,$d))[0] ;
> $woy =~ /^\d{1}$/ ? sprintf('%02d', $woy) : $woy },
For futur references, based on your solution, I did that:
########
#!/usr/local/bin/perl
use Date::Calc qw(:all);
my $y = 2004;
my $m = '02';
my $d = '09';
my %conversion = ( '%W' => left_pad_num((Week_of_Year($y,$m,$d))[0],
2),
'%w' => left_pad_num(Day_of_Week($y,$m,$d), 2),
'%j' => left_pad_num(Day_of_Year($y,$m,$d), 3),
'%Y' => "$y",
'%y' => left_pad_num(eval($y-2000), 2),
'%m' => "$m",
'%d' => "$d" );
foreach $k (sort keys %conversion) {
print "$k - $conversion{$k}\n";
}
# s/(\%\w{1})/$conversion{$1}/g
sub left_pad_num {
my ($num, $pad_len) = @_;
my $padded = sprintf("%0${pad_len}d", $num);
return $padded;
}
#########
------------------------------
Date: 12 Feb 2004 08:30:01 -0800
From: zak+test@freeshell.org (zak zebrowski)
Subject: Test message, please ignore.
Message-Id: <a65d00d3.0402120830.364fb399@posting.google.com>
This is a simple test message, please ignore.
------------------------------
Date: 12 Feb 2004 08:30:15 -0800
From: zak+test@freeshell.org (zak zebrowski)
Subject: Test message, please ignore.
Message-Id: <a65d00d3.0402120830.4b09ef01@posting.google.com>
This is a simple test message, please ignore.
------------------------------
Date: 12 Feb 2004 17:26:57 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: Test message, please ignore.
Message-Id: <Xns948D7EA4B4D74asu1cornelledu@132.236.56.8>
zak+test@freeshell.org (zak zebrowski) wrote in
news:a65d00d3.0402120830.364fb399@posting.google.com:
> This is a simple test message, please ignore.
>
Your wish is my command!
--
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)
------------------------------
Date: Thu, 12 Feb 2004 09:06:07 -0800
From: Yuri Shtil <yshtil@cisco.com>
Subject: tying hashes
Message-Id: <402BB27F.70406@cisco.com>
Hi all
I am considering using tie to control access to the properties of our
objects. The idea is to intercept store/fetch calls and check the
validity of the keys/values.
My questions are:
- has anyone used tie for this purpose
- are there any performance or other drawbacks
- are there better alternatives to tie
Thank you
Yuri
------------------------------
Date: Thu, 12 Feb 2004 18:17:24 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: tying hashes
Message-Id: <c0gfvk$f34$2@wisteria.csv.warwick.ac.uk>
Yuri Shtil <yshtil@cisco.com> wrote:
> Hi all
>
> I am considering using tie to control access to the properties of our
> objects. The idea is to intercept store/fetch calls and check the
> validity of the keys/values.
>
> My questions are:
>
> - has anyone used tie for this purpose
> - are there any performance or other drawbacks
tie is slow. This may not matter: implement the code and benchmark it
to see if the losses are significant.
Ben
--
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes, [ Heracles shoots Vulture with arrow. Vulture bursts into ]
/Alcestis/) [ flame, and falls out of sight. ] ben@morrow.me.uk
------------------------------
Date: 12 Feb 2004 03:16:16 -0800
From: dmedhora@yahoo.com (Darius)
Subject: Re: Using Tie::IxHash order a hash reference
Message-Id: <26a5971.0402120316.55539ea6@posting.google.com>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<c0esmc$16b5iq$1@ID-184292.news.uni-berlin.de>...
> Jeff 'japhy' Pinyan wrote:
> >
> > use Tie::IxHash;
> >
> > local ($,) = ("\n", " ");
> > my ($r1,$r2);
> >
> > tie %$r1, 'Tie::IxHash';
> >
> > @$r1{a..z} = @$r2{a..z} = ();
> >
> > print for keys %$r1, "\n"; # abcdefghijklmnopqrstuvwxyz
> > print for keys %$r2, "\n"; # wraxdjyukhgftienvmslcpbqzo
> >
> > Perl 5.8.0 seems to handle the situation just fine.
>
> Hmm.. Please consider the following example:
>
> use Tie::IxHash;
> my ($r1,$r2,$r3);
> tie %$r1, 'Tie::IxHash';
> tie %$r2, 'Tie::IxHash';
> tie %$r3, 'Tie::IxHash';
>
> print $r2, "\n"; # HASH(0x158123c)
>
> %$r1 = ( one => 1, two => 2, three => 3 );
> $r2 = { one => 1, two => 2, three => 3 };
>
> print $r2, "\n"; # HASH(0x158132c)
> # -----------^^
> $r3->{one} = 1;
> $r3->{two} = 2;
> $r3->{three} = 3;
>
> print $r1->{$_} for keys %$r1; # 123
> print "\n";
> print $r2->{$_} for keys %$r2; # 312
> print "\n";
> print $r3->{$_} for keys %$r3; # 123
> print "\n";
>
> I'd appreciate some help to understand what I'm doing. :)
> Is the difference in result because the construct
>
> $hashref = { };
>
> *always* creates a *new* anonymous hash, dropping previously created
> referent?
Hi, Yes I guess so. Therefore instead of using
$r2 = { one => 1, two => 2, three => 3 };
We have to use
%$r2 = ( one => 1, two => 2, three => 3 );
Then it prints 123.
Thanks Guys!
------------------------------
Date: Thu, 12 Feb 2004 11:07:15 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Why is Perl losing ground?
Message-Id: <d82605850f91deaded890d78471ba857@news.teranews.com>
>>>>> "Chris" == Chris Mattern <syscjm@gwu.edu> writes:
Chris> OSX's window manager/GUI is written in ObjC, but the base operating
Chris> system is FreeBSD, and it's written in C.
No, the base OS userland stuff (non-kernel) was populated primarily
from a snapshot of FreeBSD back when OSX was essentially NeXT. The
Kernel never came from FreeBSD, but was written from scratch from the
ground up.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
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 6123
***************************************