[22321] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4542 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 10 19:12:03 2003

Date: Mon, 10 Feb 2003 16:06:43 -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           Mon, 10 Feb 2003     Volume: 10 Number: 4542

Today's topics:
    Re: Splitting lines from a temporary buffer <knewman00@earthlink.net>
    Re: Splitting lines from a temporary buffer <goldbb2@earthlink.net>
    Re: Splitting lines from a temporary buffer <knewman00@earthlink.net>
    Re: Splitting lines from a temporary buffer <goldbb2@earthlink.net>
    Re: Splitting lines from a temporary buffer (Kevin Newman)
        Statistics for comp.lang.perl.misc <gbacon@cs.uah.edu>
        Storing `ls -R` into an array (William English)
    Re: Storing `ls -R` into an array <nobull@mail.com>
    Re: strange localtime return (Shadowfax)
    Re: strange localtime return <spamtrap@nowhere.com>
    Re: strange localtime return <spamtrap@nowhere.com>
    Re: string in datei <pne-news-20030208@newton.digitalspace.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 08 Feb 2003 04:18:51 GMT
From: Kevin Newman <knewman00@earthlink.net>
Subject: Re: Splitting lines from a temporary buffer
Message-Id: <3E448EBB.6080706@earthlink.net>



Benjamin Goldberg wrote:
[snip]
> Actually, even better might be to assign to $buffer directly...  E.g. I
> could probably change my code to:
> 
>    my $terminator = qr/\015\012|[\015\012\000]/;
>    my $buffer = "";
>    while( sysread FH, $buffer, 4096, length $buffer ) {
>       my @lines = split /$terminator(?!\z)/, $buffer, -1;
>       $buffer = pop @lines;
>       print "[$_]\n" for @lines;
>    }
>    if( length $buffer ) {
>       my @lines = split /$terminator/, $buffer, -1; # no (?!\z)
>       if( length $lines[-1] ) { warn "Incomplete last line" }
>       else { pop @lines }
>       print "[$_]\n" for @lines;
>    }
> 
> There's now no need to "remove" anything from $buffer.
> 
> Hmm, this code looks rather simpler, ne?
> 
> [snip]
> 
>>I don't think it's worth while to do this in Perl.  If you really need
>>a regex as a line-terminator, I bet there's a module on CPAN.
> 
> 
> Actually, if you want a regex as a line-terminator, consider using awk,
> rather than perl... awk has that as one of it's built-in features.
> 
> Hmm, or if you *really* need speed, consider 'lex' or 'flex'. :)
> 

Thank you Ben! I was just about ready to give up.  I think this code is 
what I want.  Preliminary tests show that it works on my more "popular" 
data sets, but there is still much to be done.

Since this is my first encounter with sysread, I do have a couple of 
questions.  First should sysread be used with sysopen?  So far, all of 
my test files end with a warning because the end of file marker (?) or 
an extra blank line (?) is handled by the if( length $buffer ) block. 
How can I prevent this from happening?

Thanks again,

kln



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

Date: Sat, 08 Feb 2003 00:47:54 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Splitting lines from a temporary buffer
Message-Id: <3E449A09.3DF6FB50@earthlink.net>

Kevin Newman wrote:
> 
> Benjamin Goldberg wrote:
> [snip]
> > Actually, even better might be to assign to $buffer directly... 
> > E.g. I could probably change my code to:
> >
> >    my $terminator = qr/\015\012|[\015\012\000]/;
> >    my $buffer = "";
> >    while( sysread FH, $buffer, 4096, length $buffer ) {
> >       my @lines = split /$terminator(?!\z)/, $buffer, -1;
> >       $buffer = pop @lines;
> >       print "[$_]\n" for @lines;
> >    }
> >    if( length $buffer ) {
> >       my @lines = split /$terminator/, $buffer, -1; # no (?!\z)
> >       if( length $lines[-1] ) { warn "Incomplete last line" }
> >       else { pop @lines }
> >       print "[$_]\n" for @lines;
> >    }
> >
> > There's now no need to "remove" anything from $buffer.
> >
> > Hmm, this code looks rather simpler, ne?
> >
> > [snip]
> >
> >>I don't think it's worth while to do this in Perl.  If you really
> >>need a regex as a line-terminator, I bet there's a module on CPAN.
> >
> >
> > Actually, if you want a regex as a line-terminator, consider using
> > awk, rather than perl... awk has that as one of it's built-in
> > features.
> >
> > Hmm, or if you *really* need speed, consider 'lex' or 'flex'. :)
> 
> Thank you Ben! I was just about ready to give up.  I think this code
> is what I want.  Preliminary tests show that it works on my more
> "popular" data sets, but there is still much to be done.
> 
> Since this is my first encounter with sysread, I do have a couple of
> questions.  First should sysread be used with sysopen?

