[21708] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3912 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 4 03:05:52 2002

Date: Fri, 4 Oct 2002 00:05:09 -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           Fri, 4 Oct 2002     Volume: 10 Number: 3912

Today's topics:
    Re: Best Method to Check Remote Directory <cbenedict@comcast.net>
    Re: Best Method to Check Remote Directory (BUCK NAKED1)
    Re: Calling a shell from perl without losing control (Bryan Castillo)
        case insensitive -f and -d (Kiyohiro Honda)
    Re: cgi woes <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
    Re: IO::Select has limits? or how to use IO::Poll? <crudmail@cox.net>
    Re: IO::Select has limits? or how to use IO::Poll? <goldbb2@earthlink.net>
    Re: New Perl Module for QA Engineers <comdog@panix.com>
        nice comments in linux src (Vishal Agarwal)
    Re: Printing text to a file <dha@panix2.panix.com>
    Re: Script to Change Filename <brittedg@student.gvsu.edu>
    Re: Script to Change Filename <s_grazzini@hotmail.com>
    Re: Script to Change Filename <wsegrave@mindspring.com>
    Re: What is the best way for file/stream IO in Perl? <paul@pco.iis.nsk.su>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 3 Oct 2002 23:34:10 -0500
From: "Chris" <cbenedict@comcast.net>
Subject: Re: Best Method to Check Remote Directory
Message-Id: <_MqcnWSq0txvhACgXTWcoA@News.GigaNews.Com>


"Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
news:3D9CD893.F81809C2@earthlink.net...
> Chris wrote:
> >
> > What is the best perl method to check a remote directory recursively
> > to see what files and directories uploaded correctly? I'm using
> > Net::FTP, and I cannot get a Recursive directory listing with
> > $ftp->ls() or $ftp->dir(). However, that's probably not the best way.
>
> It's close, though.
>
>    my @files = grep !/^\.\.?\z/,
>       @{ $ftp->list() or die horribly };
>    my %results = ( "." => [@files] );
>    while( @files ) {
>       my $path = shift @files;
>       my $subdir = $ftp->list($path) or next;
>       $results{$path} = $subdir;
>       push @files, map "$path/$_",
>          grep !/^\.\.?\z/, @$subdir;
>    }
>
>    require Data::Dumper;
>    print Data::Dumper::Dump( \%results );
>
> [untested]
>
> --
> How many Monks would a Chipmonk chip,
> if a Chipmonk could chip Monks?

Hmm... I get an Array error? However, if I change $ftp->list() to $ftp->ls,
that error goes away; but how do I print the hash out? The Data::Dumper code
you supplied doesn't print anything.




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

Date: Fri, 4 Oct 2002 00:49:24 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Best Method to Check Remote Directory
Message-Id: <11315-3D9D2BE4-266@storefull-2275.public.lawson.webtv.net>

This will print out the hash.

foreach my $key ( keys %results ) { 
        my $value = $results{$key}; 
        print "$key<BR>\n"; 
           }


Kind Regards,
Dennis



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

Date: 3 Oct 2002 22:33:31 -0700
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: Calling a shell from perl without losing control
Message-Id: <1bff1830.0210032133.7158a963@posting.google.com>

> the perl script. I'd like to go one step further. I'm interested in
> executing the shell and run a few shell scripts *within* the shell and
> then hand over the control to the perl program.

Why would you need to do this?  It doesn't make much sense to me.  I'm
sure what ever you are trying to do would be done better directly from
perl.


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

Date: 3 Oct 2002 23:55:57 -0700
From: kiyo9876@yahoo.co.jp (Kiyohiro Honda)
Subject: case insensitive -f and -d
Message-Id: <2ca34ccc.0210032255.5f3e9047@posting.google.com>

Hi,guys!
Would you please give me your suggestions?

I want a function that is similar to -f and -d , BUT
which ignore lower and upper case.
For example, when I put "/Foo/BAR/Aaa.gif" to the function
and there exists "/fOO/Bar/aAa.gif", then the fucntion returns true.

