[22576] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4797 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 1 00:05:41 2003

Date: Mon, 31 Mar 2003 21:05:09 -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, 31 Mar 2003     Volume: 10 Number: 4797

Today's topics:
    Re: Bot to modify a resume on monster.com <hiro@asari.net>
    Re: capitalize songs names (pattern question) <goldbb2@earthlink.net>
    Re: CGI.pm or roll-your-own? (Sam Holden)
    Re: CGI::ContactForm 1.03 - Feedback request <noreply@gunnar.cc>
    Re: CGI::ContactForm 1.03 - Feedback request <tore@aursand.no>
    Re: Does Perl can do everything you need in unix shell  (Tad McClellan)
    Re: implementing a threaded serial device (or any other <goldbb2@earthlink.net>
    Re: Loading STDOUT into a variable (Tad McClellan)
    Re: modules using modules - shared objects <nwzmattXX@XXnetscape.net>
    Re: modules using modules - shared objects <goldbb2@earthlink.net>
    Re: modules using modules - shared objects <goldbb2@earthlink.net>
    Re: MSWin32 Active State Perl Question <goldbb2@earthlink.net>
    Re: MSWin32 Active State Perl Question <mooncm.lbkejwiAhEgSfSe@dAcEbSaS>
        search a dir for a file <noneya@biz.com>
    Re: search a dir for a file <noreply@gunnar.cc>
    Re: search a dir for a file <goldbb2@earthlink.net>
    Re: search a dir for a file <jurgenex@hotmail.com>
    Re: slow file access under windows <goldbb2@earthlink.net>
    Re: sort array of structs <goldbb2@earthlink.net>
    Re: split map avoid error message <uri@stemsystems.com>
    Re: split map avoid error message (Tad McClellan)
    Re: split map avoid error message <stremitz@consultant.com>
    Re: split map avoid error message <spam@thecouch.homeip.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 31 Mar 2003 22:34:29 -0600
From: "Hiro Asari" <hiro@asari.net>
Subject: Re: Bot to modify a resume on monster.com
Message-Id: <v8i5mfmhl5kk28@corp.supernews.com>

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


"BlueTrin" <darkdan666@hotmail.com> wrote in message
news:b69l5m$c82$1@news-reader10.wanadoo.fr...
> Hi,
>
> I m new to perl, I wanted to write a script that would log
> on monster.com, fetch the URL of the first resume, then
> edit some part of it and validate it.
>
> Anyone knows what module/functions should I use or
> have written already a script to do this.
>
>
> Anthony
>
>


If you are new to Perl, by the time you figure out how to do this
with Perl, you'd have had enough time to do it by hand ten times
over.

Having said that, I'd first look at Net::SSLeay, libwww-perl,
WWW::Mechanize, etc.  You might want to take a look at "Perl & LWP"
by Sean Burke.

HTH.
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - GPGOE 0.4.1

iD8DBQE+iRbVoXhPvmJPsrERAgCHAKCdYuq6jmNqonCqLsoS4F1AEJtt/ACeIZjz
8rQUdbjGk7Qpsa4ps2dyiiU=
=rZ5b
-----END PGP SIGNATURE-----




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

Date: Mon, 31 Mar 2003 22:29:36 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: capitalize songs names (pattern question)
Message-Id: <3E8907A0.29BD2021@earthlink.net>



Elvar Ojar wrote:
> 
> So.., I have list of files names in lowercase:
[snip]
> And I want to capitalize them. But traditional use don't give always
> result I want. I understand that somewhere I must make compromize
[snip]
> So finally my question is: is there some simple, shorter, faster way
> that i did? Probably is.

The following simple short substitution should get all of them right
except for "Heaven's" and "2u":

   s/\b(\w)/\u$1/g;

To fix the "Heaven's", one could do:

   s/\b(?!=s\b)(\w)/\u$1/g;

To fix the "2u", one could do:

   s/(?<![a-z])(\w)/\u$1/ig;

A combo should both:

   s/(?<![a-z])(?!=s\b)(\w)/\u$1/ig;

[all untested]

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: 1 Apr 2003 04:27:35 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <slrnb8i59n.j0k.sholden@flexal.cs.usyd.edu.au>

On 31 Mar 2003 00:09:18 -0500, Jason Parker-Burlingham <jasonp@uq.net.au> wrote:
> sholden@flexal.cs.usyd.edu.au (Sam Holden) writes:
> 
>> Why anyone would actually use the OO interface is beyond me, since
>> it is a domain in which in the *vast* majority of cases you only
>> have one instance (I have *never* needed multiple CGI objects in one
>> script).
> 
> CGI::Application uses it to great effect.

Yes, and it is a framework and hence benefits from the OO way of doing things.
Since it allows a different query interface to be used in place of CGI.pm, 
something which I doubt is used too often, but is essential to support
from an application framework. This replacement of components is one of
things that the OO approach makes easy in perl (especially since you
only need interface compatability and not actual inheritance as you would
in say C++).

In the world of a single CGI script though, the OO interface just doesn't give
enough benefit to outweight the tediousness of the interface.

-- 
Sam Holden



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

Date: Tue, 01 Apr 2003 04:14:46 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGI::ContactForm 1.03 - Feedback request
Message-Id: <b6asqu$39svr$1@ID-184292.news.dfncis.de>

Tore Aursand wrote:
> As your module is today, you must most certainly be a Perl 
> programmer to change any of the text.

No. All the text can be changed via arguments in the calling script. 
To do it you just need to be able to read the documentation.

For instance, you can easily create a Norwegian contact form. :)

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Tue, 01 Apr 2003 06:26:50 +0200
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: CGI::ContactForm 1.03 - Feedback request
Message-Id: <pan.2003.04.01.01.38.03.708869@aursand.no>

