[23439] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5654 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 13 21:10:41 2003

Date: Mon, 13 Oct 2003 18:10:11 -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           Mon, 13 Oct 2003     Volume: 10 Number: 5654

Today's topics:
    Re: Strange printf behavior <invalid-email@rochester.rr.com>
        Why doesn't this work? <nospam@goawayspam.com>
    Re: Why doesn't this work? <hexkid@hotpop.com>
    Re: Why doesn't this work? (Tad McClellan)
    Re: Why doesn't this work? <REMOVEsdnCAPS@comcast.net>
    Re: Why doesn't this work? <flavell@ph.gla.ac.uk>
    Re: Why Is My Hash Assignment Taking So Long? <nospam_for_jkeen@concentric.net>
    Re: Wierdness with code to display file creation date <grazz@pobox.com>
    Re: Writing a perl file comparison program <jorge.b@rrios.com>
    Re: Writing a perl file comparison program <krahnj@acm.org>
    Re: Writing a perl file comparison program (Roy Johnson)
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 14 Oct 2003 00:13:19 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Strange printf behavior
Message-Id: <3F8B3F8C.2050607@rochester.rr.com>

Jay Tilton wrote:

> Bob Walton <invalid-email@rochester.rr.com> wrote:
> 
> : Perl:  Activestate build 806 (5.8.0)
> : OS:  Windows 98SE
> : 
> : I note that:
> : 
> :     perl -e "printf '%0d %0d',1,2;"
> : 
> : gives:  1 2
> : 
> : but that:
> : 
> :     perl -e "printf '%d %d',1,2;"
> : 
> : gives:  d
> : 
> : and that:
> : 
> :     perl -e "printf '%d %0d',1,2;"
> : 
> : gives:  0d
> : 
> : and that:
> : 
> : perl -e "printf '%d %garbage',1,2;"
> : 
> : gives:  garbage
> : 
> : Does anyone else observe this behavior and, if so, have an explanation?
> 
> The '%' character is meaningful to the command interpreter.  It is used
> to interpolate environment variables.
> 
> Double up a '%' character to ensure the shell doesn't try to do any
> interpolation, e.g.
> 
>     perl -e "printf '%%d %%d',1,2;"
> 
> 

Ah, missed that one!  Thanks!

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



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

Date: Mon, 13 Oct 2003 15:55:59 -0500
From: "Kubaton Lover" <nospam@goawayspam.com>
Subject: Why doesn't this work?
Message-Id: <vom4b8m4kdj207@corp.supernews.com>

This is returning an error on my server.

$L1 = substr(split(/~/,$rqpairs{$param}))[5],0,1);

If I remove the substr, it works fine, but I just want to return the first
character.  Can someone point out my syntax error?  Thanks.




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

Date: 13 Oct 2003 21:13:58 GMT
From: Pedro <hexkid@hotpop.com>
Subject: Re: Why doesn't this work?
Message-Id: <bmf4im$luao3$1@ID-203069.news.uni-berlin.de>

Kubaton Lover wrote:
> This is returning an error on my server.
>
> $L1 = substr(split(/~/,$rqpairs{$param}))[5],0,1);
>
> If I remove the substr, it works fine, but I just want to return the first
> character.  Can someone point out my syntax error?  Thanks.

Try this:
$L1 = substr( ( split(/~/,$rqpairs{$param}) ) [5],0,1);
______________^_____________________________^_______ new parenthesis


-- 
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.


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

Date: Mon, 13 Oct 2003 16:21:04 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Why doesn't this work?
Message-Id: <slrnbom5q0.1v1.tadmc@magna.augustmail.com>

Kubaton Lover <nospam@goawayspam.com> wrote:

> This is returning an error on my server.


Error messages are meant to help in debugging.

If you want help with debugging, helpfully supply the exact text
of the helpful error message.


> $L1 = substr(split(/~/,$rqpairs{$param}))[5],0,1);
                                                  ^
                                                  ^
> Can someone point out my syntax error?


Where is the open paren to go with that closing one?

   $L1 = substr((split(/~/,$rqpairs{$param}))[5],0,1)


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


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