please show me some example code.

Tnank you very much in advance.
#and sorry for my broken English.

K


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

Date: Fri, 04 Oct 2002 08:29:18 +0200
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: cgi woes
Message-Id: <newscache$u02g3h$1u8$1@news.emea.compuware.com>

Paul Kirk wrote (Thursday 03 October 2002 17:13):

> My IT will not
> let me use the cgi section of the server until the script has been
> verified, which I am finding hard as I can not test it!

If you have one, you can install Perl and Apache in your home directory.

-- 
KP



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

Date: Fri, 04 Oct 2002 04:46:00 GMT
From: Joel Nelson <crudmail@cox.net>
Subject: Re: IO::Select has limits? or how to use IO::Poll?
Message-Id: <3D9D1EB4.1F0688BE@cox.net>

Benjamin tried to help Joel with::::

> > I am trying to build both client and server pieces that can be used to
> > stress test a server program being written at work.  We run these
> > scripts under windows (blech)...
> >
> > The problem with the server piece is that I need to be able to handle
> > at least 1024 connections.  IO::Select seems to choke at 127
> > connections(clients time out),
>
> This is a system imposed limitation; it's not perl's fault, but the
> fault of the underlying C function call.

Hmmm, I'm not a C guy.  But how are servers written to handle large numbers
of connections (even on windows, like Apache)?