On Tue, 01 Apr 2003 01:57:00 +0200, Gunnar Hjalmarsson wrote:
> sub htmlize {
>     [...]
> }
> 
> I found that CGI.pm includes a function for it, so I simply replaced 
> the above subroutine with the escapeHTML() function.

Great!  Now, with the templating in mind you could have used that function
for _every_ value inserted into the HTML template.  That would've resulted
in perfectly valid HTML no matter what characters the users of your module
have been trying to use.


-- 
Tore Aursand


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

Date: Mon, 31 Mar 2003 20:56:22 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Does Perl can do everything you need in unix shell scripting?what about PHP?
Message-Id: <slrnb8hvum.27c.tadmc@magna.augustmail.com>

edu@rd c <ecleofe7@yahoo.com> wrote:

> what about
> PHP,since they are just the same function with perl


PHP is not at all the "same function" as Perl.

Perl is a general purpose programming language.

PHP is a special purpose programming language.


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


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

Date: Mon, 31 Mar 2003 22:52:44 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: implementing a threaded serial device (or any other parallel way)
Message-Id: <3E890D0C.40CB3E5@earthlink.net>

Alexander Eisenhuth wrote:
> 
> Hallo together,
> 
> I'm quite new to perl, but with enough experiences in other
> programming languages.
> 
> What I need is a serial device class, where each object waits for a
> special character to receive. After receiving the "termination char"
> it calls a callback to evaluate the received message.

Are these real serial devices, or are they sockets?

If they're sockets, consider doing using select() or IO::Select.

On unix, select() or IO::Select should work even if they're real serial
devices, assuming that they're filehandles with valid filedescriptors.

PS:
        &threads::shared::share ({$comObj});
Can't possibly work.

The share() function is really just a thin wrapper for tie $arg,
"threads::shared";, or something like that.  And as you (should) know,
when you tie something, it hides the data inside it.  What you would
want to do, would be something like:

   my $comobj = bless {}, $packagename;
   &threads::shared::share $comobj;
   bless $comobj, $packagename; # extra blessing for good luck
   # now, *AFTER* sharing, fill in the data.
   %$comobj = (
      inputBuffer=>"",
      running=>1,
      watchThread=>0,
      internalCountr=>0,
      serialPort=>0,
      osDeviceName => $osDeviceName,
   );
   $comobj->{serialPort} = ...;
   my $watch_thread = threads->create( \&watch_device, $comobj, $c );
   $comobj->{watchThread} = $watch_thread->tid;
   return $comobj;
}