Date: Mon, 13 Oct 2003 16:32:31 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Why doesn't this work?
Message-Id: <Xns9413B26C717FDsdn.comcast@206.127.4.25>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

"Kubaton Lover" <nospam@goawayspam.com> wrote in
news:vom4b8m4kdj207@corp.supernews.com: 

> This is returning an error on my server.
> 
> $L1 = substr(split(/~/,$rqpairs{$param}))[5],0,1);
> 
> If I remove the substr, it works fine, but I just want to return the
> first character.  Can someone point out my syntax error?  Thanks.

Mismatched parentheses.

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP4sZ5GPeouIeTNHoEQKDewCfXq+iTQ6I5rnhyPJzxqCZJPfBszUAnic2
vhkUEUJOAmZoy7vEYqXi/0qP
=lE01
-----END PGP SIGNATURE-----


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

Date: Mon, 13 Oct 2003 22:56:12 +0100
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Why doesn't this work?
Message-Id: <Pine.LNX.4.53.0310132250200.21768@ppepc56.ph.gla.ac.uk>

On Mon, 13 Oct 2003, Kubaton Lover wrote:

| Subject : Re: Why doesn't this work?

You'll be needing this shortly[1]:

http://catb.org/~esr/faqs/smart-questions.html#bespecific

The rest of the page is also a good read, and will help you to help
yourself, without waiting for the possibly acid remarks from a
newsgroup.

[1] i.e before your newbie credits run out:

http://groups.google.com/groups?as_drrb=q&q=kubaton&as_qdr=w&btnG=Google+Search

> This is returning an error on my server.
>
> $L1 = substr(split(/~/,$rqpairs{$param}))[5],0,1);

It would return errors on anyone's server, I suppose.

good luck


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

Date: 13 Oct 2003 23:05:53 GMT
From: "James E Keenan" <nospam_for_jkeen@concentric.net>
Subject: Re: Why Is My Hash Assignment Taking So Long?
Message-Id: <bmfb4h$t7@dispatch.concentric.net>


"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:bmdrkl$gji$1@mamenchi.zrz.TU-Berlin.DE...
> James E Keenan <nospam_for_jkeen@concentric.net> wrote in
comp.lang.perl.misc:
> > I need to build a hash whose elements represent characteristics of each
of
> > 9600 files in a single directory.  I am trying to figure out why this
hash
> > assignment is taking so long.  Here is my code:
>
> That's a lot of files to keep in a single directory.  That is the
> reason why it's slow.
>
> There are a few obvious inefficiencies in your code, but these have
> no measurable effect.
>
> >     my %threads_chars = (
> >         dir => "~/Threads",
> >         pattern => "\.thr\.txt",
>
> You have a quoting problem here.  Backslashing the dots in a *string*
> has no effect.  After the string is built, the backslashes are gone.
> Use qr// to quote patterns:
>
>         pattern => qr/\.thr\.txt/,
>

Ah!  An incentive to learn the 'qr' operator!.

> >     );
> >
> >     $threadsref = analyze_dir(\%threads_chars);
> >
> >     sub analyze_dir {
> >         my $hashref = shift;
> >         my $dir = ${$hashref}{'dir'};
> >         my $pattern = ${$hashref}{'pattern'};
> >         my (%filechars, $count);
> >         chdir $dir or die "Couldn't change to $dir: $!";
> >         opendir DIR, $dir or die "Couldn't open $dir: $!";
> >
> >         #1: get files in $dir which match pattern
> >         my @files = grep { m|$pattern$|o } readdir DIR;
>
> Why do you build a list of all files just to process them once?  Walk
> through the directory and skip what you don't want.  You'll save
> the list (space efficiency) and you'll only have to apply the regex
> once (time efficiency).
>
I was trying to think of the way to walk thru the directory, but I was just
too tired to think.  After a good night's sleep, I located the answer in the
Llama book, similar to what you have below.

> You should also take care to de-select anything that isn't a plain file.
>
As it happened, there was only one non-matching file in the directory.  But
your point is well taken and I've done that in other scripts.

> >         print '@files established for ', "$dir\n";
> >
> >         #2:  build a hash where each element is keyed by the core of the
> > file name
> >         #    and the value is a ref to an array holding the file name,
full
> > path, atime, mtime.
> >         #    Set a counter so I know how fast it's going
> >         foreach (@files) {
> >             $_ =~ m|^(.*)$pattern$|;
> >             my $core = $1;
> >             $filechars{$core} = [ $_, "$dir/$_", (stat($_))[8..9] ];
> >             $count++;
> >             if ($count % 100 == 0) { print 'count:  ', "$count\n";}
> >         }
> >         closedir DIR or die "Couldn't close $dir:  $!";
> >         print "$dir HAS BEEN ANALYZED\n";
> >         return \%filechars;
> >     }
> >
> > The counter prints to screen in 100-file increments.  The first couple
of
> > hundred files zip right by, but then the process slows to a crawl.  This
> > occurred despite there being no other significant activity happening on
this
> > disk.  Why?
>
> The stat() operation takes longer for files that are "late" in the
> directory, in the sense that readdir() produces them late.  Since
> your directory is oversized, the difference is significant.  Since
> you process the files in the order in which they were found, the process
> seems to slow down progressively.