You can, but don't need to.

In modern perls (5.6.1), the only real difference is that with sysopen,
you pass the open-mode as a number, not as a string, and you can't get
the various magical opens (open to/from a pipe, open with verious perlio
layers), whereas with open, you pass the mode as a string, and do get
those other things.

> So far, all of my test files end with a warning because the end of
> file marker (?)

There is no such thing as an 'end of file marker'.  When sysread returns
zero, that indicates the end of file.  But there's no "marker", no
special byte or byte sequence within the file, which causes this -- it
happens because the position of the filehandle is at or beyond the
length of the file (which is part of the file header, stored along with
the file's permissions and such).

> or an extra blank line (?) is handled by the if( length $buffer )
> block.
> How can I prevent this from happening?

Unless my logic is wrong (and it might be!  I'm not infallible), you
should only get this warning if the last character(s) of the file ARE
NOT either NUL, CR, LF, or CRLF.  You should be able to avoid the
warning simply by adding a newline to the end of the file.

In other words, if the file consists of "foo\nbar\nbaz\n", then there
should be no warning, but if the file consists of "foo\nbar\nbaz", with
no trailing newline, then there should be a warning.  (Where "\n" could
be any of your terminator sequences.)

-- 
"So, who beat the clueless idiot today?"
"Well, we flipped for it, but when Kuno
 landed, he wasn't in any shape to fight."
"Next time, try flipping a *coin.*"


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

Date: Sun, 09 Feb 2003 02:38:24 GMT
From: Kevin Newman <knewman00@earthlink.net>
Subject: Re: Splitting lines from a temporary buffer
Message-Id: <3E45BEFD.60503@earthlink.net>



Benjamin Goldberg wrote:
> Kevin Newman wrote:
> 
>>Benjamin Goldberg wrote:
>>[snip]

>>Since this is my first encounter with sysread, I do have a couple of
>>questions.  First should sysread be used with sysopen?
> 
> You can, but don't need to.
> 
> In modern perls (5.6.1), the only real difference is that with sysopen,
> you pass the open-mode as a number, not as a string, and you can't get
> the various magical opens (open to/from a pipe, open with verious perlio
> layers), whereas with open, you pass the mode as a string, and do get
> those other things.
> 

That's good to know.  I have 5.6.1 and 5.8.0 on my pc, but the system 
that this code is to be used on has 5.005_03.

> 
>>So far, all of my test files end with a warning because the end of
>>file marker (?)
> 
> 
> There is no such thing as an 'end of file marker'.  When sysread returns
> zero, that indicates the end of file.  But there's no "marker", no
> special byte or byte sequence within the file, which causes this -- it
> happens because the position of the filehandle is at or beyond the
> length of the file (which is part of the file header, stored along with
> the file's permissions and such).
> 

Understood.  However, some DOS\Windows apps use(d) ^Z to mark the end of 
the file.  The test files that I was working with had ^Z on the last 
line of the file.

>>or an extra blank line (?) is handled by the if( length $buffer )
>>block.
>>How can I prevent this from happening?
> 
> 
> Unless my logic is wrong (and it might be!  I'm not infallible), you
> should only get this warning if the last character(s) of the file ARE
> NOT either NUL, CR, LF, or CRLF.  You should be able to avoid the
> warning simply by adding a newline to the end of the file.
> 
> In other words, if the file consists of "foo\nbar\nbaz\n", then there
> should be no warning, but if the file consists of "foo\nbar\nbaz", with
> no trailing newline, then there should be a warning.  (Where "\n" could
> be any of your terminator sequences.)
> 

Okay.


Thanks, I still have much to learn.

kln



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

Date: Sat, 08 Feb 2003 23:42:41 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Splitting lines from a temporary buffer
Message-Id: <3E45DC41.4E8CC639@earthlink.net>

Kevin Newman wrote:
> Benjamin Goldberg wrote:
> > Kevin Newman wrote:
[snip]
> >> So far, all of my test files end with a warning because the end of
> >> file marker (?)
> >
> > There is no such thing as an 'end of file marker'.  When sysread
> > returns zero, that indicates the end of file.  But there's no
> > "marker", no special byte or byte sequence within the file, which
> > causes this -- it happens because the position of the filehandle is
> > at or beyond the length of the file (which is part of the file
> > header, stored along with the file's permissions and such).
> 
> Understood.  However, some DOS\Windows apps use(d) ^Z to mark the end
> of the file.  The test files that I was working with had ^Z on the
> last line of the file.

Ahh, I see.  The ^Z character causes an artificial EOF condition (even
if there's data after it in the file) when the file is being read using
<>, or readline(), or read().  When the file is read using sysread(),
then ^Z appears as an ordinary character.

It should be harmless to change the sysread() to a read() call, and
leave everything else the same -- this should result in the ^Z being
treated as if were a real EOF.

(I usually prefer sysread because it's a bit faster, due to it's
bypassing of stdio/perlio buffering, and since you *must* use sysread if
you're multiplexing filehandles (sockets), but it has a side effect of
producing data as if the file had been binmode()ed -- that's not a
problem on sockets, but is a problem on text-mode file handles)

-- 
"So, who beat the clueless idiot today?"
"Well, we flipped for it, but when Kuno
 landed, he wasn't in any shape to fight."
"Next time, try flipping a *coin.*"


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

Date: 10 Feb 2003 10:02:20 -0800
From: knewman00@earthlink.net (Kevin Newman)
Subject: Re: Splitting lines from a temporary buffer
Message-Id: <4c8e4398.0302101002.11cb5b27@posting.google.com>

Benjamin Goldberg <goldbb2@earthlink.net> wrote in message news:<3E45DC41.4E8CC639@earthlink.net>...
> Kevin Newman wrote:
> > Benjamin Goldberg wrote:
> > > Kevin Newman wrote:
>  [snip]
> > >> So far, all of my test files end with a warning because the end of
> > >> file marker (?)
> > >
> > > There is no such thing as an 'end of file marker'.  When sysread
> > > returns zero, that indicates the end of file.  But there's no
> > > "marker", no special byte or byte sequence within the file, which
> > > causes this -- it happens because the position of the filehandle is
> > > at or beyond the length of the file (which is part of the file
> > > header, stored along with the file's permissions and such).
> > 
> > Understood.  However, some DOS\Windows apps use(d) ^Z to mark the end
> > of the file.  The test files that I was working with had ^Z on the
> > last line of the file.
> 
> Ahh, I see.  The ^Z character causes an artificial EOF condition (even
> if there's data after it in the file) when the file is being read using
> <>, or readline(), or read().  When the file is read using sysread(),
> then ^Z appears as an ordinary character.

> It should be harmless to change the sysread() to a read() call, and
> leave everything else the same -- this should result in the ^Z being
> treated as if were a real EOF.

It was easy enough to fix with sysread:
if ( s/\x1A//)	{print "$_";}

Besides, it should be removed because it's a useless character.
 
> (I usually prefer sysread because it's a bit faster, due to it's
> bypassing of stdio/perlio buffering, and since you *must* use sysread if
> you're multiplexing filehandles (sockets), but it has a side effect of
> producing data as if the file had been binmode()ed -- that's not a
> problem on sockets, but is a problem on text-mode file handles)

Thanks again,

kln


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

Date: Mon, 10 Feb 2003 14:11:06 -0000
From: Greg Bacon <gbacon@cs.uah.edu>
Subject: Statistics for comp.lang.perl.misc
Message-Id: <v4fcnq5r0m8s13@corp.supernews.com>

Following is a summary of articles spanning a 7 day period,
beginning at 03 Feb 2003 14:25:09 GMT and ending at
10 Feb 2003 14:05:07 GMT.

Notes
=====

    - A line in the body of a post is considered to be original if it
      does *not* match the regular expression /^\s{0,3}(?:>|:|\S+>|\+\+)/.
    - All text after the last cut line (/^-- $/) in the body is
      considered to be the author's signature.
    - The scanner prefers the Reply-To: header over the From: header
      in determining the "real" email address and name.
    - Original Content Rating (OCR) is the ratio of the original content
      volume to the total body volume.
    - Find the News-Scan distribution on the CPAN!
      <URL:http://www.perl.com/CPAN/modules/by-module/News/>
    - Please send all comments to Greg Bacon <gbacon@cs.uah.edu>.
    - Copyright (c) 2003 Greg Bacon.
      Verbatim copying and redistribution is permitted without royalty;
      alteration is not permitted.  Redistribution and/or use for any
      commercial purpose is prohibited.

Excluded Posters
================

perlfaq-suggestions\@(?:.*\.)?perl\.com
faq\@(?:.*\.)?denver\.pm\.org
comdog\@panix\.com

Totals
======

Posters:  256
Articles: 870 (368 with cutlined signatures)
Threads:  190
Volume generated: 1707.8 kb
    - headers:    774.6 kb (14,538 lines)
    - bodies:     881.5 kb (29,013 lines)
    - original:   545.1 kb (19,413 lines)
    - signatures: 50.8 kb (1,185 lines)

Original Content Rating: 0.618

Averages
========

Posts per poster: 3.4
    median: 2.0 posts
    mode:   1 post - 126 posters
    s:      6.5 posts
Posts per thread: 4.6
    median: 3.0 posts
    mode:   2 posts - 40 threads
    s:      8.7 posts
Message size: 2010.1 bytes
    - header:     911.7 bytes (16.7 lines)
    - body:       1037.6 bytes (33.3 lines)
    - original:   641.5 bytes (22.3 lines)
    - signature:  59.8 bytes (1.4 lines)

Top 10 Posters by Number of Posts
=================================

         (kb)   (kb)  (kb)  (kb)
Posts  Volume (  hdr/ body/ orig)  Address
-----  --------------------------  -------

   57   113.4 ( 47.8/ 56.7/ 32.6)  Benjamin Goldberg <goldbb2@earthlink.net>
   43   124.0 ( 49.6/ 68.7/ 55.2)  tadmc@augustmail.com
   34    74.8 ( 32.1/ 37.6/ 34.4)  abigail@abigail.nl
   30    53.8 ( 22.7/ 31.1/ 12.4)  Anno Siegel <anno4000@lublin.zrz.tu-berlin.de>
   27    67.8 ( 26.9/ 34.8/ 19.2)  tassilo.parseval@post.rwth-aachen.de
   24    59.5 ( 26.1/ 26.1/ 13.1)  Uri Guttman <uri@stemsystems.com>
   20    62.9 ( 19.4/ 40.3/ 26.7)  mgjv@tradingpost.com.au
   17    28.0 ( 16.0/ 12.0/  5.4)  "Jürgen Exner" <jurgenex@hotmail.com>
   15    28.0 ( 20.0/  8.0/  6.3)  "mgarrish" <mgarrish@rogers.com>
   15    23.8 ( 13.0/  9.8/  2.7)  "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>

These posters accounted for 32.4% of all articles.

Top 10 Posters by Volume
========================

  (kb)   (kb)  (kb)  (kb)
Volume (  hdr/ body/ orig)  Posts  Address
--------------------------  -----  -------

 124.0 ( 49.6/ 68.7/ 55.2)     43  tadmc@augustmail.com
 113.4 ( 47.8/ 56.7/ 32.6)     57  Benjamin Goldberg <goldbb2@earthlink.net>
  74.8 ( 32.1/ 37.6/ 34.4)     34  abigail@abigail.nl
  67.8 ( 26.9/ 34.8/ 19.2)     27  tassilo.parseval@post.rwth-aachen.de
  62.9 ( 19.4/ 40.3/ 26.7)     20  mgjv@tradingpost.com.au
  59.5 ( 26.1/ 26.1/ 13.1)     24  Uri Guttman <uri@stemsystems.com>
  53.8 ( 22.7/ 31.1/ 12.4)     30  Anno Siegel <anno4000@lublin.zrz.tu-berlin.de>
  28.0 ( 16.0/ 12.0/  5.4)     17  "Jürgen Exner" <jurgenex@hotmail.com>
  28.0 ( 20.0/  8.0/  6.3)     15  "mgarrish" <mgarrish@rogers.com>
  26.8 ( 10.8/ 15.1/  8.6)     12  Brian McCauley <nobull@mail.com>

These posters accounted for 37.4% of the total volume.

Top 10 Posters by Volume of Original Content (min. five posts)
==============================================================

        (kb)
Posts   orig  Address
-----  -----  -------

   43   55.2  tadmc@augustmail.com
   34   34.4  abigail@abigail.nl
   57   32.6  Benjamin Goldberg <goldbb2@earthlink.net>
   20   26.7  mgjv@tradingpost.com.au
   27   19.2  tassilo.parseval@post.rwth-aachen.de
   24   13.1  Uri Guttman <uri@stemsystems.com>
   30   12.4  Anno Siegel <anno4000@lublin.zrz.tu-berlin.de>
    7   12.1  Shing-Fat Fred Ma <fma@doe.carleton.ca>
   12    9.6  "Janek Schleicher" <bigj@kamelfreund.de>
   12    8.6  Brian McCauley <nobull@mail.com>

These posters accounted for 41.1% of the original volume.

Top 10 Posters by OCR (minimum of five posts)
==============================================

         (kb)    (kb)
OCR      orig /  body  Posts  Address
-----  --------------  -----  -------

0.913  ( 34.4 / 37.6)     34  abigail@abigail.nl
0.856  (  7.5 /  8.8)      5  Mina Naguib <spam@thecouch.homeip.net>
0.804  ( 55.2 / 68.7)     43  tadmc@augustmail.com
0.792  (  6.3 /  8.0)     15  "mgarrish" <mgarrish@rogers.com>
0.725  (  5.5 /  7.6)     12  "Alan J. Flavell" <flavell@mail.cern.ch>
0.709  (  3.8 /  5.3)      6  Allan Cady <allancady@yahoo.com>
0.696  ( 12.1 / 17.4)      7  Shing-Fat Fred Ma <fma@doe.carleton.ca>
0.684  (  1.7 /  2.5)      5  xyf@nixnotes.org
0.668  (  2.8 /  4.2)      5  John English <je@brighton.ac.uk>
0.666  (  3.2 /  4.7)      5  Jeff Zucker <jeff@vpservices.com>

Bottom 10 Posters by OCR (minimum of five posts)
================================================

         (kb)    (kb)
OCR      orig /  body  Posts  Address
-----  --------------  -----  -------

0.427  (  1.7 /  4.0)      5  Tony Curtis <tony_curtis32@yahoo.com>
0.403  (  1.4 /  3.4)      7  "Tintin" <me@privacy.net>
0.397  ( 12.4 / 31.1)     30  Anno Siegel <anno4000@lublin.zrz.tu-berlin.de>
0.384  (  3.6 /  9.3)     10  zenskin
0.362  (  2.7 /  7.4)      5  andrew
0.322  (  2.2 /  6.9)      7  Jeff D Gleixner <glex_nospam@qwest.net>
0.320  (  1.9 /  6.0)      7  Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
0.313  (  0.5 /  1.7)      6  Ingo Wichmann <w_ichmann@uni-wuppertal.de>
0.273  (  2.7 /  9.8)     15  "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
0.255  (  1.9 /  7.5)      8  "John W. Krahn" <krahnj@acm.org>

38 posters (14%) had at least five posts.

Top 10 Threads by Number of Posts
=================================

Posts  Subject
-----  -------

   36  Crossposting (was: Fetchrow Question)
   28  string in datei
   26  Perl operators in variables
   20  Why no perl function to detect numeric or string?
   14  can't locate Mail/MboxParser.pm in @INC
   13  sort, my concoction of
   12  Help with arrays and such, please.
   12  I'm just not getting it... FAQ5
   11  What do you think of this?
   11  Until loop not working with multiple conditions

These threads accounted for 21.0% of all articles.

Top 10 Threads by Volume
========================

  (kb)   (kb)  (kb)  (kb)
Volume (  hdr/ body/ orig)  Posts  Subject
--------------------------  -----  -------

  72.4 ( 27.4/ 41.7/ 29.0)     26  Perl operators in variables
  71.2 ( 44.9/ 23.9/ 12.9)     36  Crossposting (was: Fetchrow Question)
  51.8 ( 21.9/ 28.1/ 15.9)     20  Why no perl function to detect numeric or string?
  51.3 ( 27.0/ 22.4/ 12.4)     28  string in datei
  36.0 ( 12.0/ 23.5/ 11.1)     12  Help with arrays and such, please.
  34.0 (  2.1/ 32.0/ 32.0)      2  Posting Guidelines for comp.lang.perl.misc ($Revision: 1.3 $)
  33.7 ( 12.5/ 19.1/ 13.6)     13  sort, my concoction of
  30.2 (  9.4/ 19.8/  8.6)     10  Splitting lines from a temporary buffer
  28.7 ( 14.1/ 13.7/  6.4)     14  can't locate Mail/MboxParser.pm in @INC
  23.5 ( 10.3/ 12.6/  6.8)     12  I'm just not getting it... FAQ5

These threads accounted for 25.3% of the total volume.

Top 10 Threads by OCR (minimum of five posts)
=============================================

         (kb)    (kb)
OCR      orig /  body  Posts  Subject
-----  --------------  -----  -------

0.809  (  3.9/   4.8)      9  Argument detection not working
0.789  (  5.3/   6.8)      6  Can't use an undefined value as an ARRAY reference
0.778  (  2.5/   3.2)      5  question
0.759  (  3.0/   4.0)      5  Aren't there any functions in perl similar to print_r in PHP?
0.751  (  3.2/   4.2)      5  100 levels deep redux.
0.748  (  8.8/  11.7)     10  Regex difficulty
0.747  (  2.2/   3.0)      7  matching with [
0.724  (  5.4/   7.5)      7  Strange behaviour using underscore "_" as a subroutine name
0.717  (  3.0/   4.2)      6  PERL + SQL
0.716  ( 13.6/  19.1)     13  sort, my concoction of

Bottom 10 Threads by OCR (minimum of five posts)
================================================

         (kb)    (kb)
OCR      orig /  body  Posts  Subject
-----  --------------  -----  -------

0.435  (  8.6 / 19.8)     10  Splitting lines from a temporary buffer
0.434  (  3.7 /  8.4)      9  Quick regexp question
0.423  (  2.4 /  5.6)      8  Help with split() command
0.418  (  2.1 /  5.1)      7  Carriage Returns (ARG!)
0.402  (  2.3 /  5.7)      7  'Flatten' array of phrases
0.402  (  2.8 /  6.9)      5  How do you: 'make install PREFIX=somepath', and then platform-independantly find somepath?
0.396  (  2.5 /  6.2)      5  grab lines and format
0.377  (  0.8 /  2.2)      5  Perl scripts utilizing Openview Omniback commands
0.276  (  1.6 /  5.9)      7  Question on back-quotes
0.253  (  1.9 /  7.6)      9  Simple regexp gots me stuck...

75 threads (39%) had at least five posts.

Top 8 Targets for Crossposts
============================

Articles  Newsgroup
--------  ---------

      40  alt.perl
       6  comp.lang.php
       6  alt.comp.lang.coldfusion
       6  comp.lang.perl
       5  comp.lang.awk
       5  microsoft.public.inetserver.iis
       5  comp.unix.shell
       3  gnu.g++.help

Top 10 Crossposters
===================

Articles  Address
--------  -------

      12  "mgarrish" <mgarrish@rogers.com>
       8  Benjamin Goldberg <goldbb2@earthlink.net>
       5  Uri Guttman <uri@stemsystems.com>
       4  "Jim Davis" <newsmonkey@vboston.com>
       4  Tim Cargile <tecargile@hotmail.com>
       4  "Smiley" <smiley@uvgotemail.com>
       3  Shing-Fat Fred Ma <fma@doe.carleton.ca>
       3  "Jürgen Exner" <jurgenex@hotmail.com>
       2  "Erik Allen" <newsemail@erikallen.com>
       2  "George Bouras" <novastar@novastar.dtdns.net>


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

Date: 10 Feb 2003 10:09:19 -0800
From: william_english@mentor.com (William English)
Subject: Storing `ls -R` into an array
Message-Id: <7a735a20.0302101009.29c8588e@posting.google.com>

I am doing this:

@dirContents = `ls -R`;

When I do a foreach and print each line, I get results like this:

nt_empty_tree:
_bin
_lib
bin
data
lib
licenses
userware
file1
file2

When I just do an 'ls -R' from the command line, I get this:

 ./nt_empty_tree:
_bin/
_lib/
bin/
data/
lib/
licenses/
userware/
file1
file2

If you notice, directories have a "/" at the end and files do not. The
array however does not have the "/" at the end. How can I tell what is
a directory? I know the first element in my example of 'ls -R' from
the command line has an ":" at the end, so I set the directory path to
that, but sometimes it is long:

 ./nt_empty_tree/_bin/tools/sae_tools/lib/perl5/bin:


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

Date: 10 Feb 2003 18:30:00 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Storing `ls -R` into an array
Message-Id: <u98ywo6lav.fsf@wcl-l.bham.ac.uk>

william_english@mentor.com (William English) writes:

> I am doing this:
> 
> @dirContents = `ls -R`;

Why, for $DEITY's sake!?  

File::Find exists and is even in the standard distribution.

> When I do a foreach and print each line, I get results like this:

> bin

> When I just do an 'ls -R' from the command line, I get this:

> _bin/

> If you notice, directories have a "/" at the end and files do not.

Looks to me as if from the command line you are really doing 'ls -FR'.

Probably got a shell alias or an environment variable in the
interactive shell.

> How can I tell what is a directory?

-d

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 7 Feb 2003 10:52:32 -0800
From: shadowfax@optonline.net (Shadowfax)
Subject: Re: strange localtime return
Message-Id: <22e9b972.0302071052.7a8e7993@posting.google.com>

 ...
> 
> >	$new_filename=$YYYYMMDD."_".$file_date{$YYYYMMDD};
> 
> So the sum of what you are doing is to take the old file name and set it
> to $YYYYMMDD_1?  Why do you need hashes to do that??

ok, the script is intended to rename files in specific directory to
YYYYMMDD_x, if YYYYMMDD_1 exist then name the new file with same date
to YYYYMMDD_2, and so on...  The reason I want to use hash is because
I don't want to scan the directory to find out are there any file with
name YYYYMMDD_x exist already when it processing a new file.

-Shadowfax


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

Date: Fri, 07 Feb 2003 20:40:05 GMT
From: Andrew Lee <spamtrap@nowhere.com>
Subject: Re: strange localtime return
Message-Id: <sc684v0s1cduf9234ejiqcm8mkjqpbrv28@4ax.com>

On 5 Feb 2003 23:04:15 -0800, shadowfax@optonline.net (Shadowfax) wrote:

>Thanks all for the reply. 
>
>I make some progress but stuck on below error again, it seems all the
>variable was initialized already.
>"Use of uninitialized value in addition (+) at E:\temp\rename.pl line
>29 "
>
>Thanks,
>Shadowfax
>
>use strict;
>use warnings;
>use Time::localtime;
>use File::stat;
>
>my %file_date=();

You don't have to init %file_date to an empty list.

>my $YYYYMMDD;
>my $org_file;
>my $mtime;
>my $new_filename;
>my %month_translate=("Jan","01","Feb","02","Mar","03","Apr","04","May","05","Jun","06","Jul","07","Aug","08","Sep","09","Oct","10","Nov","11","Dec","12");
>my $org_dir="E:/temp/v";
>
>opendir(DIR,$org_dir)||die "can't open original directory $org_dir" ;
>my @org_files=readdir(DIR) ;
>closedir(DIR) ;
>
>foreach $org_file(@org_files)
>{
>	$mtime=ctime(stat("$org_dir/$org_file")->mtime);
>	my ($wday,$mon,$mday,$min,$year)=split(/\s+/,$mtime);
>	$YYYYMMDD = sprintf ("%4d%02d%02d", $year, $month_translate{$mon},
>$mday);
>
>#	print "$org_file\n";
>#	print "Modified Time: $YYYYMMDD\n";
>	while (undef $file_date{$YYYYMMDD}) {
>		$file_date{$YYYYMMDD}=0;

Why are you testing to see if $file_date is undefined?  of course it is
 ... no need to set it to 0 ... it islready undefined!  :-)

>	}
>	$file_date{$YYYYMMDD} = $file_date{$YYYYMMDD} + 1;

just say $file_date{$YYYYMMDD}++ .. less typing -- not sure why you are
getting an error here.

>	$new_filename=$YYYYMMDD."_".$file_date{$YYYYMMDD};

So the sum of what you are doing is to take the old file name and set it
to $YYYYMMDD_1?  Why do you need hashes to do that??




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

Date: Fri, 07 Feb 2003 20:42:24 GMT
From: Andrew Lee <spamtrap@nowhere.com>
Subject: Re: strange localtime return
Message-Id: <te684v4i1jehpgajid6fqqv8jirv133kb1@4ax.com>

On 7 Feb 2003 10:52:32 -0800, shadowfax@optonline.net (Shadowfax) wrote:

>...
>> 
>> >	$new_filename=$YYYYMMDD."_".$file_date{$YYYYMMDD};
>> 
>> So the sum of what you are doing is to take the old file name and set it
>> to $YYYYMMDD_1?  Why do you need hashes to do that??
>
>ok, the script is intended to rename files in specific directory to
>YYYYMMDD_x, if YYYYMMDD_1 exist then name the new file with same date
>to YYYYMMDD_2, and so on...  The reason I want to use hash is because
>I don't want to scan the directory to find out are there any file with
>name YYYYMMDD_x exist already when it processing a new file.

Clear now.

Try the $hash{key}++ semantics.

Let Perl do the work  :-)


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

Date: Sat, 08 Feb 2003 16:46:19 +0100
From: Philip Newton <pne-news-20030208@newton.digitalspace.net>
Subject: Re: string in datei
Message-Id: <4v8a4vgtlqg6r347j9th7von2imckck8pk@4ax.com>

On Thu, 6 Feb 2003 15:20:04 +0000 (UTC),
mauzo@ux-ma160-17.csv.warwick.ac.uk (Ben Morrow) wrote:

> I was under the impression that discussions in the 
> non-regional groups were conventionally carried out
> in English.

FWIW, that is my impression of the "intended purpose" for "Big8" groups
as well (with the exception of some groups such as soc.culture.* and
groups specifically about particular natural languages or groups
thereof, such as sci.lang.japan). As picked up from news.groups, for
example.

I'm not saying I agree or disagree, but that is my perception of the
situation.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

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


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