sub watch_device {
   my ($com, $char) = @_;
   threads->self->detatch;
   while( 1 ) {
      my $b = $com->{serialPort}->DoBlockingRead();
      lock $com;
      last if !$com->{running};
      $com->{inputBuffer} .= $b;
      threads::shared::cond_signal($com);
   }
   print "thread $com->{watchThread} finished\n";
}

[untested]

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Mon, 31 Mar 2003 21:02:28 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Loading STDOUT into a variable
Message-Id: <slrnb8i0a4.27c.tadmc@magna.augustmail.com>

Stephan Bour <sbour@niaid.nih.gov> wrote:

> system("ifconfig");

> there any way to assign the content of STDOUT to a variable


   perldoc -f system


*plonk*


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


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

Date: Tue, 01 Apr 2003 02:24:30 GMT
From: Matt <nwzmattXX@XXnetscape.net>
Subject: Re: modules using modules - shared objects
Message-Id: <uk7efeyzy.fsf@XXnetscape.net>

Matt <nwzmattXX@XXnetscape.net> writes:

> "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> writes:
> 
> > Subject: Re: modules using modules - shared objects
> > 
> > The subject is a little misleading. When I hear "shared object" I think
> > of .so files (the Linux equivalent of a dll). 
> > 
> > Also sprach Matt:
> > 
> > > I have been playing around with writing a module. I was suprised to
> > > find that I can use a module from within my module, and return an
> > > object ref from the other module with all of its methods.
> <code snipped>
> > > Ok, now obviously I am able to use all of the methods exported from
> > > DBI in my script. How/why is this. I have not been able to find
> > > documentation that has completely made me understand how this
> > > works. 
> > 
> > Not quite. You are calling methods on the object previously returned. An
> > object is something that combines data, a namespace and a couple of
> > functions (methods in this context). There is no exporting involved
> > really. When you do:
> > 
> >     $obj->method(@args);
> > 
> > perl finds out the class to which $obj belongs and does roughly this:
> > 
> >     CLASS_OF_OBJ::method($obj, @args);
> > 
> > Of course, what perl does is more complicated especially when
> > inheritance etc. is involved.
> > 
> 
> Thanks Tassilo. I'm starting to get a handle on it. I've been reading
> up on inheritance a little. What I want to do now is to (bless? tie?)
> an object of my class to a DBI object. In other words, just extend the
> methods of the DBI object to include some custom methods. I've tried
> various things, but I'm not sure what I'm doing and nothing is
> working. Can you(or anyone else) give me an example of how this might
> be possible, or point me in the direction of one.
> 

That's not quite what I meant to say. I don't want to actually add
methods to DBI. I just want to be able to access methods from my own
module, _and_ from DBI using a single object reference.

Like:

        package MYMOD
        use DBI; 
        our @ISA = qw(DBI);

        sub new { ... }
        sub mysub { ... }

and being able to:

        use MYMOD;
        my $myobj = new MYMOD;

        $myobj->connect($dsn, $dbu, $dbp); # Call the DBI connect method.

        $myobj->mysub(); # Call my own method.  


Matt
-- 
Remove the X's to reply directly.


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

Date: Mon, 31 Mar 2003 21:45:54 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: modules using modules - shared objects
Message-Id: <3E88FD62.927AAA38@earthlink.net>

Matt wrote:
> 
> I have been playing around with writing a module. I was suprised to
> find that I can use a module from within my module, and return an
> object ref from the other module with all of its methods.
[snip]
> Ok, now obviously I am able to use all of the methods exported from
> DBI in my script.

DBI is not "exporting" *any* functions.  Exporting is a different
mechanism from object methods.

There are methods which can be called on objects blessed into the DBI
class, but this has nothing to do with exporting.

Methods on a blessed object can be called on that object from any
package.

> How/why is this. I have not been able to find
> documentation that has completely made me understand how this
> works.

When you do:

   bless $someref, $someclass;

It associates the package name $someclass with the reference $someref.

Later on, you can (from *anywhere*) call functions on $someref, as:
   $someref->somemethod(@args);