Very interesting!

> To test the hypothesis, just change
>
>     my @files = grep { m|$pattern$|o } readdir DIR;
>
> in your code to
>
>     my @files = reverse grep { m|$pattern$|o } readdir DIR;
>
> and watch it start out slow and grow faster as it goes.  To gain speed,
> spread the files out over more smaller directories.
>
I'll test these out!  Thanks, Anno.

More generally, is the sort of too-many-files-in-a-directory slowdown I
experienced here true across operating systems?  Or just on this one
(Windows98 SE)?  (It does seem as if all directory-related operations
calling upon this directory are slow.)

jimk

jimk




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

Date: Mon, 13 Oct 2003 18:54:02 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: Wierdness with code to display file creation date
Message-Id: <exCib.6685$fv4.5540@nwrdny02.gnilink.net>

Dave Saville <dave.nospam@ntlworld.com> wrote:
> On Mon, 13 Oct 2003 09:24:44 -0500, Tony Curtis wrote:
> >ctime records inode (attribute, not content) changes.

[ snip: so don't rely on it being creation time ]
 
> Looks like you *might* rely on it on non-unix - this is perl
> 5.8 on OS/2 Warp. And I am sure windows has accessed/modified/created.

This is (at least partially) documented in perlport.

-- 
Steve


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

Date: Mon, 13 Oct 2003 20:08:35 GMT
From: Jorge Barrios <jorge.b@rrios.com>
Subject: Re: Writing a perl file comparison program
Message-Id: <m3r81hrmxd.fsf@www.drakonis.com>

kmall@lehman.com (Kulvinder Mall) writes:

> Hi 
> 
> I want to write perl utility to compare two text files.
> 
> The files will contain text in following format below.
> 
> I want to be able to compare the files and report on differences.
> 
> Rather than reinventing wheel can somebody throw me some pointers.
> 

A simple method would be to parse each file and load keys and values
into different hashes and then go through each key and compare
values. This method should work when the fields are not declared in
the same order on the files. Otherwise take a look at the diff utility
on *nix. Also, check CPAN for diff modules.



-- 
Jorge Barrios


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

Date: Mon, 13 Oct 2003 20:43:56 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Writing a perl file comparison program
Message-Id: <3F8B0E76.BBBE00F9@acm.org>

Kulvinder Mall wrote:
> 
> I want to write perl utility to compare two text files.
> 
> The files will contain text in following format below.
> 
> I want to be able to compare the files and report on differences.
> 
> Rather than reinventing wheel can somebody throw me some pointers.

perldoc File::Compare


John
-- 
use Perl;
program
fulfillment


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

Date: 13 Oct 2003 14:22:06 -0700
From: rjohnson@shell.com (Roy Johnson)
Subject: Re: Writing a perl file comparison program
Message-Id: <3ee08638.0310131322.7870da2d@posting.google.com>

kmall@lehman.com (Kulvinder Mall) wrote in message news:<29fa23df.0310130850.480210e0@posting.google.com>...
> 
> I want to write perl utility to compare two text files.

Would Algorithm::Diff get you there?

http://search.cpan.org/~nedkonz/Algorithm-Diff-1.15/lib/Algorithm/Diff.pm


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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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


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