substitution problem

2003-10-23 Thread Steve Massey
Hi

I though I had sussed this s/ stuff but

#! /usr/bin/perl -w

$test =  "BRIGHTON (Firm)";


print "$test\n";
$test =~ s/,*/,/;
$test =~ s/,*$/,/g;

print "$test\n";



does not work, I want to substitute all multiple commas into a single one.

any help appreciated

Steve

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: substitution problem

2003-10-23 Thread Steve Massey
Ok scrub that

 + works but * doesn't

i'm guess the * is matching anything 

took me 2 hours to figure that  ;)






-Original Message-
From: Steve Massey [mailto:[EMAIL PROTECTED]
Sent: 23 October 2003 11:33
To: [EMAIL PROTECTED]
Subject: substitution problem


Hi

I though I had sussed this s/ stuff but

#! /usr/bin/perl -w

$test =  "BRIGHTON (Firm)";


print "$test\n";
$test =~ s/,*/,/;
$test =~ s/,*$/,/g;

print "$test\n";



does not work, I want to substitute all multiple commas into a single one.

any help appreciated

Steve

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: substitution problem

2003-10-23 Thread Gary Stainburn
On Thursday 23 Oct 2003 11:52 am, Steve Massey wrote:
> Ok scrub that
>
>  + works but * doesn't
>
> i'm guess the * is matching anything
>
> took me 2 hours to figure that  ;)
>


Hi Steve,

+ matches 1 or more,
* matches 0 or more.

for better efficiency, you really want to do 

s/,,+/,/;

which will not then replace 1 comma with another.

Gary