Provided that $someclass, or one of the classes it inherits from,
provides a subroutine named 'somemethod'.

Really, what it's doing internally, is something like:

   $the_class = ref $someref;
   $the_subroutine = UNIVERSAL::can( $the_class, "somemethod" );
   &$the_subroutine( $someref, @args );

(It's not quite like that, due to autoloaded subroutines, but this is a
close enough description for understanding what's happening)

The UNIVERSAL::can function is something like this:
   sub can {
      my ($class, $meth) = @_;
      if( defined &{ $class . "::" . $meth } ) {
         return \&{ $class . "::" . $meth };
      }
      foreach my $parent ( @{ $class . "::INC" } ) {
         if( defined( my $m = can($parent, $meth) ) ) {
            return $m;
         }
      }
      return undef;
   }

(It's not *quite* like that, due to caching, but this is a close enough
description for understanding what's happening)

> Also, as you see, I declare both the $dbh variable in the
> module and in the script with my(). In the script, I am getting the
> object ref from the return value of a function in my module, so they
> are both pointing to the same object, right? And when I call
> selectSomething(), it is using this same object right?

Yes.  Both refer to the same object.

> I just need a little help understanding how this is all
> working. Thanks in advance.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Mon, 31 Mar 2003 22:17:47 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: modules using modules - shared objects
Message-Id: <3E8904DB.6C2AB4F@earthlink.net>

Matt wrote:
> 
> "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> writes:
[snip]
> > Not quite. You are calling methods on the object previously
> > returned. An object is something that combines data, a namespace and
> > a couple of functions (methods in this context). There is no
> > exporting involved really. When you do:
> >
> >     $obj->method(@args);
> >
> > perl finds out the class to which $obj belongs and does roughly
> > this:
> >
> >     CLASS_OF_OBJ::method($obj, @args);
> >
> > Of course, what perl does is more complicated especially when
> > inheritance etc. is involved.
> 
> Thanks Tassilo. I'm starting to get a handle on it. I've been reading
> up on inheritance a little. What I want to do now is to (bless? tie?)

bless.

tieing is something different.

> an object of my class to a DBI object. In other words, just extend the
> methods of the DBI object to include some custom methods. I've tried
> various things, but I'm not sure what I'm doing and nothing is
> working. Can you(or anyone else) give me an example of how this might
> be possible, or point me in the direction of one.

This will *not* work with DBI, but the *ordinary* semantic for
inheriting from another class would be something like this:

   package MyDBI;
   require DBI;
   @ISA = qw(DBI);
   # "ISA" means "is a".  In other words, the above line says
   # that this class inherits from the DBI class.
   sub selectSomething {
      my $dbh = shift;
      my ($a) = $dbh->selectrow_array("select something from nothing");
      return $a;
   }
   1;
   __END__
   # main program:
   use MyDBI;
   my $dbh = MyDBI->connect( .... );
   my $a = $dbh->selectSomething();
   __END__

Note that you wouldn't have to redefine the connect method... it would
be passed on to MyDBI's parent class, DBI, due to inheritance.

##################

However... DBI is special, it's not like other, normal, classes, so this
wouldn't work.  It does some really funky things.

What you would have to do instead would be:

   package MyDBI;
   use DBI ();
   sub connect {
      my $thisclass = shift;
      my $self = DBI->connect( @_ );
      my $old_class = ref $self;
      my $new_class = $old_class . "::$thisclass Mixin";
      @{ $new_class . "::ISA" } = ( $thisclass, $old_class );
      return bless $self, $new_class;
   }
   sub selectSomething {
      my $dbh = shift;
      my ($a) = $dbh->selectrow_array("select something from nothing");
      return $a;
   }
   1;
   __END__
   [and the main script as already described]

[untested]

Even this might not work.  I think it should.

The *proper* way to subclass DBI, though, is to read the special
documentation on doing so.

PS: The wierd trickery here is done so that you *can* inherit from MyDBI
in the normal manner, even though you can't inherit from DBI easily. 
Any class which inherits from MyDBI should *not* write it's own connect
method.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Mon, 31 Mar 2003 21:27:58 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: MSWin32 Active State Perl Question
Message-Id: <3E88F92E.80EC515A@earthlink.net>

BSK wrote:
> 
> Hello All,
> 
> I am trying to put together some Perl code that will timeout after
> waiting so many seconds for input from STDIN.  That is, after waiting
> so many seconds for the user to supply input by way of STDIN, if the
> user does not supply anything then the code just continues on
> executing by assuming some default values that would have otherwise
> been provided by the user.  I am trying to do this with Active State
> Perl (Version 5.008) on an MSWin32 system (WindowsNT4.0sp6a to be
> exact).

I'm afraid that alarm() doesn't work on windows.  At all.  Not just, it
doesn't work with STDIN, it just doesn't work.

I would suggest you use Term::ReadKey with a blocking read with timeout.

Aparently, you can't use the ReadLine function on windows, but I believe
that using ReadKey should suffice.

use Term::ReadKey qw(ReadKey);
sub MyReadLine {
   my $s = ReadKey( 3, \*STDIN );
   return if !defined($s);
   return "" if $s eq "\n";
   while( defined(my $c = ReadKey( 0, \*STDIN ) ) {
      return $s if $c eq "\n";
      $s .= $c;
   }
   die "Error: ReadKey returned undef on blocking read: $^E\n";
}

With this function, you must press the first key for whatever line
you're typing within three seconds, and can take as long as you want
typing the rest of the line.

PS: Since alarm() doesn't work on windows, Sisyphus's suggested code
can't possibly work, even though it uses the Term::ReadKey::ReadKey()
function.  You have to use the timeout functionality that the ReadKey()
itself provides, rather than trying to use alarm().

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Tue, 01 Apr 2003 04:12:27 GMT
From: "BSK" <mooncm.lbkejwiAhEgSfSe@dAcEbSaS>
Subject: Re: MSWin32 Active State Perl Question
Message-Id: <Lk8ia.2559$4P1.213991@newsread2.prod.itd.earthlink.net>

Thanks Rob and Benjamin-- I really appreciate all the good info.  I guess
the first I need to do is to install the Term::ReadKey pm.  Today, by way of
CPAN, I learned that a precompiled version of the module is available
through ActivePerl so that will be my next task.

Thanks again.


BSK
[For AntiSpam: Email address is spelled
backwards.  Remove every other letter
starting with 'a' in 'SaS'.]



"Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
news:3E88F92E.80EC515A@earthlink.net...
> BSK wrote:
> >
> > Hello All,
> >
> > I am trying to put together some Perl code that will timeout after
> > waiting so many seconds for input from STDIN.  That is, after waiting
> > so many seconds for the user to supply input by way of STDIN, if the
> > user does not supply anything then the code just continues on
> > executing by assuming some default values that would have otherwise
> > been provided by the user.  I am trying to do this with Active State
> > Perl (Version 5.008) on an MSWin32 system (WindowsNT4.0sp6a to be
> > exact).
>
> I'm afraid that alarm() doesn't work on windows.  At all.  Not just, it
> doesn't work with STDIN, it just doesn't work.
>
> I would suggest you use Term::ReadKey with a blocking read with timeout.
>
> Aparently, you can't use the ReadLine function on windows, but I believe
> that using ReadKey should suffice.
>
> use Term::ReadKey qw(ReadKey);
> sub MyReadLine {
>    my $s = ReadKey( 3, \*STDIN );
>    return if !defined($s);
>    return "" if $s eq "\n";
>    while( defined(my $c = ReadKey( 0, \*STDIN ) ) {
>       return $s if $c eq "\n";
>       $s .= $c;
>    }
>    die "Error: ReadKey returned undef on blocking read: $^E\n";
> }
>
> With this function, you must press the first key for whatever line
> you're typing within three seconds, and can take as long as you want
> typing the rest of the line.
>
> PS: Since alarm() doesn't work on windows, Sisyphus's suggested code
> can't possibly work, even though it uses the Term::ReadKey::ReadKey()
> function.  You have to use the timeout functionality that the ReadKey()
> itself provides, rather than trying to use alarm().
>
> --
> $a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
> );{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
> ]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
>




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

Date: Mon, 31 Mar 2003 21:28:34 -0500
From: "h8dnwld" <noneya@biz.com>
Subject: search a dir for a file
Message-Id: <pan.2003.04.01.02.28.34.53655@biz.com>

I am trying to search a dir for any file that ends in ".txt".  would fgrep
be the way to go?  Can I use the same ($, ^ or . ) as I would in unix
fgrep?

	THANKS


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

Date: Tue, 01 Apr 2003 04:33:46 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: search a dir for a file
Message-Id: <b6atui$3gb1k$1@ID-184292.news.dfncis.de>

h8dnwld wrote:
> I am trying to search a dir for any file that ends in ".txt".

Have you studied the docs?

     http://www.perldoc.com/perl5.8.0/pod/func/readdir.html

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Mon, 31 Mar 2003 22:55:52 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: search a dir for a file
Message-Id: <3E890DC8.31D927A6@earthlink.net>

h8dnwld wrote:
> 
> I am trying to search a dir for any file that ends in ".txt".  would
> fgrep be the way to go?  Can I use the same ($, ^ or . ) as I would in
> unix fgrep?

   perldoc -f glob
   my @names = glob("/path/to/directory/*.txt");


-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Tue, 01 Apr 2003 03:46:30 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: search a dir for a file
Message-Id: <qY7ia.18815$gp1.6149@nwrddc02.gnilink.net>

h8dnwld wrote:
> I am trying to search a dir for any file that ends in ".txt".  would
> fgrep be the way to go?  Can I use the same ($, ^ or . ) as I would
> in unix fgrep?

fgrep? "perldoc -f fgrep" yields
    No documentation for perl function `fgrep' found

If you want the names of all files in a given directory ending in '.txt'
then use simple file globbing (perldoc -f glob).
If you want the names of all files in a given directory matching a given RE
then use readdir and a grep() on the result of the readdir.
If you want to search for files recursively then use
    File::Find

jue




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

Date: Mon, 31 Mar 2003 21:32:43 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: slow file access under windows
Message-Id: <3E88FA4B.7C1784F6@earthlink.net>

Michael Bickel wrote:
> 
> Hi,
> I recognice, that a simple file access is much slower under Windows
> (W2K, Perl 5.6.1) than under Unix (AIX). I just check 5 directories if
> they exist or not  (with switch and opendir) and it took more than 10
> sec.
> Also using File::Find (see below) take much longer under Win than
> under AIX (Win: 25 sec., AIX <2 sec).
> Has anyone suggestions to increase the speed?

Windows and Unix use different filesystems.  The filesystem which
Windows uses is slower than the filesystem which Unix uses.  This is not
perl's fault, and there is no perl solution.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Mon, 31 Mar 2003 22:20:33 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: sort array of structs
Message-Id: <3E890581.EDBFEB82@earthlink.net>

Tore Aursand wrote:
> 
> On Sun, 30 Mar 2003 11:38:21 +0100, vervoom wrote:
> > I have an array @maillist of Mail structs :
> 
> You mean an array of hashes?  Try 'perldoc -q sort'.

No, he means an array of objects blessed into the "Mail" class.  To
assume that these are implemented as hashrefs, would violate the
encapsulation that the class provides.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Tue, 01 Apr 2003 02:22:56 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: split map avoid error message
Message-Id: <x7vfxzq7lv.fsf@mail.sysarch.com>

>>>>> "AS" == Alexander Stremitzer <stremitz@consultant.com> writes:

  AS> Uri Guttman wrote:

  >> simple, make sure $_ has at least a null string in there. and i would do
  >> this in two lines. modifying $_ inside map is not the clearest code. map
  >> is best used to generate new lists and foreach is best used to modify
  >> existing lists.
  >> 
  >> my @ris_list = map { $_ || '' } quotewords ('\t', 0, $_);
  >> 
  AS> Thank you for your quick replay. It works great, except when one of
  AS> the fields contains the value '0'. It is then replaced by a blank
  AS> field. Any suggestions ?

so check for defined instead:

my @ris_list = map { defined $_ ? $_ : '' } quotewords ('\t', 0, $_);

you should learn about handling undefined and boolean values. there are
many common idioms like this to help out.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Mon, 31 Mar 2003 21:05:17 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: split map avoid error message
Message-Id: <slrnb8i0fd.27c.tadmc@magna.augustmail.com>

Alexander Stremitzer <stremitz@consultant.com> wrote:

> I experience an error message.

> Use of uninitialized value in substitution (s///) at zzz line 9, <DATA> 
> line 2.


There were no error messages in your post, only warning messages.


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


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

Date: Mon, 31 Mar 2003 23:06:27 -0500
From: Alexander Stremitzer <stremitz@consultant.com>
Subject: Re: split map avoid error message
Message-Id: <3E891043.9050104@consultant.com>


--------------040803060801080202090706
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Thanks for your comment. This was really helpful.

Tad McClellan wrote:

>Alexander Stremitzer <stremitz@consultant.com> wrote:
>
>  
>
>>I experience an error message.
>>    
>>
>
>  
>
>>Use of uninitialized value in substitution (s///) at zzz line 9, <DATA> 
>>line 2.
>>    
>>
>
>
>There were no error messages in your post, only warning messages.
>
>
>  
>

-- 
All man's miseries derive from not being able to sit quietly in a room alone. (Pascal)



--------------040803060801080202090706
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
  <title></title>
</head>
<body>
Thanks for your comment. This was really helpful.<br>
<br>
Tad McClellan wrote:<br>
<blockquote type="cite"
 cite="midslrnb8i0fd.27c.tadmc@magna.augustmail.com">
  <pre wrap="">Alexander Stremitzer <a class="moz-txt-link-rfc2396E" href="mailto:stremitz@consultant.com">&lt;stremitz@consultant.com&gt;</a> wrote:

  </pre>
  <blockquote type="cite">
    <pre wrap="">I experience an error message.
    </pre>
  </blockquote>
  <pre wrap=""><!---->
  </pre>
  <blockquote type="cite">
    <pre wrap="">Use of uninitialized value in substitution (s///) at zzz line 9, &lt;DATA&gt; 
line 2.
    </pre>
  </blockquote>
  <pre wrap=""><!---->

There were no error messages in your post, only warning messages.


  </pre>
</blockquote>
<br>
<pre class="moz-signature" cols="$mailwrapcol">-- 
All man's miseries derive from not being able to sit quietly in a room alone. (Pascal)</pre>
<br>
</body>
</html>

--------------040803060801080202090706--




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

Date: Mon, 31 Mar 2003 23:45:43 -0500
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: split map avoid error message
Message-Id: <%P8ia.92760$Y47.592514@weber.videotron.net>

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

Alexander Stremitzer wrote:
> 
> Uri Guttman wrote:
> 
>>>>>>>"AS" == Alexander Stremitzer <stremitz@consultant.com> writes:
>>>>>>>            
>>>>>>>
>>
>>  AS> My program splits a tab separated record in individual fields and
>>  AS> removes any trailing spaces from each field. Whenever a record is too
>>  AS> short, I experience an error message. I would prefer not to get an
>>  AS> error message and have an empty field rather than an undefined
>>  AS> field. The last data line contains a TAB but no middle name.
>>
>>  AS>         my @ris_list = map { s/\s+$//; $_ } quotewords ('\t', 0, $_);
>>
>>simple, make sure $_ has at least a null string in there. and i would do
>>this in two lines. modifying $_ inside map is not the clearest code. map
>>is best used to generate new lists and foreach is best used to modify
>>existing lists.
>>
>>         my @ris_list = map { $_ || '' } quotewords ('\t', 0, $_);
>>
> Thank you for your quick replay. It works great, except when one of the 
> fields contains the value '0'. It is then replaced by a blank field. Any 
> suggestions ?

(Untested)

my @ris_list = map { defined ? $_ : '' } quotewords ('\t', 0, $_);


-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE+iRl8eS99pGMif6wRAqiDAKCbt9S1v5AaoNllQSxyBXiAjN4fUACfRO9W
foCjl3O0Caq/w3pBdkl0E8s=
=4gKB
-----END PGP SIGNATURE-----



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

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


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