[26220] in Perl-Users-Digest
Perl-Users Digest, Issue: 8405 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 11 18:06:47 2005
Date: Sun, 11 Sep 2005 15:05:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 11 Sep 2005 Volume: 10 Number: 8405
Today's topics:
[ANNOUNCE] POD2::IT 0.09 <bepi@perl.it>
How to redirect stderr to C lang function <luki@NOSPAMsdf-eu.org>
not or ! ? <"h.v.niekerk at hccnet.nl">
Re: not or ! ? <sbryce@scottbryce.com>
Re: not or ! ? <see.sig@rochester.rr.com>
Re: not or ! ? <no@email.com>
Re: not or ! ? <"h.v.niekerk at hccnet.nl">
Re: not or ! ? <sherm@dot-app.org>
sorting data - hash vs. list <Fred@fred.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 8 Sep 2005 11:05:33 GMT
From: Enrico Sorcinelli <bepi@perl.it>
Subject: [ANNOUNCE] POD2::IT 0.09
Message-Id: <IMo9IA.12vn@zorch.sf-bay.org>
Hi all,
the pod2it[1] team is proud to announce a new POD2::IT release available on
CPAN[2]
CHANGES FROM PREVIOUS VERSION
+ Added perlunicode.pod translation [dakkar]
+ Added resources/podenc.pl script in order to encode
italian characters with E<> sequence [dakkar, bepi]
! Updated E<> pod entities [bepi]
! Updated IT.pm pod documentation [bepi]
! Fixed Changes and README typos [bepi]
POD2::IT also contains the patch to Pod/Perldoc.pm in order to continue to use
-f and -q switches with translated pods (not only italian).
Regards
- Enrico
[1] http://pod2it.sf.net - Italian translation project of core Perl pods
[2] http://cpan.uwinnipeg.ca/dist/POD2-IT
------------------------------
Date: Sun, 11 Sep 2005 19:21:57 +0000 (UTC)
From: Lukas P <luki@NOSPAMsdf-eu.org>
Subject: How to redirect stderr to C lang function
Message-Id: <dg204l$dih$1@chessie.cirr.com>
Keywords: Perl, stderr
Hello,
I am currently trying to figure out how to redirect all Perl error
messages to my own logging function. The Perl interpreter is embedded in
my app (written in C), which means that I can modify even the interpreter
itself.
I have found several ways to do it, but none of them seems to be
"proper" way.
Thanks in advance for any advices.
Best regards, Lukas P
------------------------------
Date: Sun, 11 Sep 2005 17:20:01 +0200
From: Huub <"h.v.niekerk at hccnet.nl">
Subject: not or ! ?
Message-Id: <43244a74$0$774$3a628fcd@reader10.nntp.hccnet.nl>
Hi,
I'm trying to use 'not' but it gives an error. So, can I do this or is
it too simple thought?
while !(/m\s/g) # While the character being read is no white space
{
...
}
Thank you,
Huub
------------------------------
Date: Sun, 11 Sep 2005 09:32:11 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: not or ! ?
Message-Id: <3JKdnZ2dnZ2UrYnonZ2dnWvQud6dnZ2dRVn-zZ2dnZ0@comcast.com>
Huub wrote:
> Hi,
>
> I'm trying to use 'not' but it gives an error. So, can I do this or
> is it too simple thought?
>
> while !(/m\s/g) # While the character being read is no white space {
> ... }
What happened when you tried it?
------------------------------
Date: Sun, 11 Sep 2005 15:32:37 GMT
From: Bob Walton <see.sig@rochester.rr.com>
Subject: Re: not or ! ?
Message-Id: <p6YUe.87152$Hx4.72990@twister.nyroc.rr.com>
Huub wrote:
...
> I'm trying to use 'not' but it gives an error. So, can I do this or is
> it too simple thought?
>
> while !(/m\s/g) # While the character being read is no white space
Uh, if you mean what your comment says, you probably want
m/\s/g
as the regex you posted will match an "m" followed by a
whitespace character.
Also, the syntax for the while is incorrect. It is
while(expression){...}
Did you actually try compiling what you posted? It generates a
syntax error.
Even if all that is fixed, the special meaning of //g in a while
doesn't work with a ! in front of the regex (one gets either no
executions of the loop if one or more whitespace characters is
present, or an infinite loop if no whitespace character is
present). Maybe what you want is:
while(/[^\s]/g){...}
?
For example:
D:\junk>perl -e "$_='a b c';while(/[^\s]/g){print 'hi'}"
hihihi
D:\junk>
> {
> ...
> }
...
> Huub
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Sun, 11 Sep 2005 16:37:00 +0100
From: Brian Wakem <no@email.com>
Subject: Re: not or ! ?
Message-Id: <3oj18sF66754U1@individual.net>
Bob Walton wrote:
> Maybe what you want is:
>
> while(/[^\s]/g){...}
or even /\S/g
--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
Date: Sun, 11 Sep 2005 18:50:45 +0200
From: Huub <"h.v.niekerk at hccnet.nl">
Subject: Re: not or ! ?
Message-Id: <43245fb9$0$146$3a628fcd@reader1.nntp.hccnet.nl>
Bob Walton wrote:
> Huub wrote:
>
> ...
>
>> I'm trying to use 'not' but it gives an error. So, can I do this or is
>> it too simple thought?
>>
>> while !(/m\s/g) # While the character being read is no white space
>
>
> Uh, if you mean what your comment says, you probably want
>
> m/\s/g
Yes..typo. Should type and read more carefully.
>
> as the regex you posted will match an "m" followed by a whitespace
> character.
>
> Also, the syntax for the while is incorrect. It is
>
> while(expression){...}
Yes, (!(m/\s/g)) compiles better.
>
> Did you actually try compiling what you posted? It generates a syntax
> error.
Yes.
>
> Even if all that is fixed, the special meaning of //g in a while doesn't
> work with a ! in front of the regex (one gets either no executions of
> the loop if one or more whitespace characters is present, or an infinite
> loop if no whitespace character is present). Maybe what you want is:
>
> while(/[^\s]/g){...}
>
> ?
>
> For example:
>
> D:\junk>perl -e "$_='a b c';while(/[^\s]/g){print 'hi'}"
> hihihi
> D:\junk>
>
>> {
>> ...
>> }
>
> ...
>
>> Huub
------------------------------
Date: Sun, 11 Sep 2005 15:07:07 -0400
From: Sherm Pendley <sherm@dot-app.org>
Subject: Re: not or ! ?
Message-Id: <m2vf17l8ys.fsf@Sherm-Pendleys-Computer.local>
Huub <"h.v.niekerk at hccnet.nl"> writes:
> Bob Walton wrote:
>> Uh, if you mean what your comment says, you probably want
>> m/\s/g
>
> Yes..typo. Should type and read more carefully.
No, should copy-and-paste.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Sun, 11 Sep 2005 16:41:28 -0500
From: "Fred@fred.net" <Fred@fred.net>
Subject: sorting data - hash vs. list
Message-Id: <qf79i19v7kqklccnr86pqr56ck5rc6loio@4ax.com>
Greetings and salutations!
Like many I come seeking knowledge. I have been using perl for 1 year.
I am in the early stages of conceptualizing a small
perl program.
My dilemma is that I have to sort a flat file on a certain field.
Now in Unix you can `sort -d"|" -f13` and viola sort the 13th field of a well-mannered data file. BUT in perl so far, I have had no luck. Allow me first to introduce my/our/the data record.
|C|170|901|2|0000000000008|4|000008|5|09/05/05|6|BART'S HVYDTY PROPHYLACTIC|14|3.99|15|00006|
I can shift the |C| off the front and then record splits nicely into a hash of field/data pairs where the single whole numbers in each pipe delimited field become the keys and the associated data matching. Field 2 is UPC for example. Field |14| is price,
etc
But my data file is 18meg.
I need to sort, you guessed it, the date field |5|. Now I know from reading in the "Perl Cookbook" aka
Publisher: O'Reilly; 2 edition (August 21, 2003)
Language: English
ISBN: 0596003137
Regarding "recipe" 3.2 & 3.3 where you use timelocal() to convert back and forth between epoch seconds and what a human thinks of time as and that's no problem. That code is easy. (Easy, right, thanks to who ever wrote localtime().)
My Problem: I have split each record into an array only to realize I have a varying length record due to product description, so a substr won't help. And at that rate I'd have to "swap" all the subscripts at once to keep the dates with the records they go
with.
Back to the hash approach. I'd have to read the entire 18 Meg file into memory to sort it. (Unless this concern exposes the limits of my technical expertise in perl and programming at large in any case.
And that is a troubling prospect but one for which I can find no remedy. So assuming I did that, could I then sort the filled hash and get the results I am looking for from the Unix command `sort -d"|" -f5` ?
I don't have any code to post becuase I'm not at that point yet.
But just so you'll know I am not a complete rookie I'll post some recent work,
I try and make absolutlely as clear as possible with variable names and control flow conventions, exactly what is going on.
use strict;
use warnings;
my $i = 0;
my $ubound = scalar(@list) ;
for ($i = 0; $i < $ubound ; $i++){ print "$i\n";} # I like c style for loops...
Here is my sub for a file delete utility I wrote that uses timelocal() -- it'll show that I not leeching here becuase it's likely riddled with shortcomings. So you'll know I ain't getting you to do my "homework":
sub too_old($$$) {
#get arguments
my ( $dir, $pattern, $days ) = ( shift, shift, shift );
my $file_name;
my @del_list;
#read directory looking for targets
opendir( DIR, $dir ) or die(print AUDIT "Cannot open directory '$dir': $!");
# this next line is A peice of work.. it loads the times hash with
# the filenames and the mtimes for the given function call.
my (%times) = map { $_, ( stat("$dir/$_") )[9] } grep( !/^\.{1,2}$/, readdir(DIR) );
my $key;
foreach $key ( keys %times ) {
my $inkey = substr( $key, 0, 8 );
if ( $inkey =~ /^\./g ) { $inkey =~ s/\.//g; } # fixs .xxx
if ( $inkey !~ /$pattern/ ) { #has to match the pattern
delete $times{$key}; #and remove it if it does not
}
else {
$file_name = $key; # bingo!
push( @del_list, $file_name );
}
}
my $number_o_files = @del_list;
foreach (@del_list) {
my $file_name = $_;
my $val = $times{$file_name}; # get the epoch time
my $target = $days; # what was that target?
my $candidate = $file_name; # just a name change
my $file_epoch_date = $val;
#fix up another set of vars into sets for timegm
my $sec = sprintf "%d", $now[0];
my $minutes = sprintf "%d", $now[1]; # setting these up as required dummies
my $hours = sprintf "%d", $now[2];
my $now_date_mon = sprintf "%d", $now[4] + 1;
my $now_date_day = sprintf "%d", $now[3];
my $now_date_year = sprintf "%02d", $now[5] + 1900;
$hours = $hours + 6; # add 6 to acoomodate GMTtime to get to CST
# $current_epoch_date is the current date in epoch seconds
# call timegm to convert from mm/dd/yyyy to epoch seconds
my $check;
my $current_epoch_date = timegm(
$sec, $minutes, $hours, $now_date_day ,
$now_date_mon - 1 ,
$now_date_year
);
my $target_check = localtime($file_epoch_date);
my $today_check = localtime($current_epoch_date);
# do the math in epoch seconds
my $difference = $current_epoch_date - $file_epoch_date;
my $hours2 = ( $difference / 3600 );
my $days2 = ( $hours2 / 24 );
my $days_between = $days2;
#touch -t 200409241201 fred.tmp for testing
#2nd parameter to touch should be in the form [[CC]YY]MMDDhhmm[.SS]
if ( $days_between > $target ) {
print AUDIT
"Removing $dir\\$candidate -- File was $days_between days old.\n";
unlink "$dir\\$candidate"; #<- uncomment to activate
}
} #close the foreach @file_del
} # close the sub routine
I have posted here before and been flamed to death, so I guess I'm ready if it happens again. OTH -- I'd be interested in any helpful critisims on my file delete sub. Plus the main question on how to sort that dang file.
Thanks,
Fred
------------------------------
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 8405
***************************************