[21707] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3911 Volume: 10

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

Date: Thu, 3 Oct 2002 21:05:08 -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           Thu, 3 Oct 2002     Volume: 10 Number: 3911

Today's topics:
        Best Method to Check Remote Directory <cbenedict@comcast.net>
    Re: Best Method to Check Remote Directory <goldbb2@earthlink.net>
    Re: Calling a shell from perl without losing control <goldbb2@earthlink.net>
    Re: Convert Perl script to C program (and Why was this  <Cptn.Fredo@S.S.No.Spam>
    Re: Convert Perl script to C program (and Why was this  <Cptn.Fredo@S.S.No.Spam>
        Dynamically defining subroutines in another package (Gupit)
    Re: Dynamically defining subroutines in another package <pinyaj@rpi.edu>
    Re: Dynamically defining subroutines in another package <mgjv@tradingpost.com.au>
    Re: Dynamically defining subroutines in another package <mgjv@tradingpost.com.au>
    Re: How can I count files in a directory? <spam@all.costs.must.die>
    Re: Keeping scripts running--socket server question <goldbb2@earthlink.net>
    Re: Messages getting truncated. <goldbb2@earthlink.net>
    Re: New Perl Module for QA Engineers <pkent77tea@yahoo.com.tea>
    Re: Open File problem (kazchan)
    Re: Parse a word into three strings <jkeen@concentric.net>
        Proper readdir??? michael.e.grimes@fritolay.com
        Script to Change Filename <NO_SPAM_pangjoe@rogers.com>
    Re: Script to Change Filename (Walter Roberson)
        Security-Hole in module Safe.pm <andreas.jurenda@chello.at>
    Re: Splice function with arrays <jkeen@concentric.net>
    Re: Unable to trap error from child <tom.beer@btfinancialgroup.spamfilter.com>
    Re: What is the best way for file/stream IO in Perl? <REMOVEsdnCAPS@comcast.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 03 Oct 2002 22:56:18 GMT
From: "Chris" <cbenedict@comcast.net>
Subject: Best Method to Check Remote Directory
Message-Id: <mW3n9.47653$bY5.255216@bin4.nnrp.aus1.giganews.com>

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.

I'm thinking of using LWP's "getstore" to check the remote directory, but
that would require storing the files and more processing which I don't want
to do.

I also thought of parsing the FTP dialog, but that doesn't seem like a good
option either. Another option is using the $ftp->(size) for each file and
directory; but that seems like that would be CPU intensive also.

I need some way that uses the least amount of processor power as possible.
My CPU percentage is already getting high on this script.

Suggestions?

--Chris (JAPF - just another perl flunkie)







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

Date: Thu, 03 Oct 2002 19:53:55 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Best Method to Check Remote Directory
Message-Id: <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?


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

Date: Thu, 03 Oct 2002 18:32:53 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Calling a shell from perl without losing control
Message-Id: <3D9CC595.C87A40B@earthlink.net>

Zeus wrote:
> 
> > The closest that you could do would be something like:
> >   open  FH, "| csh" or die horribly;
> >   print FH "myprog1.csh\n";
> >   print FH "myprog2.csh\n";
> >   close FH or die horribly;
> >
> 
> This does not run myprog1.csh and myprog2.csh from within the opened
> csh, which is my requirement.

This starts csh, then acts as if the user had (within csh) typed
"myprog1.csh", then pressed enter, then typed "myprog2.csh", then
pressed enter again, then pressed a key combo which would generate an
end-of-file (control-d on most unices, or control-z on windows).

If that's not how you would start a script from within csh (I don't know
-- I don't use csh.  Nor do I particularly care), then alter the strings
that are printed to FH.

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


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

Date: Fri, 04 Oct 2002 00:06:51 GMT
From: ".Fredo" <Cptn.Fredo@S.S.No.Spam>
Subject: Re: Convert Perl script to C program (and Why was this group's name changed?)
Message-Id: <vY4n9.623$oA3.50269326@newssvr14.news.prodigy.com>


"Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net> wrote in
message news:slrnapnrfv.142.bernard.el-hagin@gdndev25.lido-tech...
> In article <g9Im9.276$3r2.2422851@newssvr21.news.prodigy.com>, .Fredo
> wrote:
> >
> > "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net> wrote
in
>
> [...]
>
> >> Do you not understand the concept of a killfile? Neither Tad nor
Alan
> >> can see your replies, so why bother?
> >
> > So they would have you think. It doesn't take a complete genius to
> > figure out how to get around those. They need to be taught you just
> > cannot "plonk" a person and hope that wins the argument. A killfile
in
> > it's self is not a bad thing, but the way it's commonly (mis)used to
> > cheaply get the last word (especially if the plonker is wrong).
>
>
> Your opinion on the use or misuse of killfiles has no bearing on the
> fact that they didn't see your two replies to them.

You cannot prove they did not see them.

> > Over recent years, it has become a straight fact the Tad.

Opps that should of been:
   Over recent years, it has become a straight fact the Tad has a nack
for being quite rude.

> > To deny what has been going on here for the past years is to deny
history.
>
>
> That is a statement which is *always* true no matter what you're
> talking about. Think about it.

Yes, but try thinking about it in *context*.

> > No one, not even a revered book author, nor an expert programmer,
has no
> > right to display such rudeness when ever they see fit. This is what
has
> > been going on. I have been corresponding via email with various folk
> > from this group for well over a year now, and this feeling not only
felt
> > by myself.
>
>
> But what's forcing you to keep reading the group, then? Are you a
> masochist?

Who was forcing Tad and the likes to respond rudely so many times again
and again. I've been ehre and seen so much of it. There really was no
excuse for it. Simple as that.




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

Date: Fri, 04 Oct 2002 00:17:23 GMT
From: ".Fredo" <Cptn.Fredo@S.S.No.Spam>
Subject: Re: Convert Perl script to C program (and Why was this group's name changed?)
Message-Id: <n65n9.625$wQ3.51277854@newssvr14.news.prodigy.com>


"Helgi Briem" <helgi@decode.is> wrote in message
news:3d9c116f.2078347575@news.cis.dfn.de...
> On Thu, 3 Oct 2002 07:14:33 +0000 (UTC), Bernard El-Hagin
> <bernard.el-hagin@DODGE_THISlido-tech.net> wrote:
>
> >> No one, not even a revered book author, nor an expert programmer,
has no
> >> right to display such rudeness when ever they see fit. This is what
has
> >> been going on. I have been corresponding via email with various
folk
> >> from this group for well over a year now, and this feeling not only
felt
> >> by myself.
> >
> >But what's forcing you to keep reading the group, then? Are you a
> >masochist?
>
> Ah, but you see, the lurkers support him in e-mail.
>
> I think this is our "friend" Manny Wilco again, aka
> Harl, Kamitri, Robin Givens, Al MacHonahey etc etc.

It matters not who I am. any person has a right to post under what ever
identity they chose. It's called staying anonymous which is a key thing
about the internet itself.

But the issue here is not about who I am it's about what this group has
come to with such sheer and utter rudeness from such so called
high-stature people like Tad and TomC, who have over the past recent
years, have stooped to posting incredibly rude replies to anyone they
deemed deserving of it.

In fact that sherade you speak of was precisely sparked by such rude
responces. Had it not been for that I most likely not be as fed up as I
currently am at the general attitude displayed in this group over the
years.

I'll even say it again. There is absolutely no excuse or jsutification
for such rude post like those that have been flying around here the past
years. The truth hurts, exspially when it's being right in the faces of
those it pertains to. Obvious symptom is Tad's classic instant
"plonk"ing when confronted with it. He apparently is under the
impression that his precious killfile can mask the truth for him.




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

Date: 3 Oct 2002 19:41:23 -0700
From: gupit@yahoo.com (Gupit)
Subject: Dynamically defining subroutines in another package
Message-Id: <1ea0ec40.0210031841.460b21c5@posting.google.com>

Hi,
Can I declare a subroutine in another package at run time?
Something like:

package Base;
sub new {
   my ($o) = @_;
   my $class = ref($o) || $o;
   
   my $self = bless {}, $class;

   $self->{evalHandler} = eval {
       package $class;
       return sub {
           my ($o, $cmd) = @_;
           {
              no strict;
              eval $cmd;
              die $@ if $@;
           }
       };
   };
   return $self;
}

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

package Derived;
use vars qw($foo);
$foo = 123;


package main;

my $obj = new Derived();
&$obj->{evalHandler}($obj, 'print $foo');
------------------------


Basically I want to be able to register a evaluation callback in the
Base class. This evaluation callback should evaluate commands passed
to it in the context of the Derived class (I want to access $foo).

With the above code, I get a syntax error near package $class;
If I hardcode the package name (i.e. package Derived) in the eval, it
works great. But I want the derived class's name to be picked up
dynamically.

BTW, I know I can always have the user implement a subroutine in
package Derived which can then evaluate commands in Derived's context.
But I want to provide this to the user automatically.

Any ideas?
Thanks,
G


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

Date: Thu, 3 Oct 2002 23:04:26 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Gupit <gupit@yahoo.com>
Subject: Re: Dynamically defining subroutines in another package
Message-Id: <Pine.A41.3.96.1021003230259.60880A-100000@vcmr-104.server.rpi.edu>

[posted & mailed]

On 3 Oct 2002, Gupit wrote:

>package Base;
>sub new {
>   my ($o) = @_;
>   my $class = ref($o) || $o;
>   
>   my $self = bless {}, $class;
>
>   $self->{evalHandler} = eval {

You want eval qq{ ... } and then escape various characters:

>       package $class;
>       return sub {
>           my ($o, $cmd) = @_;
>           {
>              no strict;
>              eval $cmd;
>              die $@ if $@;
>           }
>       };
>   };

  eval qq{
    package $class;
    return sub {
      my (\$o, \$cmd) = \@_;
      no strict;
      eval \$cmd;
      die \$\@ if \$\@;
    }
  };

>   return $self;
>}

-- 
Jeff "japhy" Pinyan      RPI Acacia Brother #734      2002 Acacia Senior Dean
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: Fri, 04 Oct 2002 03:46:30 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Dynamically defining subroutines in another package
Message-Id: <slrnapq3r3.1qr.mgjv@verbruggen.comdyn.com.au>

On 3 Oct 2002 19:41:23 -0700,
	Gupit <gupit@yahoo.com> wrote:
> Hi,
> Can I declare a subroutine in another package at run time?

Yes.

> Something like:
> 
> package Base;
> sub new {
>    my ($o) = @_;
>    my $class = ref($o) || $o;
>    
>    my $self = bless {}, $class;
> 
>    $self->{evalHandler} = eval {
>        package $class;
>        return sub {
>            my ($o, $cmd) = @_;
>            {
>               no strict;
>               eval $cmd;
>               die $@ if $@;
>            }
>        };
>    };

I don't think you want to create an anonymous subroutine or use block
eval.

Try something like (and see further changes below):

eval 'package ' . $class . '; 
  sub callback {
    my ($o, $cmd) = @_;
    eval $cmd;
    die $@ if $@;
  }';

Although I am not sure that this is the correct solution to what your
problem really is, it will allow you to do what you think you need to
do (see later for suggestions).

>    return $self;
> }
> 
> ------------------------
> 
> package Derived;

Derived should inherit from Base, otherwise nothing will work:

@Derived::ISA = qw/ Base /;

(or use base if they're in different module files).

> use vars qw($foo);
> $foo = 123;
> 
> 
> package main;
> 
> my $obj = new Derived();
> &$obj->{evalHandler}($obj, 'print $foo');

Don't use ampersands unless you know why you want one.

$obj is already the first argument, no need to repeat it.

$obj->callback('print "$foo\n"');

An alternative, since the Derived package inherits from class, is to
do something like (untested):

package Base;

sub execute
{
    my ($o, $cmd) = @_;
    my $package = ref($o);
    eval "package $package; $cmd";
    die $@ if $@;
}

sub new 
{
    my $o = shift;
    my $class = ref($o) || $o;
    my $self = bless {}, $class;
}

package Derived;
@Derived::ISA = qw/ Base /;
use vars '$foo';
$foo = 123;

package main;

my $obj = new Derived();
$obj->execute('print "$foo\n"');

which only switches to the package when needed.


I still thinks this sucks quite considerably, though. String evals are
not a great way to do things in general. Why do you think you need to
do this anyway?

Martien
-- 
                        | 
Martien Verbruggen      | I took an IQ test and the results were
Trading Post Australia  | negative.
                        | 


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

Date: Fri, 04 Oct 2002 03:54:51 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Dynamically defining subroutines in another package
Message-Id: <slrnapq4ao.1qr.mgjv@verbruggen.comdyn.com.au>

On Fri, 04 Oct 2002 03:46:30 GMT,
	Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> On 3 Oct 2002 19:41:23 -0700,
> 	Gupit <gupit@yahoo.com> wrote:
>> Hi,
>> Can I declare a subroutine in another package at run time?

[snip]

> Try something like (and see further changes below):
> 
> eval 'package ' . $class . '; 
>   sub callback {
>     my ($o, $cmd) = @_;
>     eval $cmd;
>     die $@ if $@;
>   }';

Oops, this will generate warnings about subroutine redefinitions for
more than one object. You could guard against that, or do the other
thing I suggested. I really don't think having a subroutine per object
in this case is right, since there is no object-dependent action that
is performed. Even a subroutine per class isn't necessary in this
specific case (see previous post).

Martien
-- 
                        | 
Martien Verbruggen      | The four horsemen of the apocalypse are
Trading Post Australia  | called Abort, Retry, Ignore and Fail.
                        | 


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

Date: Fri, 4 Oct 2002 08:33:57 +1000
From: "Tintin" <spam@all.costs.must.die>
Subject: Re: How can I count files in a directory?
Message-Id: <3d9cc6a8_1@news.iprimus.com.au>


"Newbie" <mike_constant@yahoo.com> wrote in message
news:anfggl$e1ach$1@ID-161864.news.dfncis.de...
>
> "Helgi Briem" <helgi@decode.is>
> >
> > Don't top-post.  It annoys the regular and
> > severely reduces your chances of people
> > taking you seriously.
> >
> Top post? You just did.

Perhaps you have a problem knowing the difference between "top" and
"bottom".  I'd suggest you look them up.




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

Date: Thu, 03 Oct 2002 21:32:00 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Keeping scripts running--socket server question
Message-Id: <3D9CEF90.81EAB823@earthlink.net>

Robert Fentress wrote:
> 
> I've developed a socket server in perl for a flash-based chat
> application.  I'm running it on a commercial web host, and though I
> have my code in a loop that keeps the script open until I tell it to
> close, I think there must be a timeout for perl scripts set on the
> server, because the script shuts down automatically every few minutes.

If there is such a timeout, it doesn't come from perl itself, but is
something that the administrator for your machine has set up.

>  Does anybody know a way I can override this in my script, or do I
> need to contact my server administrator?

Odds are, it's being done by something outside of your script... perhaps
you could catch the signal used to kill the script, but doing so would
likely make the sysadmins a bit annoyed with you.

First, post a minimal piece of perl code here which demonstrates your
problem, so we can be absolutely sure that it's not due to your code,
but due to something with the setup of your machine.

Then, if it is due to the setup of your machine, go contact the server
administrator.

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


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

Date: Thu, 03 Oct 2002 19:39:13 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Messages getting truncated.
Message-Id: <3D9CD521.DF5599B6@earthlink.net>

No Spam Please wrote:
> 
> I don't know if I'm having a sendmail problem here or a
> Perl problem, so I'll post it to both groups.
> 
> We have an email support system which is implemented in
> Perl and invoked by having an alias in the aliases file...
> 
>     support: "|/some/path/supportscript.pl"
> 
> The script first sucks the whole message into a string like this...
> 
>     $/ = 0777;    # Don't break at newlines

You're thinking of the "-0" commandline flag, often used as "-0777" ...
this sets $/ to undef.  (One might think that it would do '$/ =
chr(0777)', or '$/ = chr(oct("777"))' which ought to have about the same
effect, but either of these would require utf8 stuff internally, and
it's much *simpler* to just set it to undef).

*Your* code sets $/ to the number 511, which then gets treated as the
string "511".  As a result, perl's <> operator reads up to (and
including) the sequence "511".  Notice the last 3 letters of the
Message-Id which got truncated?

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


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

Date: Fri, 04 Oct 2002 01:15:31 GMT
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: New Perl Module for QA Engineers
Message-Id: <pkent77tea-CC73FD.02153104102002@news-text.blueyonder.co.uk>

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?

Oh yeah, that'd be it.

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

P

-- 
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply


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

Date: 3 Oct 2002 15:48:51 -0700
From: kazchan@curio-city.com (kazchan)
Subject: Re: Open File problem
Message-Id: <3baaab4f.0210031448.2bf8310b@posting.google.com>

Thank you for your great help, but unfortunately, it did not work. 
Even if I put the correct id, it does not recognize.


if (defined $id) {
    my ($line, $member, $mailto);
    open(FILEHANDLE,"<address.dat") or error("Could not open
address.dat");
    while(chomp($line = <FILEHANDLE>)) {
         ($member,$mailto) = split(/::/, $line);
         last if (lc $id eq lc $member);
    }
    close FILEHANDLE;
    print "found $id\n" if (lc $id eq lc $member);
}
else {
    print "id is not defined\n";
}


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

Date: 04 Oct 2002 03:09:57 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: Parse a word into three strings
Message-Id: <anj0q5$bdo@dispatch.concentric.net>


"Dominik Seelow" <kurzhalsflasche@netscape.net> wrote in message
news:3D9CA505.7030107@netscape.net...
> Ray Frye announced:
> > This seems like it should be a novice question.  In fact, it is.  I
> > need to take the first character of a string, read it into its own
> > string, and delete it from the original string.  Then I need to take
> > the next four characters from the original string minus the first
> > character and read them into another string, and delete them from the
> > original string.
> >
> > Say the original string = "E1230UNIFORM"
> > What I want to end up with is:
> > $firstChar = "E"
> > $nextFourChars = "1230"
> > $theRestOfThe String = "UNIFORM"
> >
> > I have been fiddling with regular expressions off and on all day and I
> > get nowhere.  Can anyone help?
> >
> > Ray
>
> why don't you use substr?
>
Dominick:  I appreciate that suggestion.  It just now made me rethink some
code I'm writing.  I was splitting a string on nothing, then manipulating
the elements of the resulting array.  substr is so much easier.

my $keyword = '';  # trying to get a unique ID for a data record
my $rand = rand;
my @addls = split //, $rand;
shift @addls;
shift @addls;
$keyword .= shift @addls;

    versus

$keyword .= substr rand,2,1;

Jim Keenan




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

Date: 3 Oct 2002 22:39:31 GMT
From: michael.e.grimes@fritolay.com
Subject: Proper readdir???
Message-Id: <anigv3$91t$1@news.netmar.com>

Howdy, 

I am using code similar to the following to move files around an NT 4.0
system:

 use File::Copy;
 opendir(DIR_IN, $Dir_In) || die "Failed to open $Dir_In: $!\n";
	 	   foreach $New_File (readdir (DIR_IN)) 	{ 
		      next if $New_File eq '.' || $New_File eq '..' || -d
"$Origin_Path\\$New_File";
      		      copy("$Full_Origin_Path","$Full_Dot_Share_Path") || NT_Proc(50,
"Failed on copy", $!);
		      move("$Full_Origin_Path","$Full_Local_Path") || NT_Proc(60, "Failed on
move", $!);

The un-ending loop runs once every 3 minutes through directorys looking for
new files to process.  
The directories are homes for FTP users. Sometimes, I run into a situation as
shown in the log snippet. 
The attempt to copy/move macksale0204.enc fails because the copy module does
not see it. During 
the succeeding loop, 3 minutes later, the same file processes normally.

Rename to O:\mack1carc1a\macksale0203.enc.100302@162024                       
      - OK!
Move to d:\node\mack1carc1a\macksale0203.enc.100302@162024                    
      - OK!
Can NOT copy to O:\mack1carc1a\macksale0204.enc.100302@162024              -
***PROBLEM***
copy Return code(50) - No such file or directory
File moved to d:\requeue\mack1carc1a\macksale0204.enc.100302@162024        -
***PROBLEM***
move Return code(50) - Permission denied
mack1carc1a                                                  ---------------
100302@162325
Copy to O:\mack1carc1a\.macksale0204.enc.100302@162325                        
      - OK!
Rename to O:\mack1carc1a\macksale0204.enc.100302@162325                       
      - OK!

At some level, perl sees the macksale0204.enc file when it does its readdir,
but since the file 
is in the process of being deposited (via FTP), the copy and move fail. 

Does anyone know of a work-around?

Thanks,
Mike


 -----  Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web  -----
  http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
   NewsOne.Net prohibits users from posting spam.  If this or other posts
made through NewsOne.Net violate posting guidelines, email abuse@newsone.net


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

Date: Fri, 04 Oct 2002 03:29:53 GMT
From: "JP" <NO_SPAM_pangjoe@rogers.com>
Subject: Script to Change Filename
Message-Id: <RW7n9.174125$8b1.150642@news01.bloor.is.net.cable.rogers.com>

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?






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

Date: 4 Oct 2002 03:55:13 GMT
From: roberson@ibd.nrc.ca (Walter Roberson)
Subject: Re: Script to Change Filename
Message-Id: <anj3f1$88p$1@canopus.cc.umanitoba.ca>

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'm not sure what you mean by a 'character digital', unless you perhaps
mean the standard hex characters a-f ?

Provided that you are already in the right directory...

($newfilename = $oldfilename) =~ s/(^\d+)([a-f])\.bat/$1-$2.bat/;
rename $oldfilename, $newfilename if $newfilename ne $oldfilename;
--
   And the wind keeps blowing the angel / Backwards into the future / 
   And this wind, this wind / Is called / Progress.
   -- Laurie Anderson


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

Date: Thu, 03 Oct 2002 23:48:55 GMT
From: "Andreas Jurenda" <andreas.jurenda@chello.at>
Subject: Security-Hole in module Safe.pm
Message-Id: <HH4n9.134682$142.1788540@news.chello.at>

Well, I have found a security problem in module Safe.pm

Sorry at may english, but my tongues are Pascal, Basic, C, C++,... maybe
Perl but neither german nor english, but I will do my best ;-)

The problem belongs to these two versions of Safe.pm:
Safe.pm Version 2.06 at Perl 5.6.1 and
Safe.pm Version 2.07 at Perl 5.8.0

In both versions there is the same code for Safe::reval()

Safe::reval() execute a given code in a safe compartment.

But this routine has a one-time safeness.
If you call reval() a second (or more) time with the same compartment, you
are potential unsafe.

These depends on the values of @_ at the entrypoint of the safe compartment.

Have a look at the source code of Safe::reval()

Source:
=======

sub reval {
    my ($obj, $expr, $strict) = @_;
    my $root = $obj->{Root};

    # Create anon sub ref in root of compartment.
    # Uses a closure (on $expr) to pass in the code to be executed.
    # (eval on one line to keep line numbers as expected by caller)
        my $evalcode = sprintf('package %s; sub { eval $expr; }', $root);
    my $evalsub;

        if ($strict) { use strict; $evalsub = eval $evalcode; }
        else         {  no strict; $evalsub = eval $evalcode; }

    return Opcode::_safe_call_sv($root, $obj->{Mask}, $evalsub);
}


In the last line there is the call for the execution of our $expr.
Inside $expr at runtime there are @_ set with ($root, $obj->{Mask},
$evalsub).

And thats the hole, because $_[1] is directly linked to $obj->{Mask}.

Modifying of $_[1] manipulate directly the operationmask of the safe
compartment!

At the first time calling reval() and manipulation $_[1] has no effect.
But after that the second (and more) call you get the (un-)"safe"
compartment with the manipulatet operation mask!

Example:
========

$codefullopmask = '$_[1] = chr(0x00) x 44;';   # at Perl 5.6.1 and 5.8.0
there are 352 built in opcodes (352/8=44)

$codewithtrape = <<'EOC';
opendir(DIR,"."); @d=readdir(DIR); closedir(DIR);
foreach my $dt (@d) { print "$dt\n"; }
EOC

use Safe;
$safe=new Safe;
$safe->deny(qw(opendir));       # deny opendir: You can't use opendir()
inside the safe compartment

$safe->reval($codefullopmask);  # this manipulate the operation mask to full
capability of all opcodes
$safe->reval($codewithtrap);    # now there is NO trap for opendir, and you
get the directory!


The solution of this problem is very simple.

You have only put the operation-mask into a temporary variable for execution
of $expr.
Here the source code of the solution. You have only modify the two commented
lines.

Solution:
=========

sub reval {
    my ($obj, $expr, $strict) = @_;
    my $root = $obj->{Root};

    # Create anon sub ref in root of compartment.
    # Uses a closure (on $expr) to pass in the code to be executed.
    # (eval on one line to keep line numbers as expected by caller)
        my $evalcode = sprintf('package %s; sub { eval $expr; }', $root);
    my $evalsub;

        if ($strict) { use strict; $evalsub = eval $evalcode; }
        else         {  no strict; $evalsub = eval $evalcode; }

    my $temp_mask = $obj->{Mask};                                  #
JURENDA: put opmask in temporary scalar
    return Opcode::_safe_call_sv($root, $temp_mask, $evalsub);     #
JURENDA: call with this temp var
}


Now you can't modify the operationmask within the safe compartment.

Herzliche Grüße von Andreas Jurenda :-})




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

Date: 03 Oct 2002 22:18:00 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: Splice function with arrays
Message-Id: <anifmo$r98@dispatch.concentric.net>


"John W. Krahn" <krahnj@acm.org> wrote in message
news:3D9BF0AD.5D1C1D3C@acm.org...
> As well as Jeff's fine explanation and example there are two other ways
> to do it
>
> # use redo
> for ( my $i = 0; $i <= $#array; $i++ ) {
>     if ( $array[$i] == 5 ) {
>         splice @array, $i, 1;
>         redo;
>     }
> }
>

I've rarely had to use Perl's 'redo' loop control operator, so I'm always
glad to see a practical example.  Thanks, John!




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

Date: Fri, 4 Oct 2002 09:29:21 +1000
From: "Tom Beer" <tom.beer@btfinancialgroup.spamfilter.com>
Subject: Re: Unable to trap error from child
Message-Id: <anijsi$5aa$1@merki.connect.com.au>

Benjamin Goldberg wrote in message <3D9CB387.CDE330E3@earthlink.net>...
>Tom Beer wrote:
>[snip]
>>             $childpid = wait;
>>             print "$childpid exited with q = $?; x = $!\n";
>
>The $! variable will only be valid if wait() failed.  So, do:

Thanks Benjamin. I knew that wasn't the right variable to catch the error
from the child, but I was getting desperate. I will modify my code to check
that the wait succeeds.

BTW, I thought I read that Perl 6 would combine all the error variable into
one, but I can't seem to find this now. Is it true?

Tom.





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

Date: Thu, 03 Oct 2002 17:59:26 CDT
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: What is the best way for file/stream IO in Perl?
Message-Id: <Xns929CC17DA993Dsdn.comcast@216.166.71.239>

"Paul Dortman" <paul@pco.iis.nsk.su> wrote in
news:anh7vf$hts$1@news.itfs.nsk.su: 

> Dear friends,
> 
> I have a questions for Perl's guru.

Yo Paul.  Have some patience, eh?

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


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

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


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