[29740] in Perl-Users-Digest
Perl-Users Digest, Issue: 984 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 28 00:09:45 2007
Date: Sat, 27 Oct 2007 21:09:07 -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 Sat, 27 Oct 2007 Volume: 11 Number: 984
Today's topics:
Re: FAQ 5.11 How can I write() into a string? <bik.mido@tiscalinet.it>
Re: need help with hash - been too long working in Perl <rkb@i.frys.com>
Re: need help with hash - been too long working in Perl <krahnj@telus.net>
Re: perl standard <zaxfuuq@invalid.net>
Re: perl standard <zaxfuuq@invalid.net>
reading a directory, first files the newest ones <jordilin@gmail.com>
Re: reading a directory, first files the newest ones xhoster@gmail.com
Re: reading a directory, first files the newest ones <noreply@gunnar.cc>
Re: reading a directory, first files the newest ones <krahnj@telus.net>
Re: reading a directory, first files the newest ones <jordilin@gmail.com>
Re: reading a directory, first files the newest ones <noreply@gunnar.cc>
Re: reading a directory, first files the newest ones <jurgenex@hotmail.com>
Re: reading a directory, first files the newest ones <jordilin@gmail.com>
Re: reading a directory, first files the newest ones <jordilin@gmail.com>
Re: reading a directory, first files the newest ones <noreply@gunnar.cc>
Re: reading a directory, first files the newest ones xhoster@gmail.com
Re: Regular expression to match only strings NOT contai <wizofaus@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 28 Oct 2007 02:24:08 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: FAQ 5.11 How can I write() into a string?
Message-Id: <8kl7i31b3cl8b3fpjookt4v040eqelmjkl@4ax.com>
On Sat, 27 Oct 2007 19:48:39 GMT, "Jürgen Exner"
<jurgenex@hotmail.com> wrote:
>> That would be a good question, although you might want to phrase is
>> "How do I print to a string instead of a file?".
>
>Well, isn't the answer to that question a simple:
>
> Use the sprintf() function?
No, that's the answer to "How do I printf to a string instead of a
file?"
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Sat, 27 Oct 2007 14:45:17 -0700
From: Ron Bergin <rkb@i.frys.com>
Subject: Re: need help with hash - been too long working in Perl
Message-Id: <1193521517.787448.168930@e34g2000pro.googlegroups.com>
My system seamed to hang while posting, so this may end up as a double
post.
On Oct 27, 12:57 pm, JerryP <gjwp...@gmail.com> wrote:
> Hi!
>
> This is simple? But it has been a while that I have programmed in
> Perl. What I am wanting to do is build a hash from a text file:
>
> text:
>
> 79706-0000 2229.17
> 79706-0000 2523.25
> 79701-0000 53904.48
> 79701-0000 78957.81
> 79701-0000 378043.04
> 79701-0000 1255172.34
> 79702-0000 7367.23
> 79702-0000 20742.95
> 79702-0000 67331.82
> 79702-0000 137629.57
> 79703-0000 1444.18
> 79701-0000 57565.48
> 79703-0000 2415.00
> 79703-0000 2787.97
> 79703-0000 4780.55
> 79703-0000 5061.21
> 79703-5011 1125.80
> 79704-0000 2382.31
> 79705-0000 4612.65
> 79706-0000 1416.50
> 79703-0000 64014.50
>
> With script:
>
> use strict;
> local( *FI, *FO );
Why are you using local on the file handles, which appear to have file
scope?
> my @text = ();
> my @zip = ();
It doesn't hurt, but there is no need to initialize the arrays with an
empty list.
> my %ref;
>
> open ( FI, "msj_sare.lst" ) or die "Couldn't open c:\\vf\
> \sj_sare.lst";
You should be using the 3 arg form of open and you should probably
include $! in the die statement to output the reason why it failed.
> my @text_ = <FI>;
> close FI;
It's almost never a good idea to slurp the entire file into an array.
Instead, you should loop through it.
>
> s/\n// for( @text = @text_ );
Use chomp while looping through the file to remove \n.
>
> foreach ( @text ) {
> /(\d+)\-(\d+)(\s+)(-?(?:\d+(?:\.\d*)?|\.\d+))/;
> push( @zip, $1 );
> push( @{ $ref{ $1 }{ $2 }},$_ );
> }
This is a personal preference, but I'd simplify the regex and use 1
push instead of 2.
>
> # then sort with
>
> open ( FO, "+>msj_sare.jwp" ) or die "Couldn't open c:\\vf\
> \sj_sare.jwp";
>
> foreach my $family ( sort keys %ref ) {
>
> # for my $role ( sort { $ref{$b} <=> $ref{$a} } keys %
> { $ref{$family} } ) {
> print " $family*$ref{ $family }*\n";
>
> for my $role ( sort keys %{ $ref{$family} } ) {
> print(join(', ',sort keys ${ $ref{$family} }),"\n");
> # print "$ref{$family}{$role}[0]\n";
> print FO "$ref{$family}{$role}[0]\n";
> }
> print FO "\n";
> }
>
> I am wanting to print out the data in the following format:
>
> 79701-0000 1255172.34
> 79701-0000 378043.04
> 79701-0000 78957.81
> 79701-0000 57565.48
> 79701-0000 53904.48
>
> 79702-0000 137629.57
> 79702-0000 67331.82
> 79702-0000 20742.95
> 79702-0000 7367.23
>
> 79703-0000 64014.50
> 79703-0000 5061.21
> 79703-0000 2787.97
> 79703-0000 2415.00
> 79703-0000 4780.55
> 79703-0000 1444.18
> 79703-5011 1125.80
>
> 79704-0000 2382.31
>
> 79705-0000 4612.65
>
> 79706-0000 2523.25
> 79706-0000 2229.17
> 79706-0000 1416.50
>
> Thanks,
>
> Jerry
use strict;
use warnings;
my %data;
while(<DATA>) {
my ($key) = /^(\d+)/;
my ($subkey, $value) = split /\s+/;
push @{$data{$key}{$subkey}}, $value;
}
foreach my $key ( sort keys %data ) {
foreach my $subkey ( sort keys %{$data{$key}} ) {
foreach my $value ( sort {$b <=> $a} @{$data{$key}{$subkey}} ) {
printf "%s %12.2f\n", $subkey, $value;
}
}
print "\n";
}
__DATA__
79706-0000 2229.17
79706-0000 2523.25
79701-0000 53904.48
79701-0000 78957.81
79701-0000 378043.04
79701-0000 1255172.34
79702-0000 7367.23
79702-0000 20742.95
79702-0000 67331.82
79702-0000 137629.57
79703-0000 1444.18
79701-0000 57565.48
79703-0000 2415.00
79703-0000 2787.97
79703-0000 4780.55
79703-0000 5061.21
79703-5011 1125.80
79704-0000 2382.31
79705-0000 4612.65
79706-0000 1416.50
79703-0000 64014.50
------------------------------
Date: Sun, 28 Oct 2007 02:47:52 GMT
From: "John W. Krahn" <krahnj@telus.net>
Subject: Re: need help with hash - been too long working in Perl
Message-Id: <4723F858.968C3D4B@telus.net>
JerryP wrote:
>
> This is simple? But it has been a while that I have programmed in
> Perl. What I am wanting to do is build a hash from a text file:
>
> text:
>
> 79706-0000 2229.17
> 79706-0000 2523.25
> 79701-0000 53904.48
> 79701-0000 78957.81
> 79701-0000 378043.04
> 79701-0000 1255172.34
> 79702-0000 7367.23
> 79702-0000 20742.95
> 79702-0000 67331.82
> 79702-0000 137629.57
> 79703-0000 1444.18
> 79701-0000 57565.48
> 79703-0000 2415.00
> 79703-0000 2787.97
> 79703-0000 4780.55
> 79703-0000 5061.21
> 79703-5011 1125.80
> 79704-0000 2382.31
> 79705-0000 4612.65
> 79706-0000 1416.50
> 79703-0000 64014.50
>
> With script:
>
> use strict;
> local( *FI, *FO );
You really don't need to local()ize those typeglobs.
> my @text = ();
> my @zip = ();
> my %ref;
>
> open ( FI, "msj_sare.lst" ) or die "Couldn't open c:\\vf\
> \sj_sare.lst";
You are trying to open "msj_sare.lst" but your error message says you
tried to open "c:\\vf\\sj_sare.lst"? You should include the $! (or $^E)
variable in the error message so you know *why* the open failed.
> my @text_ = <FI>;
> close FI;
>
> s/\n// for( @text = @text_ );
>
> foreach ( @text ) {
> /(\d+)\-(\d+)(\s+)(-?(?:\d+(?:\.\d*)?|\.\d+))/;
You shouldn't use the numeric variables unless the match was successful
or they will contain values from the last successful match. You are
capturing $3 and $4 but you are not using their contents?
> push( @zip, $1 );
> push( @{ $ref{ $1 }{ $2 }},$_ );
> }
>
> # then sort with
>
> open ( FO, "+>msj_sare.jwp" ) or die "Couldn't open c:\\vf\
> \sj_sare.jwp";
You are trying to open "msj_sare.jwp" but your error message says you
tried to open "c:\\vf\\sj_sare.jwp"? You are opening the file for both
reading and writing but you are not reading from the file? You should
include the $! (or $^E) variable in the error message so you know *why*
the open failed.
> foreach my $family ( sort keys %ref ) {
>
> # for my $role ( sort { $ref{$b} <=> $ref{$a} } keys %
> { $ref{$family} } ) {
> print " $family*$ref{ $family }*\n";
>
> for my $role ( sort keys %{ $ref{$family} } ) {
> print(join(', ',sort keys ${ $ref{$family} }),"\n");
> # print "$ref{$family}{$role}[0]\n";
> print FO "$ref{$family}{$role}[0]\n";
> }
> print FO "\n";
> }
>
> I am wanting to print out the data in the following format:
>
> 79701-0000 1255172.34
> 79701-0000 378043.04
> 79701-0000 78957.81
> 79701-0000 57565.48
> 79701-0000 53904.48
>
> 79702-0000 137629.57
> 79702-0000 67331.82
> 79702-0000 20742.95
> 79702-0000 7367.23
>
> 79703-0000 64014.50
> 79703-0000 5061.21
> 79703-0000 2787.97
> 79703-0000 2415.00
> 79703-0000 4780.55
> 79703-0000 1444.18
> 79703-5011 1125.80
>
> 79704-0000 2382.31
>
> 79705-0000 4612.65
>
> 79706-0000 2523.25
> 79706-0000 2229.17
> 79706-0000 1416.50
It *looks* like you might want the second column in sorted order but the
line:
79703-0000 4780.55
is not in sorted order?
Perhaps you want something like this:
use warnings;
use strict;
open FI, '<', 'msj_sare.lst' or die "Couldn't open 'msj_sare.lst' $!";
open FO, '>', 'msj_sare.jwp' or die "Couldn't open 'msj_sare.jwp' $!";
my %ref;
while ( <FI> ) {
if ( /(\d+)-(\d+)\s+-?(?:\d+\.\d*|\.?\d+)/ ) {
push @{ $ref{ $1 }{ $2 } }, $_;
}
}
for my $family ( sort { $a <=> $b } keys %ref ) {
for my $role ( sort { $a <=> $b } keys %{ $ref{ $family } } ) {
print FO @{ $ref{ $family }{ $role } }, "\n";
}
}
__END__
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 27 Oct 2007 21:40:54 -0600
From: "Wade Ward" <zaxfuuq@invalid.net>
Subject: Re: perl standard
Message-Id: <Z4KdnX0YMP1QmbnanZ2dnUVZ_tuonZ2d@comcast.com>
Standards have bugs, but fellas in the know work *very* hard on them. How
would there not be bugs in that which is computable?
--
wade Ward
South Jordan pkwy
435 -838-7760
President
wade@zaxfuuq.net
Westates Companies
Merrill Jensen Consulting
1108 W. South Jordan pkwy
42
wade@zaxfuuq.net
Merrill Jensen Consulting
1108 W. South Jordan pkwy
435 -838-7760
President
wade@zaxfuuq.net
Westates Companies
1108 W. South Jordan pkwy
435 -838-7760
President
wade@zaxfuuq.net
"Peter J. Holzer" <hjp-usenet2@hjp.at> wrote in message
news:slrnfi63en.77r.hjp-usenet2@zeno.hjp.at...
> On 2007-10-19 22:28, Ben Bullock <benkasminbullock@gmail.com> wrote:
>> On Fri, 19 Oct 2007 11:04:49 +0200, Dr.Ruud wrote:
>>
>>> ... The documentation is an important part of the implementation. So is
>>> CPAN, for example all the testcode of the serious modules.
>>
>> What to do if Perl fails the tests though, or if the documentation and
>> the
>> program disagree?
>
> "If the code and comments disagree, both are probably wrong"
>
> substitute comments for "tests and documentation" and you have your
> answer: If there is a disagreement, it's a bug, and all sides have to be
> examined carefully to determine whether the code or the test or the
> documentation has to be changed.
>
> Standards do have bugs, too. They are just harder to fix.
>
> hp
>
> --
> _ | Peter J. Holzer | I know I'd be respectful of a pirate
> |_|_) | Sysadmin WSR | with an emu on his shoulder.
> | | | hjp@hjp.at |
> __/ | http://www.hjp.at/ | -- Sam in "Freefall"
------------------------------
Date: Sat, 27 Oct 2007 21:53:27 -0600
From: "Wade Ward" <zaxfuuq@invalid.net>
Subject: Re: perl standard
Message-Id: <bYWdnfiIA5IjmrnanZ2dnUVZ_ramnZ2d@comcast.com>
"Peter J. Holzer" <hjp-usenet2@hjp.at> wrote in message
news:slrnfi65d4.77r.hjp-usenet2@zeno.hjp.at...
> On 2007-10-21 05:06, David Formosa (aka ? the Platypus)
> <dformosa@usyd.edu.au> wrote:
>> On 19 Oct 2007 10:30:11 GMT, Abigail <abigail@abigail.be> wrote:
>>> Well, there's more to be said about the merits of a standard than
>>> just dismissing it with "there's just one implementation".
>>>
>>> Read the O'Reilly interview [1] with Larry Rosler (a former clpm poster)
>>> for instance. I don't necessarely agree with his conclusion, but he
>>> makes some interesting arguments.
>
> The argument about the "marketing value" of a standard has some merit.
> But a standard is neither necessary nor sufficient for success, even in
> corporate and governmental environments.
> There is no Windows ISO standard, no Java ISO standard, and yet these
> are used very widely. OTOH there is an ISO (or at least ANSI) CPU
> standard (for a subset of the SPARC ABI, IIRC) which nobody cares about
> and I think the Pascal or BASIC ISO standards are similarily
> inconsequential.
Perl ist , in deisem Bereich, verschieden von ihrer Muttersprache C.
>
> Successful standards (like C90 or POSIX) are developed after there have
> been multiple implementations and when the implementors actually want to
> converge on a single standard. In the case of an open source interpreted
> language like perl5 there is little value in a standard. There is only
> one implementation, a second implementation is unlikely to happen
> (porting is almost always easier than rewriting from scratch) if it
> happens compatibility is probably only a minor goal.
>
>> A standard doesn't make ensure conformance. While SOAP for example
>> has a standard no one quite implements SOAP the same way, so we have a
>> set of mutually incompatable programs each implementing there own
>> subset of the protocol.
>
> Same for SQL.
Ich weiß überhaupt nichts über das Obige.
>
> Even the current C standard is widely ignored. While most C compilers
> implement C90, there are only 2 or 3 compilers which are certified
> C99-conforming, and maybe a handful of others which try to be that. Most
> C implementators either ignore C99 completely or implement only those
> features which are either easy or demanded by their customers.
>
>> Part of me would like a nice certificate to say "Perl's all mature and
>> 'Enterpize ready'" but I fear the loss of @larry's guidence that this
>> might entail.
>
> Mostly I fear that would slow down perl development even more than the
> combination of "we need to be backwards compatible" and "perl6 is just
> around the corner" has done. ISO standards are usually revised every 10
> years, and they are viewed as infallible. So if something is
> standardized which is genuinely broken (which does happen), it will take
> 10 years before it is declared "deprecated" and 20 years before it is
> removed from the language. With "normal" software development like in
> perl the problem can be fixed in the next release (and hopefully by that
> time there won't be much code which relies on it so the fix will cause
> few problems).
xdcghsf
Die Maßstäbe in perl kommen von sich selbst. Ich heiße ihn den
Camelstandard. Der Anschluß
an
iso, ist,
zumindest uns juengeren,
eine mit allen mitteln durchzu fiurherendse
Lebensaufgabe escheinedende zielzweck
zu duerfen.
Zug.
Gruß,
Jensen
--
Merrill Jensen Consulting
1108 W. South Jordan pkwy
435 -838-7760
President
wade@zaxfuuq.net
------------------------------
Date: Sun, 28 Oct 2007 01:10:04 -0000
From: jordilin <jordilin@gmail.com>
Subject: reading a directory, first files the newest ones
Message-Id: <1193533804.445334.15080@z9g2000hsf.googlegroups.com>
When I read a huge directory with opendir,
opendir(DIR,"dirname");
my $file;
while($file=readdir(DIR))
whatever...
it loads the oldest ones first. I would like the newest files first,
instead of the oldest. Taking into account that I am only interested
in the newest files, this takes a lot of time, as the directory is
really huge. I am talking about thousands and thousands of files. I
need to process the files that are two hours old from now. I am not
interested in those older than two hours ago. I know that because I
check the modification time with stat.
any idea?
Thanks in advance
------------------------------
Date: 28 Oct 2007 01:34:24 GMT
From: xhoster@gmail.com
Subject: Re: reading a directory, first files the newest ones
Message-Id: <20071027213427.819$ky@newsreader.com>
jordilin <jordilin@gmail.com> wrote:
> When I read a huge directory with opendir,
> opendir(DIR,"dirname");
> my $file;
> while($file=readdir(DIR))
> whatever...
> it loads the oldest ones first. I would like the newest files first,
> instead of the oldest.
That is completely up to your OS and your file system. Perl just provides
a fairly simple conduit for their behavior to reach you.
> Taking into account that I am only interested
> in the newest files, this takes a lot of time, as the directory is
> really huge. I am talking about thousands and thousands of files. I
> need to process the files that are two hours old from now. I am not
> interested in those older than two hours ago. I know that because I
> check the modification time with stat.
> any idea?
Come up with a better directory structure; one that doesn't involve keeping
thousands and thousands of file in one directory that has to be scanned
over and over again. Or make whatever puts the files into that directory
to make a log, or to also create a symbolic link in another directory
pointing to the new file, which link can be deleted after 2 hours or so.
Its possible that your OS and your file system provide other tools for
inspecting very large directories more efficiently, but I rather doubt it.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Sun, 28 Oct 2007 02:36:15 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: reading a directory, first files the newest ones
Message-Id: <5oi7cpFmvc77U1@mid.individual.net>
jordilin wrote:
> When I read a huge directory with opendir,
> opendir(DIR,"dirname");
> my $file;
> while($file=readdir(DIR))
> whatever...
> it loads the oldest ones first. I would like the newest files first,
> instead of the oldest. Taking into account that I am only interested
> in the newest files, this takes a lot of time,
How much time is that?
> as the directory is
> really huge. I am talking about thousands and thousands of files. I
> need to process the files that are two hours old from now. I am not
> interested in those older than two hours ago.
You may want to use grep() to assign to an array the files you are
interested in.
my @files = grep -M $_ <= 2/24, readdir DIR;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 28 Oct 2007 01:48:51 GMT
From: "John W. Krahn" <krahnj@telus.net>
Subject: Re: reading a directory, first files the newest ones
Message-Id: <4723EA82.5E7D7BE@telus.net>
jordilin wrote:
>
> When I read a huge directory with opendir,
> opendir(DIR,"dirname");
You should *always* verify that the directory opened successfully:
opendir DIR, 'dirname' or die "Cannot open 'dirname' $!";
> my $file;
> while($file=readdir(DIR))
> whatever...
> it loads the oldest ones first.
No, it reads the file names in the order that they are stored in the
directory. It is just a coincidence that the older ones appear before
the newer ones. :-)
> I would like the newest files first, instead of the oldest.
Then you will have to sort them yourself.
perldoc -f sort
> Taking into account that I am only interested
> in the newest files, this takes a lot of time, as the directory is
> really huge. I am talking about thousands and thousands of files. I
> need to process the files that are two hours old from now. I am not
> interested in those older than two hours ago. I know that because I
> check the modification time with stat.
> any idea?
The only thing you can do is read all the file names in the directory
and stat() each one.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sun, 28 Oct 2007 01:57:12 -0000
From: jordilin <jordilin@gmail.com>
Subject: Re: reading a directory, first files the newest ones
Message-Id: <1193536632.247247.50130@57g2000hsv.googlegroups.com>
On Oct 28, 1:36 am, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> jordilin wrote:
> > When I read a huge directory with opendir,
> > opendir(DIR,"dirname");
> > my $file;
> > while($file=readdir(DIR))
> > whatever...
> > it loads the oldest ones first. I would like the newest files first,
> > instead of the oldest. Taking into account that I am only interested
> > in the newest files, this takes a lot of time,
>
> How much time is that?
>
> > as the directory is
> > really huge. I am talking about thousands and thousands of files. I
> > need to process the files that are two hours old from now. I am not
> > interested in those older than two hours ago.
>
> You may want to use grep() to assign to an array the files you are
> interested in.
>
> my @files = grep -M $_ <= 2/24, readdir DIR;
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl
To grab the files that are from two hours ago till now, I have to
process each file to check the modification time. Obviously, if the
while checks the oldest files first, it can take more than 10 minutes
to arrive for those files I am interested in. This directory has a
huge amount of files.
------------------------------
Date: Sun, 28 Oct 2007 03:02:34 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: reading a directory, first files the newest ones
Message-Id: <5oi8u3FmbuutU1@mid.individual.net>
jordilin wrote:
> When I read a huge directory with opendir,
> opendir(DIR,"dirname");
> my $file;
> while($file=readdir(DIR))
> whatever...
> it loads the oldest ones first. I would like the newest files first,
> instead of the oldest. Taking into account that I am only interested
> in the newest files, this takes a lot of time, as the directory is
> really huge. I am talking about thousands and thousands of files. I
> need to process the files that are two hours old from now. I am not
> interested in those older than two hours ago.
Maybe you should let the system do the desired sorting. On *nix that
might be:
chomp( my @files = qx(ls -t $dir) );
foreach my $file (@files) {
last if -M "$dir/$file" > 2/24;
print "$file\n";
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 28 Oct 2007 02:04:46 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: reading a directory, first files the newest ones
Message-Id: <27SUi.1046$hd1.804@trndny01>
jordilin wrote:
> On Oct 28, 1:36 am, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
>> You may want to use grep() to assign to an array the files you are
>> interested in.
>>
>> my @files = grep -M $_ <= 2/24, readdir DIR;
>>
> To grab the files that are from two hours ago till now, I have to
> process each file to check the modification time.
Yes. That is what the -M does.
> Obviously, if the
> while checks the oldest files first, it can take more than 10 minutes
> to arrive for those files I am interested in.
That is exactly why Gunnar suggest not to use a while() loop but grep() in
the first place.
jue
------------------------------
Date: Sun, 28 Oct 2007 02:18:41 -0000
From: jordilin <jordilin@gmail.com>
Subject: Re: reading a directory, first files the newest ones
Message-Id: <1193537921.572310.205520@22g2000hsm.googlegroups.com>
On Oct 28, 2:02 am, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> jordilin wrote:
> > When I read a huge directory with opendir,
> > opendir(DIR,"dirname");
> > my $file;
> > while($file=readdir(DIR))
> > whatever...
> > it loads the oldest ones first. I would like the newest files first,
> > instead of the oldest. Taking into account that I am only interested
> > in the newest files, this takes a lot of time, as the directory is
> > really huge. I am talking about thousands and thousands of files. I
> > need to process the files that are two hours old from now. I am not
> > interested in those older than two hours ago.
>
> Maybe you should let the system do the desired sorting. On *nix that
> might be:
>
> chomp( my @files = qx(ls -t $dir) );
> foreach my $file (@files) {
> last if -M "$dir/$file" > 2/24;
> print "$file\n";
> }
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl
With this code, and taking into account that the directory is huge,
memory usage would be a problem as we are going to use a huge array
@files, and the Unix server is a very important one. Don't know if
that could be achieved by means of a while. The real problem is having
to process many files before arriving to the interesting ones. The
solution would be reading the newest ones first. I think there is no
solution. We have, either to slurp all the files into an array (which
is going to take time and memory), or process the whole directory
through a while (one file at a time) till we get the proper files,
which in this case is going to take a lot of time as well.
------------------------------
Date: Sun, 28 Oct 2007 02:31:35 -0000
From: jordilin <jordilin@gmail.com>
Subject: Re: reading a directory, first files the newest ones
Message-Id: <1193538695.390428.172290@o3g2000hsb.googlegroups.com>
On Oct 28, 2:04 am, "J=FCrgen Exner" <jurge...@hotmail.com> wrote:
> jordilin wrote:
> > On Oct 28, 1:36 am, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> >> You may want to use grep() to assign to an array the files you are
> >> interested in.
>
> >> my @files =3D grep -M $_ <=3D 2/24, readdir DIR;
>
> > To grab the files that are from two hours ago till now, I have to
> > process each file to check the modification time.
>
> Yes. That is what the -M does.
>
> > Obviously, if the
> > while checks the oldest files first, it can take more than 10 minutes
> > to arrive for those files I am interested in.
>
> That is exactly why Gunnar suggest not to use a while() loop but grep() in
> the first place.
>
> jue
Yeah, it seems that this would be a solution.
------------------------------
Date: Sun, 28 Oct 2007 03:36:43 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: reading a directory, first files the newest ones
Message-Id: <5oiau5FmtnadU1@mid.individual.net>
jordilin wrote:
> On Oct 28, 2:02 am, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
>> Maybe you should let the system do the desired sorting. On *nix that
>> might be:
>>
>> chomp( my @files = qx(ls -t $dir) );
>> foreach my $file (@files) {
>> last if -M "$dir/$file" > 2/24;
>> print "$file\n";
>> }
>
> With this code, and taking into account that the directory is huge,
How big is "huge"?
> memory usage would be a problem as we are going to use a huge array
> @files, and the Unix server is a very important one. Don't know if
> that could be achieved by means of a while. The real problem is having
> to process many files before arriving to the interesting ones.
With the above suggestion you wouldn't _process_ any files but the
interesting ones; you'd just store their names in an array.
> The solution would be reading the newest ones first.
And that's what the -t option achieves...
> I think there is no solution.
??
> We have, either to slurp all the files into an array (which
> is going to take time and memory), or process the whole directory
> through a while (one file at a time) till we get the proper files,
> which in this case is going to take a lot of time as well.
Have you measured the time for various options? You may want to study
the Benchmark module.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 28 Oct 2007 02:47:38 GMT
From: xhoster@gmail.com
Subject: Re: reading a directory, first files the newest ones
Message-Id: <20071027224741.589$xt@newsreader.com>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> jordilin wrote:
> > On Oct 28, 2:02 am, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> >> Maybe you should let the system do the desired sorting. On *nix that
> >> might be:
> >>
> >> chomp( my @files = qx(ls -t $dir) );
> >> foreach my $file (@files) {
> >> last if -M "$dir/$file" > 2/24;
> >> print "$file\n";
> >> }
> >
...
>
> > The solution would be reading the newest ones first.
>
> And that's what the -t option achieves...
No, the -t option tells ls to *present* the newest ones first, not to
read them first. To present them in that order, it first needs to read all
of the directory entries in whatever order the file system deigns to
deliver them, stat them all, and sort the results based on time. There is
no reason to think that ls is going to be meaningfully faster about this
than perl will.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Sat, 27 Oct 2007 14:04:53 -0700
From: Dylan Nicholson <wizofaus@hotmail.com>
Subject: Re: Regular expression to match only strings NOT containing particular words
Message-Id: <1193519093.549721.276420@t8g2000prg.googlegroups.com>
On Oct 28, 6:45 am, Jesse Houwing <jesse.houw...@newsgroup.nospam>
wrote:
> Hello Dylan,
>
>
>
>
>
> > On Oct 20, 2:40 am, "J?rgen Exner" <jurge...@hotmail.com> wrote:
>
> >> J?rgen Exner wrote:
>
> >>> Dylan Nicholson wrote:
>
> >>>> I can write a regular expression that will only match strings that
> >>>> are NOT the word apple:
>
> >>>> ^([^a].*|a[^p].*|ap[^p].*|app[^l].*|apple.+)$
>
> >>>> But is there a neater way, and how would I do it to match strings
> >>>> that are NOT the word apple OR banana? Then what would be needed to
> >>>> match only strings that do not CONTAIN the word "apple" or "banana"
> >>>> or "cherry"?
>
> >>> !(/apple/ or /banana/ or /cherry/)
>
> >> Actually, coming to think of it: there is no good reason to use a RE
> >> in the first place because you are looking for a literal substring
> >> only without any of the meta-functionality of REs. The proper tool
> >> for that much simpler task is index().
>
> >> jue
>
> > Sure, except the regular expression mechanism is already in place as a
> > feature of the application. I was just curious if it could be used to
> > solve a particular problem.
>
> > Unfortunately "!(/apple/ or /banana/ or /cherry/)" doesn't work with
> > Microsoft's .NET regex library.
>
> It isn't ideal, but this will do the trick:
>
> ^((?!\b(cherry|banana|apple)\b).)*$
Thanks...works great...why do you say it's not ideal? I removed the
\b's though, as I need to exclude any string that contains "apple",
regardless of whether it's a separate word.
>
> Make sure you set the option SingleLine and unset the option Multiline when
> appropriate. If the application is under your control, it would probably
> be easier to add a checkbox which will invert the match result from Success
Yes, we'll probably do something similar for the next version.
>
> Though as Jue pointed out, it's probably faster and easier to maintain when
> you implement a "bad words" list and use indexOf to see if the string is
> in there somewhere. You might even use \bword\b in a regex for that.
>
If the regex does the job, it's more than adequate for now.
------------------------------
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 V11 Issue 984
**************************************