>
>
>
>
>
> -Original Message-
> From: Steve Massey [mailto:[EMAIL PROTECTED]
> Sent: 23 October 2003 11:33
> To: [EMAIL PROTECTED]
> Subject: substitution problem
>
>
> Hi
>
> I though I had sussed this s/ stuff but
>
> #! /usr/bin/perl -w
>
> $test =  "BRIGHTON (Firm)";
>
>
> print "$test\n";
> $test =~ s/,*/,/;
> $test =~ s/,*$/,/g;
>
> print "$test\n";
>
>
>
> does not work, I want to substitute all multiple commas into a single one.
>
> any help appreciated
>
> Steve

-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Question on transliteration

2003-10-23 Thread Paul Harwood
Can someone translate into English:
 
($filename) = $file =~ m!([^/]*)$!;

 
Why is $filename in parens?


Regex searches including spaces

2003-10-23 Thread Paul Harwood
I am trying to parse through the following line:
 
TUITimer> TUI Dead Air Timer::1828ms::

I want to extract the 1828 value. The regex I have is: 

if ( /TUI Dead Air(\d+)/ ) {

I know this is wrong but I have tried every variation of \s that I can think of with 
no success. Also, is there a Regex generator of some kind where I can enter text 
searches and have them translated to Perl Regex format? I am using a Win32 platform.

--Paul

 

 

 

 
 


Deleting # and other characters

2003-10-23 Thread Raghu Murthy
I tried using
next if s?\([  /]\)\./?\1?g;
and it did not work. The file looks like this

a b ./zyc/dfdk ./dkld/kdj
k l ./ksdk/ksk/ksd./kskd/kdsk
Thanks

_
Never get a busy signal because you are always connected  with high-speed 
Internet access. Click here to comparison-shop providers.  
https://broadband.msn.com

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Deleting # and other characters

2003-10-23 Thread Raghu Murthy
I tried doing the following

next if s?\([  /]\)\./?\1?g;

For some reason it is not removing the ./ from the file. Any suggestions are 
welcome.
The file is in this format

a b  ./dsfj/dfl/dksl ./ksdfl/dsld

c d  ./sds/dsl/dksld   ./kdf/ksd/ksdk

Thanks

Raghu

In article <[EMAIL PROTECTED]>, Kevin Pfeiffer wrote:

In article <[EMAIL PROTECTED]>, Raghu Murthy wrote:

I need to remove ./ and #from a list of files. I can do it in sed but I
am not able to use it in my perl script. I tried to do something like
this
chomp ($txtlist = );
qx' sed -e "/^#/d $txtlist'; # To remove lines starting with a #
qx' sed -e"s?\([  /]\)\./?\1?g" $txtlist; # To remove lines starting with
a ./
I can do it if i hard code the file name but if i try to use $txtlist it
does not work. What am i doing wrong.
Thinking that I misunderstood the question... $txtlist is the file you want
to edit?
If you call the script so: ./strip_chars txtlistfile > new_version

then you would start the code I posted with "while (<>) {" instead.

--
Kevin Pfeiffer
_
Fretting that your Hotmail account may expire because you forgot to sign in 
enough? Get Hotmail Extra Storage today!   
http://join.msn.com/?PAGE=features/es

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Regex searches including spaces

2003-10-23 Thread Gary Stainburn
On Thursday 23 Oct 2003 1:03 am, Paul Harwood wrote:
> I am trying to parse through the following line:
>
> TUITimer> TUI Dead Air Timer::1828ms::
>
> I want to extract the 1828 value. The regex I have is:
>
> if ( /TUI Dead Air(\d+)/ ) {
>
> I know this is wrong but I have tried every variation of \s that I can
> think of with no success. Also, is there a Regex generator of some kind
> where I can enter text searches and have them translated to Perl Regex
> format? I am using a Win32 platform.
>
> --Paul

Hi Paul,

you missed out the colons.  Have a look at 

#!/usr/bin/perl -w

$_='TUITimer> TUI Dead Air Timer::1828ms::';

print "$1\n" if (/Dead Air Timer::(\d+)ms/) ;
  
-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Tool for Tk developer?

2003-10-23 Thread EXTERN Chakirov Timour (TZ CIS; DS/ESQ3)
Hello there,

I'm lookoing for a tool that I could use to sketch a Perl Tk GUI. Prefferable platform 
- Sun Solaris, but Windows is also Ok. Could you please tell me if such a tool exists?

TIA,
Tim

---
Robert Bosch GmbH Tel: +49 (0) 711-811- 40134
Postfach 30 02 20 Fax: +49 (0) 711-811- 31800 
D-70442 Stuttgart e-mail: [EMAIL PROTECTED]
Besucher: Wernerstr.1, Fe052/114A, D-70469 Stuttgart-Feuerbach

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



DBMHashes , a question...

2003-10-23 Thread Jones, Jeremy
Hello All,

are DBM Hashes a limited data structure? as in must they remain a standard
hash and not %HoA or %HoH (Hash of array / Hash of Hash)?

I have a program that should create  a DBM hash %HoA but the only thing that
remains is the Key. the array (Value does not get saved!)

any thoughts? 


Jeremy F. Jones


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: What is the best way to set options in a constructor

2003-10-23 Thread R. Joseph Newton
James Edward Gray II wrote:

> >   my $self;
>
> $self isn't a reference to a hash, even though you're about to start
> using it like one.
>
> my $self = { };
>
> >   $self->{BOOL_1} = 0;
> >   $self->{BOOL_2} = 0;

Actuaqlly, it will work the way he has it.  The anonymous hash is
auto-vivified on first assignment:
Greetings! E:\d_drive\perlStuff>perl -w
my $self;
$self->{'up'} = 'high';
$self->{'down'} = 'Hi';
print "$_: $self->{$_}\n" foreach keys %$self;
^Z
down: Hi
up: high

 I do agree, though, that assigning the empty hash reference at declaration
is more self-commenting.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: What is the best way to set options in a constructor

2003-10-23 Thread R. Joseph Newton
"Randal L. Schwartz" wrote:

> > "Dan" == Dan Anderson <[EMAIL PROTECTED]> writes:
>
> Dan>   my $class = ref($proto) || $proto;
>
> Don't do this!
>
> .

Hi Randal,

Read the article, and it percursor thread.  I'm still a little mystified as to
what you find offensive there.  Perhaps one should be aware of the contents, if
any, of @ISA, before writing the new method.  It doesn't always work that way,
though, and having a flexible [and standardized] constructor does not seem to do
any harm.  Is there some potential harm you see?

I'll grant that I have sometimes felt silly having that construct in a root
class, but so far it has not done any actual damage.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: What is the best way to set options in a constructor

2003-10-23 Thread Randal L. Schwartz
> "R" == R Joseph Newton <[EMAIL PROTECTED]> writes:

R> "Randal L. Schwartz" wrote:
>> > "Dan" == Dan Anderson <[EMAIL PROTECTED]> writes:
>> 
Dan> my $class = ref($proto) || $proto;
>> 
>> Don't do this!
>> 
>> .

R> Hi Randal,

R> Read the article, and it percursor thread.  I'm still a little mystified as to
R> what you find offensive there.  Perhaps one should be aware of the contents, if
R> any, of @ISA, before writing the new method.  It doesn't always work that way,
R> though, and having a flexible [and standardized] constructor does not seem to do
R> any harm.  Is there some potential harm you see?

Sorry you missed the point then.

The point is that

$instance->new

could mean either "clone", or "make one of the same class as".  You
don't need it for "make one of the same class as", because you've got:

(ref $instance)->new

to do that explicitly.  And if you really wanted that to do clone,
CALL IT CLONE, don't call it ->new.

It obscures more than it clarifies, and hence is a *bad* name
for an instance method.

And because it's a bad name for an instance method, it should
not respond as an instance method.  That simplifies the "standard
constructor immensely", to something like:

sub new {
  my $class = shift;
  my $self = { ... };
  other fixups
  return bless $self, $class; # return is optional here
}

This makes your code both clearer, and faster.

The "ref($proto) || $proto" code originally came from a guy who had
not done a lot of OO programming, and didn't completely understand it
apparently.  *I* was programming in Smalltalk in 1980.  *I* understand
the need for well-chosen method names.

So, while I cannot get "perltoot" removed from the docs, I'm
trying to do damage control to fix that problem.

There... does that help?  It's not about @ISA.  It's about proper
choice for method names.  $instance->new has too many meanings
to be a good name, ever.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: substitution problem

2003-10-23 Thread Wiggins d Anconia
> Ok scrub that
> 
>  + works but * doesn't
> 
> i'm guess the * is matching anything 
> 
> took me 2 hours to figure that  ;)
> 
To de-mystify the regexes some have a look at:

perldoc perlretut
perldoc perlre

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Regex searches including spaces

2003-10-23 Thread Perry, Alan
Paul Harwood wrote:

>I am trying to parse through the following line:
> 
>TUITimer> TUI Dead Air Timer::1828ms::
>
>I want to extract the 1828 value. The regex I have is: 
>
>if ( /TUI Dead Air(\d+)/ ) {
>
>I know this is wrong but I have tried every variation
>of \s that I can think of with no success. Also, is
>there a Regex generator of some kind where I can enter
>text searches and have them translated to Perl Regex
>format? I am using a Win32 platform.
>
>--Paul

If you know that it will be the only number on the line, try this:

if ( /(\d+)/ ) {

Not sure of any tool like you described...

- Alan

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: DBMHashes , a question...

2003-10-23 Thread Bob Showalter
Jones, Jeremy wrote:
> Hello All,
> 
> are DBM Hashes a limited data structure? as in must they remain a
> standard hash and not %HoA or %HoH (Hash of array / Hash of Hash)?

Yes, but the MLDBM module is the answer here. It uses Storable (or other
modules) to serialize the complex hash value into a single string for
storage in the DBM and reverses the process on exit.

Very nice.

> 
> I have a program that should create  a DBM hash %HoA but the only
> thing that remains is the Key. the array (Value does not get saved!)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Question on transliteration

2003-10-23 Thread Stefan Lidman
>Can someone translate into English:
>
>($filename) = $file =~ m!([^/]*)$!;
>
>
>Why is $filename in parens?

The parens put $filename in list context so that it contains whatever is after
the last '/'. In scalar context it contains the number of times the regexp matched.

/Stefan

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: trouble backup with perl.

2003-10-23 Thread Goffredo Saffioti
Wiggins d'Anconia ha scritto:

Goffredo Saffioti wrote:

Good Evening all .

I'm experiencing to write a perl script for to make backup with afio 
under perl .
But a have some problem when try to execute the system command with 
the " @_ " this seem to be not the right way for exec this system 
command "i'm not sure" .
but in past time i'm used this kind of syntax for another script that 
make the quota for all users in a directory on the same way.
the backup scrpt is as follow:

#!/usr/bin/perl -w

use strict; # always

#use IO::Socket;
use IPC::Open2;
use Term::ANSIColor;
use POSIX ":sys_wait_h";
These three modules are great, but are you sure you need them?

my $status;


Where does $status get used?

#$pid = fork;
#$begin = 1 if ( !$begin );
#$end = $i if ( !$end);
I am assuming these won't be coming back, if they are where do they 
come from?

#$FULLSYSTEM_SOURCE_DIR = "/home/webhosting/utenti/";
$MOUNT_DIR = "/mnt/test";
$BACKUP_FILE = "Testbackup.cpio";
$FULL_LOG_FILE = "Testlog.log";
These have not been scoped.

$filename = "/home/webhosting/utenti/stats.txt";

No scoping.

@_=`ls -l`;#Read the direcory content


perldoc -f opendir
perldoc -f readdir
Shelling out is a very inefficient, insecure, error prone way of doing 
this operation, it is much better handled with a dir handle, or with 
the File::Find module if you want recursion.  While Perl likes to do 
lots of fancy stuff with @_ and $_, lets dispense with the cryptic 
stuff and use real variable names until we understand when and why we 
should use cryptic names...

while ($_ = shift @_) {


I assume here you are attempting to loop over the list of files? See 
above documentation.

@strarr = split ' ';


Why are you splitting on space?
perldoc -f split
open(LOG, ">> $filename") || die "cannot open file";


Include $! in your error messages so you know why it died, not just 
that it did.  This is a very inefficient loop, if you are going to 
write to the same file every pass over the array then open the file 
once outside of the while loop, then just keep printing to it rather 
than re-opening it.


print LOG "$strarr[8]\n";#and write the filenames on a file


What does the *9th* element have in it? How do you know it is the 9th 
element?  If this is supposed to be the filename check out

perldoc File::Basename

close (LOG);


Again if you open your filehandle outside of the while loop you don't 
have to close it every iteration, this should go outside the loop.

}


At this point I am very confused because it looks like you are writing 
to a file that you then read and loop over to call a command on each 
of the elements, why the write just to read in the same thing? Why not 
just do your work all in one loop?



open (LOG1, "< /home/webhosting/utenti/stats.txt") || die "cannot 
open file with LOG1";


Again include $!...

@log1=();


Ok read the whole thing in, no scoping.

for ($i=1;$i<=((@log1)/4);$i++){  #my dir is too big so i devide the 
content in parts more little

If you are concerned about the size there is no need to store the 
whole file to an array and then loop over the array.  You do realize 
you are skipping the first elmenet of the array right? Array indices 
start at zero. This also isn't dividing your array into parts, it is 
looping from 1 to 4 so you will only get the 2nd through 5th elements 
of the array, and even if it was your initial read of the file stores 
the whole thing to memory so it is a moot point if this for loop did 
only read a quarter at a time

open (LOG2, ">> /home/webhosting/utenti/statswork.txt") || die 
"cannot open file with LOG1";


Include $!... I assume this is a file to let you know how far you have 
gone in your work?  Again open the file outside of the loop once, then 
print to it inside the loop.

print LOG2 "$log1[$i]";  #and write this part on a new file


open (LOG3, "< /home/webhosting/utenti/statswork.txt") || die "cannot 
open file with LOG1"; #so... now the trouble .


Why are we reopening the file we just wrote inside the loop?


#this is the system command that i experience to exec but when i exec 
the script i receive this : sh: -print: command not found
and the script terminate .
So how can i accomplish this trouble?

@_= `/usr/bin/find $log1[$i] -print -depth -mount -xdev | 
/usr/bin/afio -oulvAZ/ -T3k -s 2000m -L$MOUNT_DIR/$FULL_LOG_FILE 
$MOUNT_DIR/$BACKUP_FILE`; /

Again use a descriptive variable name for your output capturing. As to 
why you are getting that particular error message I really can't say, 
what is in $log1[$i]?  You should try cleaning up the program first, 
then print the commands that should be run rather than just calling 
them, then copy and paste one of them, see if it does what you want 
then add it to the looping constructs.  What's the trailing backslash 
doing there? You should also be checking the return status of the 
command by examining $?, etc. perldoc -f system for more

close (LOG3);
close (LOG2);
close (LOG1);


Assuming

Re: What is the best way to set options in a constructor

2003-10-23 Thread Steve Grazzini
On Thu, Oct 23, 2003 at 06:48:29AM -0700, R. Joseph Newton wrote:
> "Randal L. Schwartz" wrote:
> > > "Dan" == Dan Anderson <[EMAIL PROTECTED]> writes:
> >
> > Dan>   my $class = ref($proto) || $proto;
> >
> > Don't do this!
> 
> I'm still a little mystified as to what you find offensive there.

[snip]

> I'll grant that I have sometimes felt silly having that construct in a root
> class, but so far it has not done any actual damage.

There are two things going on --

First, the constructor is taking the classname from the first argument,
like this:

sub new {
  my $class = shift; 
  my $self = { initial => 'data' };
  bless $self, $class;
}

There's nothing wrong with that, and in fact it's *necessary* if a derived
class wants to inherit the new() method from Foo.  So don't feel silly about
using "my $class = shift" in a root class!  That's where you really need to
be using it.

But the constructor is also prepared to take an object as the first argument
instead of just the classname-as-a-string.  This is explained in perltoot:

While we're at it, let's make our constructor a bit more flexible.
Rather than being uniquely a class method, we'll set it up so that it
can be called as either a class method or an object method.  That way
you can say:

$me  = Person->new();
$him = $me->new();

To do this, all we have to do is check whether what was passed in was a
reference or not.  If so, we were invoked as an object method, and we
need to extract the package (class) using the ref() function.  If not,
we just use the string passed in as the package name for blessing our
referent.

sub new {
my $proto = shift;
my $class = ref($proto) || $proto;

And then Tom uses "ref($proto) || $proto" in all the following examples.

There's no *functional* problem with doing this; it's not going to break 
anything, and if users of your class don't use "$obj->new" then the
"ref($proto)" stuff won't do anything at all.

But what seems to be a problem is that lots of people got the impression
that a) this has something to do with inheritance -- which it doesn't --
and that b) it's somehow *obligatory*; that if you forget to check
"ref($proto)" your constructor is broken.

Now, I don't particularly like "$obj->new", but it's not really "wrong"
either.  If you want to let people call your constructor that way, then
go ahead and use "ref($proto) || $proto".  And conversely, if you think
"$obj->new" is an abomination, then just use "my $class = shift".

But either way, make an informed decision.  Don't cargo-cult it in
because it's in the examples in perltoot.  And don't cargo-cult it out
because Randal smacks you whenever you use "ref($proto)" in public.

-- 
Steve

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: What is the best way to set options in a constructor

2003-10-23 Thread Randal L. Schwartz
> "Steve" == Steve Grazzini <[EMAIL PROTECTED]> writes:

Steve> Now, I don't particularly like "$obj->new", but it's not really "wrong"
Steve> either.  If you want to let people call your constructor that way, then
Steve> go ahead and use "ref($proto) || $proto".  And conversely, if you think
Steve> "$obj->new" is an abomination, then just use "my $class = shift".

Steve> But either way, make an informed decision.  Don't cargo-cult it in
Steve> because it's in the examples in perltoot.  And don't cargo-cult it out
Steve> because Randal smacks you whenever you use "ref($proto)" in public.

Well, if you want to obscure your code, go ahead.  But I thought
real world code wasn't about JAPHs and Golf and Obfu-Perl.

So, it has no place in *real world* code. That's all I'm saying.  It
obscures more than it helps, and shouldn't be carbon-copied into every
constructor out of habit.  If you use it, DOCUMENT THE HELL OUT OF IT,
because it comes out of left field.

Note that I have no problem with other method names being used
for both class methods and instance methods.  It's only the highly
overloaded term "new" that I'm referencing here.

In fact, I can make a (albeit weaker) case that "new" is the wrong
name for a constructor anyway, and that constructors should be named
as natural verbs, like DBI's "connect".  But nobody from the C++ camp
would ever support me on that, because their minds are already
corrupt. :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



run in background from qx//?

2003-10-23 Thread McMahon, Chris
 
Hi... 
This should be easy, but I can't seem to do it.  I'm trying to
launch an external process from a Perl script to run in the background on a
FreeBSD system.  The process starts fine, but won't run in the background.
I've tried: 

qx/ &/ 
qx/ \&/
` &`
` \&`
qx/ '&'/
 
etc., and the "&" doesn't seem to be making it from the Perl
script to the shell.   (BTW, doing " &" at the shell prompt
works fine.) 
Any suggestions about how to launch a process in the background
from a Perl script?  
-Chris   


Re: run in background from qx//?

2003-10-23 Thread Stefan Lidman
>Hi... 
>This should be easy, but I can't seem to do it.  I'm trying to
>launch an external process from a Perl script to run in the background on a
>FreeBSD system.  The process starts fine, but won't run in the background.
>I've tried: 
>
>qx/ &/ 
>qx/ \&/
>` &`
>` \&`
>qx/ '&'/
> 
>etc., and the "&" doesn't seem to be making it from the Perl
>script to the shell.   (BTW, doing " &" at the shell prompt
>works fine.) 
>Any suggestions about how to launch a process in the background
>from a Perl script?  
>-Chris

system ' &';

/Stefan

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: substitution problem

2003-10-23 Thread Mark Anderson
> From: Steve Massey [mailto:[EMAIL PROTECTED]
> Sent: 23 October 2003 11:33
>
> #! /usr/bin/perl -w
>
> $test =  "BRIGHTON (Firm)";
>
>
> print "$test\n";
> $test =~ s/,*/,/;
> $test =~ s/,*$/,/g;
>
> print "$test\n";

It looks like the +/* issue has been discussed.  The other option you could
use would be ,{2,} which matches 2 or more ,s in a row.

The other thing that I notices is that you are using the g option on the
wrong substitution.  It matches repeatedly within the string.  There will
only ever be one set of commas at the end of the string, but there may be
multiple sets within the string.  A single substitution of
$test =~ s/,+/,/g;
will replace the string at the end as well as any that show up in
mid-string.  The second substitution can then be changed if you don't want a
trailing comma, to
$test =~ s/,$//;

/\/\ark


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: What is the best way to set options in a constructor

2003-10-23 Thread Wiggins d Anconia


> > "Steve" == Steve Grazzini <[EMAIL PROTECTED]> writes:
> 
> Steve> Now, I don't particularly like "$obj->new", but it's not really
"wrong"
> Steve> either.  If you want to let people call your constructor that
way, then
> Steve> go ahead and use "ref($proto) || $proto".  And conversely, if
you think
> Steve> "$obj->new" is an abomination, then just use "my $class = shift".
> 
> Steve> But either way, make an informed decision.  Don't cargo-cult it in
> Steve> because it's in the examples in perltoot.  And don't cargo-cult
it out
> Steve> because Randal smacks you whenever you use "ref($proto)" in public.
> 
> Well, if you want to obscure your code, go ahead.  But I thought
> real world code wasn't about JAPHs and Golf and Obfu-Perl.
> 
> So, it has no place in *real world* code. That's all I'm saying.  It
> obscures more than it helps, and shouldn't be carbon-copied into every
> constructor out of habit.  If you use it, DOCUMENT THE HELL OUT OF IT,
> because it comes out of left field.
> 
> Note that I have no problem with other method names being used
> for both class methods and instance methods.  It's only the highly
> overloaded term "new" that I'm referencing here.
> 
> In fact, I can make a (albeit weaker) case that "new" is the wrong
> name for a constructor anyway, and that constructors should be named
> as natural verbs, like DBI's "connect".  But nobody from the C++ camp
> would ever support me on that, because their minds are already
> corrupt. :)
> 

I imagine it is just the cargo culting because of lack of examples like
Randal's. Ironically I tend to fall in the "programming explicitly" camp
where I want my code to reflect exactly what it does, but I am in the
cargo cult group because *everything* I had read explained it that way.
Having seen Randal's argument, knowing my own biases, I do prefer his
idea, but I also consider myself an advanced average Perl programmer
(that is, certainly not near guru status) and so I probably reflect more
closely what the average and newbie programmers will have seen
documented and the reasons behind it. I also think Randal's example
usage while perfect is intimidating to a new or average programmer,
there is just an extra call going on there that to someone that
understands it, it doesn't matter, but to a novice it is something that
doesn't look quite right, so "hiding" the same thing in the constructor
is just the easy, lazy (in the bad way) approach for the more advanced
author of the module.  In the above I am referring to:

my $new_obj = ref($obj)->new;

The indirection is difficult to read at first so back loading it is just
easier for the user, but as Randal points out is not forcing them to
explicitly ask for what they want, where as the above is, and some of us
prefer that.

However I don't feel like running out and updating all of my modules,
but I am going to change my templates ;-)

So what would it take to get Randal's view at least added to the docs,
and a good description of why that view is held?

I do have to differ with the opinion about new, if you really are just
constructing an object then to me it still makes sense as a name, but in
the case of DBI you are constructing an object *and* performing an
action, so the 'connect' name makes sense. To me it would also make
sense if there was (and maybe there is):

my $dbi = new DBI;
my $dbh = $dbi->connect;

Because in this case you are *just* constructing an object, and then
*just* connecting...  But this assumes you throw out the history of the
corruption of the name 'new' both as a cloning method and as "let's do
more than just create an object, lets also connect to a server, read a
file, etc." which somehow I don't think Randal will let us ;-) (and he
probably is right not to)

Just my ranting on the subject

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: SMS messages from Windows

2003-10-23 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Rajendra Babu, Praveen wrote:
> Hi there,
>Did anyone send free SMS mobile messages from Perl under
> Windows environment ? If yes, can you please share your "how to ?"
> 
> Thanks heaps.
> 
> Best regards,
> Praveen
You need only to know what provider you are going through and then send to 
that phone number plus domain assoicated with that provider. For mine, I use att, so I 
send to 
[EMAIL PROTECTED] You have up to 110 characters to send. I use this to notify me of 
certain conditions as I have a couple of scripts running 24x7. I just use sendmail and 
it works like a charm.

Wags ;)


**
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



No dice;details . RE: run in background from qx//?

2003-10-23 Thread McMahon, Chris
Stefan...
The line I'm trying to execute looks like: 

"/dir/dir2/program -a -a -B 5000 -c $var1 -d value $var2&"  

I'm trying to do this with 'system' and failing.  How would you
parse this run line for 'system' to execute?  
-Chris

-Original Message-
From: Stefan Lidman [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 23, 2003 9:52 AM
To: [EMAIL PROTECTED]
Subject: Re: run in background from qx//?

>Hi... 
>This should be easy, but I can't seem to do it.  I'm trying to
>launch an external process from a Perl script to run in the background on a
>FreeBSD system.  The process starts fine, but won't run in the background.
>I've tried: 
>
>qx/ &/ 
>qx/ \&/
>` &`
>` \&`
>qx/ '&'/
> 
>etc., and the "&" doesn't seem to be making it from the Perl
>script to the shell.   (BTW, doing " &" at the shell prompt
>works fine.) 
>Any suggestions about how to launch a process in the background
>from a Perl script?  
>-Chris

system ' &';

/Stefan

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Deleting # and other characters

2003-10-23 Thread Kevin Pfeiffer
In article <[EMAIL PROTECTED]>, Raghu Murthy wrote:

> I tried doing the following
> 
> next if s?\([  /]\)\./?\1?g;

That looks to me more like sed (as best I can tell) and not Perl.

> For some reason it is not removing the ./ from the file. Any suggestions
> are welcome.
> The file is in this format
> 
> a b  ./dsfj/dfl/dksl ./ksdfl/dsld
> 
> c d  ./sds/dsl/dksld   ./kdf/ksd/ksdk

Well, you could always use:

tr/\.\///d;
print;

...which would give you this:
a b  dsfjdfldksl ksdfldsld

c d  sdsdsldksld   kdfksdksdk


Or this:
s|\./||g;
print;

...which produces this:
a b  dsfj/dfl/dksl ksdfl/dsld

c d  sds/dsl/dksld   kdf/ksd/ksdk

...if that is what you want (I'm not quite sure).

-Kevin


-- 
Kevin Pfeiffer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



How to delete a file from the file system

2003-10-23 Thread Chinku Simon
Hi,

Is there any module which has methods that can be used to delete a file from the 
filesystem in the
windows NT environment.

Thanks in Advance
Chinku

__
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: How to delete a file from the file system

2003-10-23 Thread Bakken, Luke
H.

Look at "perldoc -f unlink" 

> -Original Message-
> 
> Hi,
> 
> Is there any module which has methods that can be used to 
> delete a file from the filesystem in the
> windows NT environment.
> 
> Thanks in Advance
> Chinku

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: No dice;details . RE: run in background from qx//?

2003-10-23 Thread Stefan Lidman
>Stefan...
>   The line I'm trying to execute looks like: 
>
>"/dir/dir2/program -a -a -B 5000 -c $var1 -d value $var2&"  
>
>   I'm trying to do this with 'system' and failing.  How would you
>parse this run line for 'system' to execute?  
>   -Chris

system '/dir/dir2/program -a -a -B 5000 -c ' . $var1 .  ' -d value '. $var2 .'&';

should work

/Stefan

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



ftp file list filters?

2003-10-23 Thread Jeffrey Pearson
Im trying to write a script the ftp's a bunch of files from different locations. I 
only want to grab files that are of specific file type and whose name begins with a 
certain combination of characters. Can I filter it at the listing side in other words 
do something like dir abc*.gif and go through those files or would I need to grab all 
of the files and filter it at my side to get my file list?
 
Any suggestions/help would be greatly appreciated.
 
Jeff Pearson


Re: ftp file list filters?

2003-10-23 Thread Wiggins d Anconia


> Im trying to write a script the ftp's a bunch of files from different
locations. I only want to grab files that are of specific file type and
whose name begins with a certain combination of characters. Can I filter
it at the listing side in other words do something like dir abc*.gif and
go through those files or would I need to grab all of the files and
filter it at my side to get my file list?
>  

I am assuming you are using Net::FTP, because you should be if you
aren't ;-), in which case you should check out the 'ls' method, or the
'dir' method but it takes more parsing as it is a long listing.

'ls' returns a list of files in the remote cwd, you can then parse that
list, then do whatever you need with just the ones you parsed.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: SMS messages from Windows

2003-10-23 Thread Rajendra Babu, Praveen
Thanks David ! I reckon the mobile should be capable to receive e-mails
rather than SMS ?? Please correct me if I am wrong.
 
Regards,
Praveen

-Original Message-
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:[EMAIL PROTECTED]
Sent: Friday, 24 October 2003 2:06 AM
To: Rajendra Babu, Praveen; [EMAIL PROTECTED]
Subject: RE: SMS messages from Windows


Rajendra Babu, Praveen wrote:
> Hi there,
>Did anyone send free SMS mobile messages from Perl under
> Windows environment ? If yes, can you please share your "how to ?"
> 
> Thanks heaps.
> 
> Best regards,
> Praveen
You need only to know what provider you are going through and then
send to that phone number plus domain assoicated with that provider. For
mine, I use att, so I send to 
[EMAIL PROTECTED] You have up to 110 characters to send. I use this
to notify me of certain conditions as I have a couple of scripts running
24x7. I just use sendmail and it works like a charm.

Wags ;)


**
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.


IMPORTANT-
(1) The contents of this email and its attachments are confidential and 
intended only for the individual or entity named above. Any unauthorised
use of the contents is expressly prohibited.  If you receive this email 
in error, please contact us, then delete the email.
(2) ACNielsen collects personal information to provide and market our 
services. For more information about use, disclosure and access see our 
privacy policy at  or contact us on [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: trouble backup with perl.

2003-10-23 Thread Wiggins d'Anconia
Goffredo Saffioti wrote:



Ok your script work fine, but my problem still persist, because the work 
directory is too big so i need to do backup on more little portion of 
dir , i attempt to process i wish to process $backup_dir/2 or /4 how can 
do it?
Which part of the process is failing because the directory is to big? 
The find should be able to handle it, so is it the other part?  Because 
I am not familar with the utility you are running I can't tell where 
your size limitation is...

http://danconia.org

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: SMS messages from Windows

2003-10-23 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Rajendra Babu, Praveen wrote:
> Subject: RE: SMS messages from Windows
> 
> 
> Thanks David ! I reckon the mobile should be capable to receive
> e-mails rather than SMS ?? Please correct me if I am wrong.
> 
> Regards,
> Praveen
> 
I send to my cell phone which I assume is what you are after. There is even a 
Pager module on CPAN so if needed you could even send to a pager.

Wags ;)


**
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



passing DOS command in perl

2003-10-23 Thread Trina Espinoza
Trying to send a DOS command using perl, but get a little confused as to how 
this changes when passing this in as a system call in perl.

The DOS command:

C:\>del /q /S "c:\Documents and Settings\test\Local Settings\Temp\*.*"

When I run the command in perl I try escaping the second set of quotes to 
pass the command, but that fails to work. I have also tried passing it along 
with single quotes and escaping the spaces no avail .Can anyone offer up 
some info on how I should pass this?

Example of one failed attempt :(
system("del /q /S \"c:\Documents and Settings\test\Local 
Settings\Temp\*.*\"");

As usual, thanks for reading this!

-T

_
Cheer a special someone with a fun Halloween eCard from American Greetings! 
Go to  http://www.msn.americangreetings.com/index_msn.pd?source=msne134

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: passing DOS command in perl

2003-10-23 Thread Wiggins d'Anconia
Trina Espinoza wrote:
Trying to send a DOS command using perl, but get a little confused as to 
how this changes when passing this in as a system call in perl.

The DOS command:

C:\>del /q /S "c:\Documents and Settings\test\Local Settings\Temp\*.*"

When I run the command in perl I try escaping the second set of quotes 
to pass the command, but that fails to work. I have also tried passing 
it along with single quotes and escaping the spaces no avail .Can anyone 
offer up some info on how I should pass this?

Example of one failed attempt :(
system("del /q /S \"c:\Documents and Settings\test\Local 
Settings\Temp\*.*\"");

As usual, thanks for reading this!

I believe you need to escape the backslashes, since Perl is 
interpolating them in the string, so each of your path markers need to 
be escaped.

Though this whole thing is less secure, less efficient, less portable, 
and more error prone than doing it within Perl itself,

perldoc -f unlink
perldoc File::Path
http://danconia.org

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: substitution problem

2003-10-23 Thread R. Joseph Newton
Steve Massey wrote:

> Hi
>
> I though I had sussed this s/ stuff but
>
> #! /usr/bin/perl -w
>
> $test =  "BRIGHTON (Firm)";
>
> print "$test\n";
> $test =~ s/,*/,/;
> $test =~ s/,*$/,/g;
>
> print "$test\n";
>
> does not work, I want to substitute all multiple commas into a single one.
>
> any help appreciated
>
> Steve

One of these should work:

Greetings! E:\d_drive\perlStuff>perl -w
$test =  "BRIGHTON (Firm)";


print "$test\n";
$test =~ s/,+/,/g;
print "$test\n";
^Z
BRIGHTON (Firm)
BRIGHTON, (Firm),

Greetings! E:\d_drive\perlStuff>perl -w
$test =  "BRIGHTON (Firm)";

print "$test\n";
$test =~ s/,*/,/g;
$test =~ s/,*/BRIGHTON (Firm)
Terminating on signal SIGINT(2)

Greetings! E:\d_drive\perlStuff>perl -w
$test =  "BRIGHTON (Firm)";

print "$test\n";
$test =~ s/,+/,/g;
$test =~ s/,+$//;
print "$test\n";
^Z
BRIGHTON (Firm)
BRIGHTON, (Firm)

Greetings! E:\d_drive\perlStuff>

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: What is the best way to set options in a constructor

2003-10-23 Thread R. Joseph Newton
"Randal L. Schwartz" wrote:

> > "R" == R Joseph Newton <[EMAIL PROTECTED]> writes:
>
> R> "Randal L. Schwartz" wrote:
> >> > "Dan" == Dan Anderson <[EMAIL PROTECTED]> writes:
> >>
> Dan> my $class = ref($proto) || $proto;
> >>
> >> Don't do this!
> >>
> >> .
>
> R> Hi Randal,
>
> R> Read the article, and it percursor thread.  I'm still a little mystified as to
> R> what you find offensive there.  Perhaps one should be aware of the contents, if
> R> any, of @ISA, before writing the new method.  It doesn't always work that way,
> R> though, and having a flexible [and standardized] constructor does not seem to do
> R> any harm.  Is there some potential harm you see?
>
> Sorry you missed the point then.
>
> The point is that
>
> $instance->new
>
> could mean either "clone", or "make one of the same class as".  You
> don't need it for "make one of the same class as", because you've got:
>
> (ref $instance)->new
>
> to do that explicitly.  And if you really wanted that to do clone,
> CALL IT CLONE, don't call it ->new.
>
> It obscures more than it clarifies, and hence is a *bad* name
> for an instance method.
>
> And because it's a bad name for an instance method, it should
> not respond as an instance method.  That simplifies the "standard
> constructor immensely", to something like:
>
> sub new {
>   my $class = shift;
>   my $self = { ... };
>   other fixups
>   return bless $self, $class; # return is optional here
> }
>
> This makes your code both clearer, and faster.

Got it.  Thanks.  You know, I never would have imagined anybody trying to use a
constuctor to clone, except perhaps by passing an object reference in as an argument.
I had asumed that it had something to do with importing parent classes.  Thanks for
clearing that up.  I guess I'll do some inheritance experiments to see how the
constructor works without that construct.

Joseph



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]