> > and I am having trouble trying to use arrays of IO::Select objects.
>
> That's not likely going to work, unless you use timeouts of zero on all
> of them... That is, something like:
>
>    while( 1 ) {
>       foreach my $fh ( map $_->can_read(0), @io_select_objects ) {

It looks like your suggesting I don't use the IO::Select but to hold the
handles in an array?  Then I can do my own can_read(0) calls on the handle?

> > I have also taken a look at IO::Poll but I don't understand how to
> > use it.

> You're assuming that it doesn't suffer from the same limitation as

> select... it might.  Anyway, assuming it doesn't:

According to what little I have read, Poll uses a some sort of vector bitmap
that allows it to search through large numbers of handles faster.  I took
that to mean it CAN handle large numbers of handles.  Hehe, never assume,
right?

> If you have a filehandle which you want to watch for readability, do:
>    $poll->mask( $fh, POLLIN );
> If you have a filehandle which you want to watch for writability, do:
>    $poll->mask( $fh, POLLOUT );
> To watch a handle for both reading and writing:
>    $poll->mask( $fh, POLLIN|POLLOUT );
> To stop watching a handle, do:
>    $poll->mask( $fh, 0 );
>
> To block until some handles are ready for reading or writing, and to
> find out what those handles are, do:
>    $poll->poll( $timeout );
>    my @readok  = $poll->handles( POLLRDNORM );
>    my @writeok = $poll->handles( POLLWRNORM );

I did a test and set up a handle in poll with POLLIN|POLLOUT.  I tried a
$poll->handles(POLLOUT) and it returned 0.  Did that mean that no handles
were ready for writing?  I guess I'm confused about when a handle would be
ready for writing.  Seems like it should most always be.

> > Does anyone know how I can handle 1024 connections?
>
> You could create 9 child processes, have each of them handle 113
> connections (plus a connection to the parent), and have the children
> multiplex data from the clients, and the parent multiplex data from the
> children... But this can get kinda ugly.

It's worth a try.  So I should fork of 9 children that each use their own
IO::Select object?  I may give that a shot.

> Possibly you could manage something with some Windows specific function,
> perhaps WaitForMultipleObjects ... (I don't pretend to understand all of
> the windows APIs... I'm just guessing here).

I know you can call WaitForMultipleObjects in C, can you do that from perl?

> > The other piece I am writing is a single script that can launch the
> > 1024 connections.  I'll probably run into the same issues for
> > lots-o-connections but I may be able to run the same script multiple
> > times in different DOS windows and even on multiple machines.  Of
> > course, I'd rather not.
>
> If you start your child processes with IPC::Open2, it shouldn't open new
> DOS windows -- nor if you start child processes with Win32::Process.

Hmmm, I'll check that out too!

> How many Monks would a Chipmonk chip,
> if a Chipmonk could chip Monks?

Three!    :-)

Thanks for the help!



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

Date: Fri, 04 Oct 2002 01:04:17 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: IO::Select has limits? or how to use IO::Poll?
Message-Id: <3D9D2151.C341CF0B@earthlink.net>

Joel Nelson wrote:
> 
> Benjamin tried to help Joel with::::
> 
> > > I am trying to build both client and server pieces that can be used to
> > > stress test a server program being written at work.  We run these
> > > scripts under windows (blech)...
> > >
> > > The problem with the server piece is that I need to be able to handle
> > > at least 1024 connections.  IO::Select seems to choke at 127
> > > connections(clients time out),
> >
> > This is a system imposed limitation; it's not perl's fault, but the
> > fault of the underlying C function call.
> 
> Hmmm, I'm not a C guy.  But how are servers written to handle large numbers
> of connections (even on windows, like Apache)?

Dunno... download Apache and look at the source?

> > > and I am having trouble trying to use arrays of IO::Select objects.
> >
> > That's not likely going to work, unless you use timeouts of zero on all
> > of them... That is, something like:
> >
> >    while( 1 ) {
> >       foreach my $fh ( map $_->can_read(0), @io_select_objects ) {
> 
> It looks like your suggesting I don't use the IO::Select but to hold the
> handles in an array?  Then I can do my own can_read(0) calls on the handle?

can_read is a method of IO::Select.  I'm suggesting that @io_select_objects
be an array of IO::Select objects, and you use that method.

[snip]
> > If you have a filehandle which you want to watch for readability, do:
> >    $poll->mask( $fh, POLLIN );
> > If you have a filehandle which you want to watch for writability, do:
> >    $poll->mask( $fh, POLLOUT );
> > To watch a handle for both reading and writing:
> >    $poll->mask( $fh, POLLIN|POLLOUT );
> > To stop watching a handle, do:
> >    $poll->mask( $fh, 0 );
> >
> > To block until some handles are ready for reading or writing, and to
> > find out what those handles are, do:
> >    $poll->poll( $timeout );
> >    my @readok  = $poll->handles( POLLRDNORM );
> >    my @writeok = $poll->handles( POLLWRNORM );
> 
> I did a test and set up a handle in poll with POLLIN|POLLOUT.  I tried a
> $poll->handles(POLLOUT) and it returned 0.

Did you call $poll->poll before calling $poll->handles(POLLOUT)?

Remember, when you call $poll->handles, all it's doing is showing you
the results of the last call to the ->poll method.

> Did that mean that no handles were ready for writing?  I guess I'm
> confused about when a handle would be ready for writing.  Seems like
> it should most always be.

Yes, any connected socket should be ready for writing, unless you've
written a large amount of data and it hasn't yet been read.

> > > Does anyone know how I can handle 1024 connections?
> >
> > You could create 9 child processes, have each of them handle 113
> > connections (plus a connection to the parent), and have the children
> > multiplex data from the clients, and the parent multiplex data from the
> > children... But this can get kinda ugly.
> 
> It's worth a try.  So I should fork of 9 children that each use their own
> IO::Select object?  I may give that a shot.
> 
> > Possibly you could manage something with some Windows specific function,
> > perhaps WaitForMultipleObjects ... (I don't pretend to understand all of
> > the windows APIs... I'm just guessing here).
> 
> I know you can call WaitForMultipleObjects in C, can you do that from perl?

With Win32::API, I suppose.  I'm not a Windows guru, though, so I'm not
quite sure how you would go about constructing the parameters.

[snip]
> > How many Monks would a Chipmonk chip,
> > if a Chipmonk could chip Monks?
> 
> Three!    :-)

Ok, but where do you get that number from, though?  I've seen "Nun"
as an answer (coming from Monk vs Nun), but three?

-- 
How many Monks would a Chipmonk chip,
if a Chipmonk could chip Monks?


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

Date: Fri, 04 Oct 2002 01:52:41 -0500
From: brian d foy <comdog@panix.com>
Subject: Re: New Perl Module for QA Engineers
Message-Id: <041020020152410697%comdog@panix.com>

In article <pkent77tea-CC73FD.02153104102002@news-text.blueyonder.co.uk>, pkent <pkent77tea@yahoo.com.tea> wrote:

> In article <031020021645572449%comdog@panix.com>,
>  brian d foy <comdog@panix.com> wrote:

> > > with but a small look at the code, is there any reason why it cannot 
> > > work on MacOS (classic and X) or the Unix release of IE?

> > besides its dependence on Win32::OLE?

> Wonder if AppleEvents would be any use in this application...

they would be, but i haven't gotten around to writing Mac::IE yet :)

-- 
brian d foy <comdog@panix.com> - Perl services for hire
The Perl Review - a new magazine devoted to Perl 
<http://www.theperlreview.com>


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

Date: 3 Oct 2002 22:23:48 -0700
From: avishal@vsnl.net (Vishal Agarwal)
Subject: nice comments in linux src
Message-Id: <be1aeb16.0210032123.67693565@posting.google.com>

Hi,

Run the following script from /usr/src/linux to see some of the better
comments in the linux source tree ;)

Any comments/suggestions are welcome! btw, you are free to modify &
distribute as you like (if you think you've improved it, pls send me a
copy)

Cheers,
Vishal Agarwal

P.S. pls ignore if this posting appears twice in perl.misc (my news
reader isn't working properly it seems)
======================

#!/usr/bin/perl
# Author:   avishal@vsnl.net
# Date:     3 Oct 2002 (gandhi's 1 day older, maybe wiser)
# Version:  0.2 (changed the approach)
# Usage: program_name (and enter) /* assuming you're in
/usr/src/linux/ (n linux .c and .h r thr) */
# Synopsis: print all (nice) comments in .c/.h files underneath


# categories
@hard = ('damn','\b[fsdl]uck','sh[ia]t','[^sS]hello?','piss','fart','\bwtf\b','\barse\b','\bass\b','bitch','moron','stupid','\bsex');
@mild = ('\b[ht]umou?r(ous|\b)','\bhillarious','\bbeaut','heaven','cow','\bm[ou]m\b','mother\b','bible','love','gods?','myst','fish','thank','please','crazy','mad','fun(ny|\b)','(in)?sane','shame','sick','\bugly','\bdumb','silly','\bhate','die\b','lunatic','horrible','(d|\b)evil','dedicate');
@really_mild = ('window(s|\$)','micro(s|\$)oft','mess\b','\bh[ae]ck(er|\b)','\bhol(e|y|\b)','dead','prett(y|ie|\b)','weird','blind','hopeless','\bbomb\b');
@grunts = ('\b(ha){2,}','\b(he){2,}','\bwuff','\b[yh]i[^tg]','\bugh','\bo{2,}ps','\bphew+','\bgrr','\bduh','\bargh','\bwhoo','\bwou','\!\!','\?\?');

$req = 6;        # $points required to pass

&process_dir(".");
sub process_dir {        # cut/pasted+modified from Randal L.
Schwartz's site
    my $dir = shift;
    opendir DIR, $dir or return;
    my @contents = map "$dir/$_", sort grep !/^\.\.?$/, readdir DIR; #
read dir contents, except '.' & '..'
    closedir DIR;

    foreach (@contents) {
    &print_comments($_) if /\.(c|h)$/;
        &process_dir($_);       # go deeper
    }
}

sub print_comments {
    $filename = shift;
    undef @nice_comments;p
    return unless open (FH,"< $filename"); # don't die

    undef $/;
    $_ = <FH>;
    @comments =  m|(/\*.*?\*/)|gsx;

    foreach (@comments) {
    $comment_lines = (tr/\n//) + 1;
    next if $comment_lines > 4; # ignore REALLY big comments
    $points = (4-$comment_lines);    # shorter is preferred (well,
some times)
     $points += &do_count('hard',$_)*5;
      $points += &do_count('grunts',$_)*4 if ($points < $req);
                # don't have to take another test if you've already
got passing marks
        $points += &do_count('mild',$_)*3  if ($points < $req);
     $points += &do_count('smileys',$_)*3 if ($points < $req);
     $points += &do_count('really_mild',$_)*2 if ($points < $req);
       $points += &do_count('wtfs',$_) if ($points < $req);

     $points ++ if (defined(@nice_comments)); # probability increases
exponentially
    push @nice_comments, $_ if $points >= $req;
    }

    undef %saw;            # to remove duplicates
    @nice_comments = grep(!$saw{$_}++, @nice_comments);

    if (defined(@nice_comments)) {
    print "$filename\n","-"x(length($filename)),"\n";
    print "$_\n" foreach  @nice_comments;
    print "_"x75,"\n";
    }
}

# count the occurances of each $keyword (supplied with categories) in
the given $cmt
sub do_count {
    my ($kw,$cmt) = @_;
    $points = 0;
    if ($kw =~ /smileys/) {    # not more than 2 points per comment
     $points++ if /\s(\:|\;|\$|(8-)|(B-))(o|O|\-|\=)?(\)|\(|\]|\[|P|D|S|O|\@|\/|\\|X|\|)\s/;
# :o)
     $points++ if /\s(\)|\(|\]|\[|S|D|O|\/|\\|X|\|)(o|O|\-|\=)(\:|\;|\$)\s/;
   # (O:
    } elsif ($kw =~ /wtfs/i) {
    $points++ if /\s((wh?at|where|wh?en|(wh)?y|who|how|eh).*(\?|\!))/i;
    } else {
    return 0 unless (defined(@$kw));
    foreach (@$kw) {
        $points++ if $cmt =~ /$_/i;
    }
    }
    return $points;
}


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

Date: Fri, 4 Oct 2002 06:53:12 +0000 (UTC)
From: "David H. Adler" <dha@panix2.panix.com>
Subject: Re: Printing text to a file
Message-Id: <slrnapqemo.1fg.dha@panix2.panix.com>

In article <slrnapofg2.6ft.tadmc@magna.augustmail.com>, Tad McClellan wrote:
>> "Crackpot" <Crackhead@mensa.org> wrote in message
>> 
>> 
>> print q(what's up, dude?);
> 
> 
> For more info, see "Quote and Quote-like Operators" in perlop.pod.
> 
> 
>> my $text =<<'EOT';
>> what's up, dude?
>> EOT
>> 
>> print $text;
> 
> 
> For more info, see "Scalar value constructors" in perldata.pod.

Actually, as of 5.8, that's in perlop too...

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"I have no idea what that is.  Thank goodness we didn't order three!"
      - some nameless induhvidual quoted in Dilbert Newsletter 31.0


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

Date: Fri, 04 Oct 2002 00:35:13 -0400
From: David Britten <brittedg@student.gvsu.edu>
Subject: Re: Script to Change Filename
Message-Id: <B9C292C1.58B5%brittedg@student.gvsu.edu>

On 10/3/02 11:29 PM, in article
RW7n9.174125$8b1.150642@news01.bloor.is.net.cable.rogers.com, "JP"
<NO_SPAM_pangjoe@rogers.com> wrote:

> I am trying to write a shell script to rename files in a sub-directories.
> Here is what I have to do:
> 
> 1.  Select only those filenames with .dat extension
> 2.  The sournce filename must be all numeric but ends with a character
> digital, e.g. 12345a.dat, 234567b.dat
> 3.  If it meets the above two criteria, rename the file by inserting a dash
> in between the numerals and character, e.g. 12345a.dat --> 12345-a.dat,
> 234567b.dat -->234567-b.dat
> 
> I have trouble filtering the numeric part with variable length.  Any
> suggestions?
> 

I should really be in bed right now, so hopefully I don't mess this up. :-)

Assuming you're reading the filenames one at a time into a variable called
$filename, then try this regexp:

$newname = $filename
$success = $newname =~ s/((?:\d)+)([a-zA-Z]\.dat)/${1}-${2}/;

It should put the hyphen in the proper place and set $success to true if
$filename meets the criteria. (At least I think that's what s/// returns...)
Then you can just check if $success is true, and rename the file
accordingly.


-David Britten



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

Date: Fri, 04 Oct 2002 04:39:22 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: Script to Change Filename
Message-Id: <_X8n9.35540$YI.7497216@twister.nyc.rr.com>

JP <NO_SPAM_pangjoe@rogers.com> wrote:
> I am trying to write a shell script to rename files in a 
> sub-directories.  Here is what I have to do:
> 
> 1.  Select only those filenames with .dat extension
> 2.  The sournce filename must be all numeric but ends with a 
> character digital, e.g. 12345a.dat, 234567b.dat
> 3.  If it meets the above two criteria, rename the file by 
> inserting a dash in between the numerals and character, e.g. 
> 12345a.dat --> 12345-a.dat, 234567b.dat -->234567-b.dat
> 
> I have trouble filtering the numeric part with variable length.  
> Any suggestions?

Use a regex on the filenames.

  /^          # anchor front
      (\d+)   # one or more digits (captured in $1)
      ([a-z]) # one letter (captured in $2)
      \.dat   # literal '.dat'
   $/xi       # anchor back

If it matches, you rename the file to "$1-$2.dat".

  12345a.dat  =>  12345-a.dat
       ^ $2       "$1-$2.dat"
  ^^^^^  $1

And assuming that "in a sub-directories" means you want to 
descend through more than one, here's an example using File::Find.

File::Find will call call the wanted() subroutine once for
each file beneath (and including) $dir.  Before calling the sub,
it sets $_ to the filename and it has already changed to the 
file's directory, so matching and renaming become very simple:

  #!/usr/bin/perl
  use warnings;
  use File::Find;

  my $dir = shift  or die "usage: $0 DIRECTORY\n";

  sub wanted {
    return unless /^(\d+)([a-z])\.dat$/i;
    rename $_, "$1-$2.dat"
      or warn "couldn't rename: '$_' => '$1-$2.dat': $!\n";
  }

  find(\&wanted, $dir);


For more basic information on regexes, try:

  $ perldoc perlrequick
  $ perldoc perlretut

And of course you'll want to read:

  $ perldoc -f rename
  $ perldoc File::Find

-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'


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

Date: Fri, 4 Oct 2002 00:41:43 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Script to Change Filename
Message-Id: <anj9uh$4jm$1@slb5.atl.mindspring.net>

"David Britten" <brittedg@student.gvsu.edu> wrote in message
news:B9C292C1.58B5%brittedg@student.gvsu.edu...
> On 10/3/02 11:29 PM, in article
> RW7n9.174125$8b1.150642@news01.bloor.is.net.cable.rogers.com, "JP"
> <NO_SPAM_pangjoe@rogers.com> wrote:
>
> > I am trying to write a shell script to rename files in a
sub-directories.
> > Here is what I have to do:
> >
> > 1.  Select only those filenames with .dat extension
> > 2.  The sournce filename must be all numeric but ends with a character
> > digital, e.g. 12345a.dat, 234567b.dat
> > 3.  If it meets the above two criteria, rename the file by inserting a
dash
> > in between the numerals and character, e.g. 12345a.dat --> 12345-a.dat,
> > 234567b.dat -->234567-b.dat
> >
> > I have trouble filtering the numeric part with variable length.  Any
> > suggestions?
> >
>
> I should really be in bed right now, so hopefully I don't mess this up.
:-)
>
> Assuming you're reading the filenames one at a time into a variable called
> $filename, then try this regexp:
>
> $newname = $filename
> $success = $newname =~ s/((?:\d)+)([a-zA-Z]\.dat)/${1}-${2}/;
>
> It should put the hyphen in the proper place and set $success to true if
> $filename meets the criteria. (At least I think that's what s///
returns...)
> Then you can just check if $success is true, and rename the file
> accordingly.
>

Cool! Sleep well, David. Your regex worked perfectly when I dropped it into
the script in which I was trying to figure out how to do what the OP
requested. Script follows:

#!perl -w
# filedasher_v2.pl- adds dashes into filenames, e.g., 12345a.dat becomes
12345-a.dat
use strict;
my @filenames = ("12345a.dat", "12345b.dat", "0123456789c.dat", "a123b.bat",
"index1.html", "0123d.dat.html");
foreach (@filenames){
s/((?:\d)+)([a-zA-Z]\.dat)/${1}-${2}/; #regex from David Britten
print $_, "\n";
}

Cheers.

Bill Segraves





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

Date: Fri, 4 Oct 2002 13:56:41 +0400
From: "Paul Dortman" <paul@pco.iis.nsk.su>
Subject: Re: What is the best way for file/stream IO in Perl?
Message-Id: <anje4t$26l9$1@news.itfs.nsk.su>

Dear Tassilo,

Thank you very much for your detailed explanation. I think I understood
something.

FileHandle is a thin wrapper for IO::File and it's better to use IO::File
instead. Right?

IO::File is just object interface for standard filehandles, since using
IO::File is little slower than using standard filehandles but do not give us
extra oportunities. Right?

And since 5.6.0 version we could say  open my $file, "file" to open a file.
So we do not have to use filehandles, we could
use references to them. And this is probably the best solution while using
ordinary plain text files. Right?


Thanks again,

Paul Dortman


"Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de> wrote :
news:anhhqj$oj3$1@nets3.rz.RWTH-Aachen.DE...
> Also sprach Paul Dortman:
>
> > I have a questions for Perl's guru.
> >
> > What is the difference amoung IO::File, IO::Handle, FileHandle modules
and
> > standard operators and filehandles to access a file?
>
> When dealing with files, the only two things you should have to worry
> about is IO::File and using bare file handles. IO::Handle is one of the
> base classes for IO::File. It defines common methods for all
> file-handleish things. Even IO::Socket is actually derived from
> IO::Handle.
> So, IO::File just adds those things being unique to handles relating to
> actual files.
>
> As for FileHandle, I don't really see any benefits in using it. It is a
> very thin wrapper around IO::File (also inheriting from it).
>
> And there are file handles. One cool thing about IO::File and its
> derivates is that they can be used like an ordinary filehandle:
>
>     my $h = IO::File->new;
>     $h->open("<file");
>     while (<$h>) {
>         ...
>     }
>
> That's one of Perl's trickeries that relies on the fact that HANDLE and
> \*HANDLE basically behave the same in regards to some typical file
> handle operations.
>
> > What is the best way to access file and to deal with file?
> > Where can I find more information on IO in Perl?
>
> 'the best' depends on the task. Most of the time I have been able to get
> away using just ordinary plain handles. Also, since Perl 5.6.0 you no
> longer have to worry about localizing your handles since you can do:
>
>     open my $file, "file";
>
> So a handle can behave very much like a lexical variable.
>
> There are a number of spots where you find the desired information.
>
>     perlop      ("I/O Operators")
>     perlopentut (how to abuse open() to do funny things)
>
> and the manpages for IO::File, IO::Handle and IO::Seekable. The methods
> described therein usually exist for bare handles as Perl functions in
> which case you would need to look up those in 'perlfunc'.
>
> In case you are already using Perl 5.8.0, there is 'perldoc PerlIO::via'
> that describes how to write IO layers that can act as filters for your
> handles.
>
> Tassilo
> --
> $_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
> pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
> $_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;




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

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


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