Re: Output Unicode

2004-04-01 Thread WC -Sx- Jones
Octavian Rasnita wrote:

It seems that something's wrong because Internet Explorer automaticly
chooses UTF-8 encoding, but it doesn't display the text correctly.
In fact, I don't know which is the problem because I read the text from the
screen using a screen reader (I am blind) but I can read other UTF encoded
pages like Google's page, without problems.
Try this - If it works in Mozilla 1.6 and Doesn't work in IE -- then
IE is broken.  If it doesn't work in Mozilla then the creation method
is broken.
I get multi-byte chracter's decoded and properly displayed in Mozilla 
always -- unless the generation method was invalid to start with.

HTH/Sx

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



BitVector in GET/POST Params

2004-04-01 Thread Richard Heintze
I have a bit array I need to store in GET/POST
parameters and input type=hidden fields. Presently
I'm storing one bit per hidden field. 

I would like to optimize this and use a little less
space. If I know I need less than 32 elements in my
boolean (bit) array, I can just use an integer in a
single hidden field.

What if I need more than 32 elements in my bit array?
I suppose I could use the first hidden field for the
first 32 elements of my array and the next 32 elements
are stored in the next hidden field. Uggghhh... Is
there an easier way?

Sieg

__
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway 
http://promotions.yahoo.com/design_giveaway/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Passing arrays by reference

2004-04-01 Thread Richard Heintze
I'm trying to index into some function parameters that
are passed as array references.

Is strategy #1 (see below) identical to strategy #2? I
thought so. I had a bug I that I fixed  by recoding
strategy #1 as strategy #2 and it fixed the problem.

This leads me to believe they are not identical. What
is the difference?

  Thanks,
   Siegfried

sub f {
  my ($y) = @_;

  # strategy #1
  print $$y[0];

  # strategy #2
  print $y-[0];
}
my @x = (1,3,3,45);
f([EMAIL PROTECTED]);

__
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway 
http://promotions.yahoo.com/design_giveaway/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




How to undine a value

2004-04-01 Thread Richard Heintze
I find I'm undefining variables my assigning an
unitialized variable to defined value to make it
undefined (as exemplified below).

Is there a better way to do this?

my $k;
for($i = 0; $i  $c; $i++){
  if ( defined $k ){
  print $x[$k];
  my $t; # intentionally undefined
  $k = $t; # undefine $k
   } else {
  $k = $i;
   } 
} 

__
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway 
http://promotions.yahoo.com/design_giveaway/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How to undine a value

2004-04-01 Thread Randy W. Sims
On 4/1/2004 11:46 PM, Richard Heintze wrote:

I find I'm undefining variables my assigning an
unitialized variable to defined value to make it
undefined (as exemplified below).
Is there a better way to do this?

my $k;
for($i = 0; $i  $c; $i++){
  if ( defined $k ){
  print $x[$k];
  my $t; # intentionally undefined
  $k = $t; # undefine $k
   } else {
  $k = $i;
   } 
} 
undef $k;

see 'perldoc -f undef'

Regards,
Randy.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Passing arrays by reference

2004-04-01 Thread Randy W. Sims
On 4/1/2004 11:39 PM, Richard Heintze wrote:

I'm trying to index into some function parameters that
are passed as array references.
Is strategy #1 (see below) identical to strategy #2? I
thought so. I had a bug I that I fixed  by recoding
strategy #1 as strategy #2 and it fixed the problem.
This leads me to believe they are not identical. What
is the difference?
  Thanks,
   Siegfried
sub f {
  my ($y) = @_;
  # strategy #1
  print $$y[0];
  # strategy #2
  print $y-[0];
}
my @x = (1,3,3,45);
f([EMAIL PROTECTED]);
What problem? I get the result:

= 11

which is what I expect. Both statements are equivalent.

Randy.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: How to undine a value

2004-04-01 Thread WC -Sx- Jones
Richard Heintze wrote:
  my $t; # intentionally undefined
  $k = $t; # undefine $k


Just for clarity -

This isn't undefining it is
assignment of nothing to $k;
my $nothing;

print \n\$nothing\'s Value: $nothing and
\$nothing\'s length . length $nothing;
my $somthing = 100;

$somthing = $nothing;

print \n\$somthing\'s Value: $somthing and
\$somthing\'s length . length $somthing;
-Sx-

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: BitVector in GET/POST Params

2004-04-01 Thread WC -Sx- Jones
Richard Heintze wrote:

What if I need more than 32 elements in my bit array?
I suppose I could use the first hidden field for the
first 32 elements of my array and the next 32 elements
are stored in the next hidden field. Uggghhh... Is
there an easier way?
You must not read the regular beginners list?

Lucky you  :) Store it in as many 32 bit numbers
as required and use pack/unpack -
#! /usr/bin/perl
use strict;
use warnings;
my $count;
my $index;
my $str;
while (++$index) {
  $count = $index;
  while(1) {
(++$count) ? $count += $count--
   : $count += $count++;
$str = unpack(B32, pack(N, $count));
print $count \tis binary $str\n;
last if $count  60_000;
sleep 1;
  }
exit if $index  255;
}
__END__
-Sx-
PS - Incase you missed the joke -
the ONLY relevant part of this
answer is -
$str = unpack(B32, pack(N, $count));

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: BitVector in GET/POST Params

2004-04-01 Thread Richard Heintze
Let me rephrase that question:
Is there a way I can store large integers ( 2**32) as
character strings in radix 10 or radix 16 and covert
these strings to and from bitvectors from which I can
insert and extract individual bits?

I think bitvector is the name of the module. I did a
search on CPAN and looked thru my perldoc but could
not find it. What is the name of feature for storing
large boolean arrays?

  Thanks,
 Siegfried


--- WC -Sx- Jones [EMAIL PROTECTED] wrote:
 Richard Heintze wrote:
 
  What if I need more than 32 elements in my bit
 array?
  I suppose I could use the first hidden field for
 the
  first 32 elements of my array and the next 32
 elements
  are stored in the next hidden field. Uggghhh... Is
  there an easier way?
 
 You must not read the regular beginners list?
 
 Lucky you  :) Store it in as many 32 bit numbers
 as required and use pack/unpack -
 
 #! /usr/bin/perl
 use strict;
 use warnings;
 
 my $count;
 my $index;
 my $str;
 
 while (++$index) {
$count = $index;
 
while(1) {
  (++$count) ? $count += $count--
 : $count += $count++;
 
  $str = unpack(B32, pack(N, $count));
  print $count \tis binary $str\n;
  last if $count  60_000;
  sleep 1;
}
 
 exit if $index  255;
 }
 
 __END__
 -Sx-
 
 PS - Incase you missed the joke -
 the ONLY relevant part of this
 answer is -
 
 $str = unpack(B32, pack(N, $count));
 
 -- 
 To unsubscribe, e-mail:
 [EMAIL PROTECTED]
 For additional commands, e-mail:
 [EMAIL PROTECTED]
 http://learn.perl.org/
 http://learn.perl.org/first-response
 
 


__
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway 
http://promotions.yahoo.com/design_giveaway/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: BitVector in GET/POST Params

2004-04-01 Thread WC -Sx- Jones
Randy W. Sims wrote:
maybe 'perldoc -f vec', 'perldoc -f pack',
also http://search.cpan.org/search?query=bit
I was only suggesting:

man perlpacktut
-Sx-
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



@ in a string

2004-04-01 Thread John
I realised that the @ cannot enter in a string without escape characters. Is that 
equivalent to 

Thanks
John

Re: How to determine if STDIN has piped data?

2004-04-01 Thread Robin Sheat
On Wed, Mar 31, 2004 at 11:58:58PM -0700, Bryan Harris wrote:
 =)  I was referring to a socket.  I couldn't think of any place where I
 might need to use one.
As an example, I have a neural network system I made in Java. It accepts 
commands over a network socket. I then have a Perl program connect and 
control it over the socket. This means that I can have the program 
doing the hard work (the Java bit) on a remote computer, have the one I 
am using connect to it and tell it what to do. (This also means I can 
have one program controlling many instances of the java bit, which is 
why I did it like this). This is a place where sockets are useful. In 
general, they are used to allow communication between to programs. MySQL 
has a socket that clients connect to to use the database. X has a socket 
that X programs connect to to draw windows, and so on.

-- 
Robin [EMAIL PROTECTED] JabberID: [EMAIL PROTECTED]

Hostes alienigeni me abduxerunt. Qui annus est?

PGP Key 0x776DB663 Fingerprint=DD10 5C62 1E29 A385 9866 0853 CD38 E07A 776D B663


pgp0.pgp
Description: PGP signature


Re: @ in a string

2004-04-01 Thread Randy W. Sims
John wrote:
I realised that the @ cannot enter in a string without escape characters. Is that equivalent to 
That's not quite true. Within double quotes, anything that looks like a 
variable is interpreted as a variable. So, 'print @' is perfectly 
fine. It does not look like a variable because '@' is not followed by a 
valid variable name. But in 'print @at', the '@' is interpreted as 
part of the variable '@at'. You can use a backslash ('print [EMAIL PROTECTED]') to 
escape or use single quotes ('print '@at'') to prevent the interpolation.

Regards,
Randy.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



directory operations

2004-04-01 Thread MuthuKumar
Hello All,

I have a directory which contains several files.. like .txt .html .js
files like that.
I have to search a pattern in all files.. if it is available then replace it
and else leave it out.

I have made it for single file.. what i want is to implement for the full
directory..

my @file_list = /*.txt/
foreach $file (@file_list){
file loop
snip.
close(file-handle);
}

I have checked like this.. i did not get any response at all..
No files are stored in the array too. what is wrong with this.. and how to
accomplish this.


--
Regards,
Muthukumar.





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How to determine if STDIN has piped data?

2004-04-01 Thread Morten Liebach
On 2004-03-30 21:35:21 -0700, Bryan Harris wrote:
 
 
  On Mon, 29 Mar 2004 00:38:50 -0700
  Bryan Harris [EMAIL PROTECTED] wrote:
  
  Alternatively, you can use the '-t' operator:
  
  exit 0 if -t STDIN
  
  
  I've been waiting for this for a LONG time, thanks Smoot.
  
  No problem.  It took me a while to find the correct operator as well.
  
  Please keep in mind that doing this breaks the de facto Unix standard
  for filters.  A simply command which is a filter (e.g takes
  input from STDIN and sends output to STDOUT) is written without any
  consideration whether the input is a terminal, pipe, socket or
  otherwise. This makes it very simple to use the command in a pipeline or
  standalone from the terminal.
 
 [stuff cut out]
 
 Smoot,
 
 Strangely, I find that we almost always want our scripts to act this way.
 If any files or data is passed to the script, then it uses it.  Otherwise,
 it prints usage instructions (since we'd rather not have man pages for
 scripts, and I don't know how to build them anyway).

Use POD.  See 'perldoc perlpod' for all the details.

Then the user can just run 'perldoc scriptname' (provided 'scriptname'
is in $PATH) and get a nicely formatted manpage.

Have a nice day
 Morten

-- 
http://m.mongers.org/ -- http://zentience.mongers.org/
__END__

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: directory operations

2004-04-01 Thread Flemming Greve Skovengaard
MuthuKumar wrote:
Hello All,

I have a directory which contains several files.. like .txt .html .js
files like that.
I have to search a pattern in all files.. if it is available then replace it
and else leave it out.
I have made it for single file.. what i want is to implement for the full
directory..
my @file_list = /*.txt/
foreach $file (@file_list){
file loop
snip.
close(file-handle);
}
I have checked like this.. i did not get any response at all..
No files are stored in the array too. what is wrong with this.. and how to
accomplish this.
--
Regards,
Muthukumar.




You need to change the line:
my @file_list = /*.txt/
to
my @file_list = *.txt
or
my @file_list = glob *.txt
--
Flemming Greve Skovengaard   FAITH, n.
a.k.a Greven, TuxPower   Belief without evidence in what is told
[EMAIL PROTECTED]  by one who speaks without knowledge,
4168.08 BogoMIPS of things without parallel.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



help in find and replacing a string in a number of files

2004-04-01 Thread prabu
Hi,
 i am new to perl.I am in a problem,So please help me to get a solution
I want to change texts in 172 files available at a directory
/pages(there are files also in a sub-directory),they all  are text files.
 There are also some text files,which I no need to change.I want one
single script to open all these files,match the particular
 string and replace them with new string.

I tried with a singel file,able to open that file,make changes ,but only
write in another file.I want to write the changes in same old file.


the string needed to find:

td bgcolor=#336699 valign=top width=10img src=a web link here
images/corner_2.gif width=10 height=10/td


the string to be replaced is;

td bgcolor=#336699 valign=top width=10
  script
document.write(img src= + url + /images/corner_2.gif width='10'
height='10'/td);
  /script
Can anyone help me in this,
With Thanks in advance,
prabu.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.620 / Virus Database: 399 - Release Date: 3/11/2004




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How Random is Random?

2004-04-01 Thread Phil Schaechter
 You will note that the documentation says apparently random order.  In
 more recent versions of Perl (IIRC starting at 5.8.1) randomness was
 added to hash keys for security reasons.  In previous versions the order
 of the hash keys was determined by the hash function used which appeared
 random because it was not the same order that the keys were entered.
 As to your question, if the hash keys remain the same then the order
 will remain the same.  However, if you add or delete keys then the order
 may change.

Thanks for the information John.  Will the order only change if I add or 
delete keys?  Or if I am modifying large numbers of keys?  I'm using 5.8.3, 
and probably will always be adding/removing keys, so I think it's probably ok 
for my uses.

-Phil

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: directory operations

2004-04-01 Thread Randy W. Sims
MuthuKumar wrote:
Hello All,

I have a directory which contains several files.. like .txt .html .js
files like that.
I have to search a pattern in all files.. if it is available then replace it
and else leave it out.
I have made it for single file.. what i want is to implement for the full
directory..
my @file_list = /*.txt/
foreach $file (@file_list){
file loop
snip.
close(file-handle);
}
I have checked like this.. i did not get any response at all..
No files are stored in the array too. what is wrong with this.. and how to
accomplish this.
my @file_list = *.txt;

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Strings with extended characters

2004-04-01 Thread Jimstone77

Is there a simple way to reject any string that has extended characters in 
it? In other words, only accept the 88 (I think it's 88) regular keyboard 
characters and numbers. I can't find a simple way to do this.


Check if another script running

2004-04-01 Thread Mike Blezien
Hello,

I need to setup a cronjob to run a script every 2hrs, but if another particular
script(executed via a standard web form), on the same machine, is being
executed, I want the cron script wait or sleep(); till the other script is
finished.
Is this possible to do and how is the best way to accomplish this task. :)

TIA
--
MikemickaloBlezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
http://www.thunder-rain.com
Quality Web Hosting
http://www.justlightening.net
MSN: [EMAIL PROTECTED]
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



using strict

2004-04-01 Thread DBSMITH
People of the Perl, 

from my understanding strict disallows soft references, ensures that all 
variables are declared before usage and disallows barewords except for 
subroutines.

what is a soft reference?
what is a bareword?
why is strict disallowing a compile here When I comment out strict the 
syntax checks outs as ok!???
how do I display each element # with its corresponding data line, b/c I 
only want certain elements printed out?

thank you!

# Set pragma

use strict;

tsm_critical_servers;

# Declare sub

sub tsm_critical_servers {

my $crout=/tmp/critical_servers.out;

# Make system call for data gathering 

system (dsmadmc -id=menu -password=xx 'q event * * 
begind=-1 begint=15:30 endd=today endtime=now'  $crout);
 
# Create array and read in each line as a seperate element
 
open (CRITICALSERVERS, $crout) || die can't open file \n: $!;
while ( defined($line = CRITICALSERVERS) ) {
chomp ($line);
my @tsm = CRITICALSERVERS;
foreach $_ (@tsm) {
print $_;
}
}
close (CRITICALSERVERS);
}


Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams



Need some guidance

2004-04-01 Thread Najamuddin, Junaid
Thanks in advance.

Being a novice to Perl trying to write a perl script at my work in
windows environment.
I have couple of machines on Microsoft network load balancing (wlbs)
And one url is being used to access those machines.
Want to ping individual urls related to each machine on the cluster.
And if a ping to a particular machine fails then want to initiate a
command to that machine to shut down the network load balancer and send
email/page to networkadmin so that users are not affected while
accessing the url.
I have planned to ping every 5 minutes.
May be some of you already using a similar script.

All help will be appreciated:)
Thanks again
Junaid 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: using strict

2004-04-01 Thread Guay Jean-Sébastien
Hello Derek,

When using strict, the error message should point you to the line where the
error is. It's usually pretty darn good at pointing the right line. In this
case, I bet it's this one:

while ( defined($line = CRITICALSERVERS) ) {

There is no declaration of the $line variable. Try declaring it first, like
this:

my $line;
while ( defined($line = CRITICALSERVERS) ) {

I think that's the only variable that wasn't declared. If you get any more
error messages, you can check them out and figure out what's wrong.

Just a suggestion: You should use or instead of || when checking if a file
opened correctly, because if you ever want to do some operations on the
right side, or will bind less tightly and allow your operations to work
correctly without needing parentheses to fix the precedence.

By the way, why are you reading one line in the while's parentheses, and and
then slurping the rest of the file into an array inside the while? That
means your while will only be run once, because at the next iteration you'll
already be at the end of the file... Just use $line inside the while, and
you'll read one line at a time. 

You also chomped your line, which is good. Just remember to re-add the line
ending (\n) when printing the lines as you're doing, or else all the lines
will be printed on a single, very long line.

I'll let the experts explain what soft references and barewords are. I've
never used either, as I come from the relatively new school of programming.
As I understand, they are features of the language that are dangerous to use
in some contexts, so use strict disallows them knowing that if you really
want to use them, you'll disable strict for the block of code where you use
it, and then re-enable it.

Hope this helps,


Jean-Sébastien Guay

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Check if another script running

2004-04-01 Thread Mike Blezien
Hello,

I need to setup a cronjob to run a script every 2hrs, but if another particular 
script(executed via a standard web form), on the same machine, is being 
executed, I want the cron script wait or sleep(); till the other script is 
finished.

Is this possible to do and how is the best way to accomplish this task. :)

TIA
--
MikemickaloBlezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
http://www.thunder-rain.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



RE: Check if another script running

2004-04-01 Thread Jayakumar Rajagopal
I think your question is more related to unix than perl.
Try something like this in shell script :
program=$0
while ps -ef | grep $0 | grep -v grep | grep $$
do 
   sleep 10
done

or in perl

$program=$0;
while (  `ps -ef | grep $0 | grep -v grep | grep $$` ) {
 sleep 10 ;
}

** I did not check the stuff... ***

Jay

-Original Message-
From: Mike Blezien [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 01, 2004 3:47 PM
To: Perl List
Subject: Check if another script running


Hello,

I need to setup a cronjob to run a script every 2hrs, but if another particular
script(executed via a standard web form), on the same machine, is being
executed, I want the cron script wait or sleep(); till the other script is
finished.

Is this possible to do and how is the best way to accomplish this task. :)

TIA
-- 
MikemickaloBlezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
http://www.thunder-rain.com
Quality Web Hosting
http://www.justlightening.net
MSN: [EMAIL PROTECTED]
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Check if another script running

2004-04-01 Thread Mike Blezien
Hi Randy,

that was my original plan, but I though there maybe a better way others may use 
or suggest :)

Appreciate the feedback,

Mike

Randy W. Sims wrote:
On 4/1/2004 3:46 PM, Mike Blezien wrote:

Hello,

I need to setup a cronjob to run a script every 2hrs, but if another 
particular
script(executed via a standard web form), on the same machine, is being
executed, I want the cron script wait or sleep(); till the other 
script is
finished.

Is this possible to do and how is the best way to accomplish this 
task. :)


If you are able to modify both scripts, the traditional solution would 
be to have the cgi script create a lock file on startup, removing it 
when exiting. Then your other script can check for the presence of the 
lock file, if it exists, wait.

Regards,
Randy.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



RE: help in find and replacing a string in a number of files

2004-04-01 Thread Charles K. Clarkson
prabu [EMAIL PROTECTED] wrote:
: 
:  i am new to perl.I am in a problem,So please help me to 
: get a solution
: I want to change texts in 172 files available at a directory
: /pages(there are files also in a sub-directory),they all  are 
: text files.
:  There are also some text files,which I no need to 
: change.I want one
: single script to open all these files,match the particular
:  string and replace them with new string.

Read the file 'perlrun' included in your perl distribution.
The section under the -i option gives examples of how to do this.

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: using strict

2004-04-01 Thread Daniel Staal
--As of Thursday, April 1, 2004 5:01 PM -0500, [EMAIL PROTECTED] is 
alleged to have said:


what is a soft reference?
what is a bareword?
why is strict disallowing a compile here When I comment out strict
the  syntax checks outs as ok!???
how do I display each element # with its corresponding data line, b/c I
only want certain elements printed out?
I'll leave these to some Guru who knows what he is talking about, but I 
think I can say why strict is disallowing a compile...

thank you!

# Set pragma

use strict;
use warnings;   #It just makes things easier...
   #Use always, or nearly.
use diagnostics;#It answers questions...
   #Use until comfortable that you know
   #what it will tell you.
tsm_critical_servers;

# Declare sub

sub tsm_critical_servers {

my $crout=/tmp/critical_servers.out;

# Make system call for data gathering

system (dsmadmc -id=menu -password=xx 'q event * *
begind=-1 begint=15:30 endd=today endtime=now'  $crout);
# Create array and read in each line as a seperate element

open (CRITICALSERVERS, $crout) || die can't open file \n: $!;
while ( defined($line = CRITICALSERVERS) ) {
Right here.  You've never told the compiler what $line is before.  'strict' 
doesn't like that, though it is technically legal Perl.

Make that:
 my $line;
 while ( defined($line = CRITICALSERVERS) ) {
chomp ($line);
my @tsm = CRITICALSERVERS;
foreach $_ (@tsm) {
print $_;
}
}
close (CRITICALSERVERS);
}
I think that will get you going.

Daniel T. Staal

---
This email copyright the author.  Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes.  This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



RE: Check if another script running

2004-04-01 Thread Jayakumar Rajagopal
sorry.. I missed one thing..
This is the right condition line:
ps -ef | grep $0 | grep -v $$ | grep -v grep | grep $0

-Original Message-
From: Jayakumar Rajagopal 
Sent: Thursday, April 01, 2004 5:30 PM
To: [EMAIL PROTECTED]; Perl List
Subject: RE: Check if another script running


I think your question is more related to unix than perl.
Try something like this in shell script :
program=$0
while ps -ef | grep $0 | grep -v grep | grep $$
do 
   sleep 10
done

or in perl

$program=$0;
while (  `ps -ef | grep $0 | grep -v grep | grep $$` ) {
 sleep 10 ;
}

** I did not check the stuff... ***

Jay

-Original Message-
From: Mike Blezien [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 01, 2004 3:47 PM
To: Perl List
Subject: Check if another script running


Hello,

I need to setup a cronjob to run a script every 2hrs, but if another particular
script(executed via a standard web form), on the same machine, is being
executed, I want the cron script wait or sleep(); till the other script is
finished.

Is this possible to do and how is the best way to accomplish this task. :)

TIA
-- 
MikemickaloBlezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
http://www.thunder-rain.com
Quality Web Hosting
http://www.justlightening.net
MSN: [EMAIL PROTECTED]
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Check if another script running

2004-04-01 Thread Randy W. Sims
On 4/1/2004 3:46 PM, Mike Blezien wrote:

Hello,

I need to setup a cronjob to run a script every 2hrs, but if another 
particular
script(executed via a standard web form), on the same machine, is being
executed, I want the cron script wait or sleep(); till the other 
script is
finished.

Is this possible to do and how is the best way to accomplish this task. :)
If you are able to modify both scripts, the traditional solution would 
be to have the cgi script create a lock file on startup, removing it 
when exiting. Then your other script can check for the presence of the 
lock file, if it exists, wait.

Regards,
Randy.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Strings with extended characters

2004-04-01 Thread Daniel Staal
--As of Thursday, April 1, 2004 9:58 AM -0500, [EMAIL PROTECTED] is 
alleged to have said:

Is there a simple way to reject any string that has extended characters
in  it? In other words, only accept the 88 (I think it's 88) regular
keyboard  characters and numbers. I can't find a simple way to do this.
--As for the rest, it is mine.

I'm sure there is a smart way, but here's a dumb idea:

my @characters = unpack('U*', $string);
for @characters {
   if $_  $max_Char_Value {
   # Do something
   } else
   # Do something else.
   }
}
Daniel T. Staal

---
This email copyright the author.  Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes.  This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



RE: Strings with extended characters

2004-04-01 Thread Jayakumar Rajagopal
Jim
Please send two sample strings one that contains 'reject'able stuff, and other with 
those 88. That would clarify us better.
Jay
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 01, 2004 9:58 AM
To: [EMAIL PROTECTED]
Subject: Strings with extended characters



Is there a simple way to reject any string that has extended characters in 
it? In other words, only accept the 88 (I think it's 88) regular keyboard 
characters and numbers. I can't find a simple way to do this.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Hash ref's of hash's

2004-04-01 Thread mgoland

Hi all,
 I am trying to setup a hash who's values are referance to hash's. Data structure 
should look like this

hash
 1:
   setting 1
   setting 2
 2:
   setting 1
   setting 2


  I would think it can be accomplished with following code, but when I try to print it 
out it only prints the last setting which it read. Any idea's ??

CODE:
#!perl -w
use strict;
open RD, input.txt;

my ( $field,$portsetting, $value, $port, $portnum, %digi, $debug );
$debug=0;

 while ( RD ) {
 if(m/^(port)\s\=\s(.*)$/i){$portnum=$2;$portnum++}

 $field = {};
 $digi{$portnum} = $field;

m/^(.*)\s\=\s(.*)$/;
$portsetting=$1;
$value=$2;
$field-{$portsetting}=$value;

print setting $portsetting - $digi{$portnum}{$portsetting}\n if $debug;

if($portsetting eq 'porttitle'){
$value =~ tr /-/ /;
$value =~ m/^(\w+)\s+(\w+)/i;
$field-{$portsetting}=$1;
$field-{'type'}=$2;
print 1:$digi{$portnum}{$portsetting}\t2:$digi{$portnum}{'type'}\n if $debug;
}

 }


# print the whole thing
 foreach $port ( keys %digi ) {
 print $port: { ;
 for $field ( keys %{ $digi{$port} } ) {
 print $field=$digi{$port}{$field} ;
 }
 print }\n;
 }

Sample DATA

port = 0
bmanset = 0
benable = 1
uarttype = 0
baudrate = 9600
stopbits = 1
databits = 8
parity = 0
flowcontrol = 0
protocol = 1
port = 1
bmanset = 0
benable = 1
uarttype = 0
baudrate = 9600
stopbits = 1
databits = 8
parity = 0
flowcontrol = 0
protocol = 1


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: using strict

2004-04-01 Thread Randy W. Sims
On 4/1/2004 5:01 PM, [EMAIL PROTECTED] wrote:

People of the Perl, 

from my understanding strict disallows soft references, ensures that all 
variables are declared before usage and disallows barewords except for 
subroutines.

what is a soft reference?
what is a bareword?
why is strict disallowing a compile here When I comment out strict the 
syntax checks outs as ok!???
perldoc strict

answers all of the above questions. Those below have already been answered.

how do I display each element # with its corresponding data line, b/c I 
only want certain elements printed out?

thank you!

# Set pragma

use strict;

tsm_critical_servers;

# Declare sub

sub tsm_critical_servers {

my $crout=/tmp/critical_servers.out;

# Make system call for data gathering 

system (dsmadmc -id=menu -password=xx 'q event * * 
begind=-1 begint=15:30 endd=today endtime=now'  $crout);
 
# Create array and read in each line as a seperate element
 
open (CRITICALSERVERS, $crout) || die can't open file \n: $!;
while ( defined($line = CRITICALSERVERS) ) {
chomp ($line);
my @tsm = CRITICALSERVERS;
foreach $_ (@tsm) {
print $_;
}
}
close (CRITICALSERVERS);
}

Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Timezone conversion

2004-04-01 Thread Distribution Lists

can someone give me ideas of how I could convert this date and time stamp
that is in GMT to Central time ?

2004-04-01-19:15:15.525+00:00

Thanks

-- 




-- 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: using strict

2004-04-01 Thread u235sentinel
Does the following turn off strict for a vars?

no strict vars;

Could you also turn off strict for other things besides vars, refs and subs?  Say for 
a subroutine (for example).

Just curious.  I've run into situations where I've come across badly maintained code 
and would like to do this for pieces instead of the whole deal.

Thx
 On 4/1/2004 5:01 PM, [EMAIL PROTECTED] wrote:
 
  People of the Perl, 
  
  from my understanding strict disallows soft references, ensures that all 
  variables are declared before usage and disallows barewords except for 
  subroutines.
  
  what is a soft reference?
  what is a bareword?
  why is strict disallowing a compile here When I comment out strict the 
  syntax checks outs as ok!???
 
 perldoc strict
 
 answers all of the above questions. Those below have already been answered.
 
  how do I display each element # with its corresponding data line, b/c I 
  only want certain elements printed out?
  
  thank you!
  
  # Set pragma
  
  use strict;
  
  tsm_critical_servers;
  
  # Declare sub
  
  sub tsm_critical_servers {
  
  my $crout=/tmp/critical_servers.out;
  
  # Make system call for data gathering 
  
  system (dsmadmc -id=menu -password=xx 'q event * * 
  begind=-1 begint=15:30 endd=today endtime=now'  $crout);
   

  # Create array and read in each line as a seperate element
   
  open (CRITICALSERVERS, $crout) || die can't open file \n: $!;
  while ( defined($line = CRITICALSERVERS) ) {
  chomp ($line);
  my @tsm = CRITICALSERVERS;
  foreach $_ (@tsm) {
  print $_;
  }
  }
  close (CRITICALSERVERS);
  }
  
  
  Derek B. Smith
  OhioHealth IT
  UNIX / TSM / EDM Teams
  
  
 
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Can anyone help

2004-04-01 Thread Doug Guilding
I am trying to get perl scripts working on a win2k server - does anyone have
any good ideas.
 
My ISP say that they cannot support the use of web scripts However they
have told me the path to perl and sendmail.
 
/usr/bin/perl
/usr/sbin/sendmail
 
The problem is I can't get anything to work. I've downloaded perl and can
run scripts locally, but online is another story.
 
Do I need to create a CGI-BIN of my own, or do ISPs generally have a
communal one? If I need to create one, does it need to be within my site, or
on my top level (as the html files are obviously not in the top level of my
webspace.
 
please someone help
 
Yours
 
Lost and confused
 
Doug Guilding


Check if another script running

2004-04-01 Thread Mike Blezien
Hello,

I need to setup a cronjob to run a script every 2hrs, but if another particular
script(executed via a standard web form), on the same machine, is being
executed, I want the cron script wait or sleep(); till the other script is
finished.
Is this possible to do and how is the best way to accomplish this task. :)

TIA
--
MikemickaloBlezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
http://www.thunder-rain.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: using strict

2004-04-01 Thread WilliamGunther

In a message dated 4/1/2004 5:03:40 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
People of the Perl, 

from my understanding strict disallows soft references, ensures that all 
variables are declared before usage and disallows barewords except for 
subroutines.

what is a soft reference?

A soft reference is a symbolic reference. For example:
$hello = Hey, what's up?;
$var = hello;
print $$var; #or, if it helps you see it better 'print ${$var}'

This may be what you want, but may not be (usually you want hard references), 
hence use strict 'refs'

what is a bareword?

A bareword is...a bare...word? Really its just a word not expicitly denoted 
to be something. For example:

sub foo { 1 }

foo;

foo is a barewords. In the above case, strict doesn't freak out because the 
subroutine is predeclared. But if you just throw around words whenever you 
want, it will freak out. For example,
@array = (String, String, String, String);

String is a bareword. strict will throw up an exception so fast. 

2 exceptions to the bareword throw-up: left side of '=' and inside curly 
braces. For Example: 

%hash = (
left = 'right'
)
print $hash{left};




why is strict disallowing a compile here When I comment out strict the 
syntax checks outs as ok!???
how do I display each element # with its corresponding data line, b/c I 
only want certain elements printed out?

People already answered these. On an aside, Your code may compile dandy, 
that's not what strict is for. If perl could catch the errors like the ones you 
stated, there would be no need for strict. Strict is basically just so you don't 
screw up. You don't want barewords because you might think it means something 
else. You don't want soft references when you think you're using hard 
references. You don't want your code to screw up and you not to know why cause you 
used $var on 10,000 of the 20,000 lines and $Var on the other 10,000.

-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier


Re: Check if another script running

2004-04-01 Thread Smoot Carl-Mitchell
On Thu, 01 Apr 2004 16:34:11 -0600
Mike Blezien [EMAIL PROTECTED] wrote:

 that was my original plan, but I though there maybe a better way
 others may use or suggest :)
 
 Appreciate the feedback,

If you are running this on a Unix/Linux system check out perldoc -f
flock. It enables advisory file locking. It avoids the complexity of
doing file locking by creating sentinel files using the standard Unix
atomic open semantics.  There are some serious race condition problems
with that approach.

The information in the perl manual for flock contains an example mailbox
locking routine which explains how to use flock to grant exclusive
access to a file.

-- 
Smoot Carl-Mitchell
Systems/Network Architect
email: [EMAIL PROTECTED]
cell: +1 602 421 9005
home: +1 480 922 7313

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: directory operations

2004-04-01 Thread Tim Johnson
If you did want to filter based on a regular expression, you can always do it the long 
way:
 
opendir(DIR,.) || die;
my @file_list = readdir(DIR);
foreach my $file(@file_list){
 if(-f $file  ($file =~ /Place Regex Here/)){
  #do something...
 }
}
 
You get the general idea.  Also, if you want to do a recursive search, look into the 
standard File::Find module.
 

-Original Message- 
From: Randy W. Sims [mailto:[EMAIL PROTECTED] 
Sent: Thu 4/1/2004 2:02 AM 
To: MuthuKumar 
Cc: [EMAIL PROTECTED] 
Subject: Re: directory operations



[snip]



 my @file_list = /*.txt/
 foreach $file (@file_list){
 file loop
 snip.
 close(file-handle);
 }

 I have checked like this.. i did not get any response at all..
 No files are stored in the array too. what is wrong with this.. and how to
 accomplish this.

my @file_list = *.txt;





Re: A long time helper needs help

2004-04-01 Thread William.Ampeh




Wow!

Thanks a lot.  I am going to try to decipher your code and hope you will
not mind me asking questions later.


It's a bit hard to give good suggestions if I do not understand the
data.  Are all the data yearly like the stuff in page6.prn?

The data are bunch of report files, the format of which is a combination of
the report files represented in pages 6 and 7 (copies attached).
So a table will have the following:

- a page number of the form (#   {Release}, {date}).  E.g.: 6
Z.1, March 4, 2004
- 2 title lines
  -- D.1 Debt Growth by Sector
  -- In percent; quarterly figures are seasonally adjusted annual rates
- a variable number of column header (what I call major #1, major #2, major
#3, )
   where major N-1 is a parent of major N (N=2, 3, 4, ..)
   and major N represents an atomic column header A, B, C,  (e.g.,
Total, government, nonfederal .. Corporate)
- data lines (which could either be of the format {date} {value for column
A} {value for column B} 


--

Sample tables
===

6 Z.1, March 4, 2004
_
D.1 Debt Growth by Sector\203^G\202\201\205^K 1
In percent; quarterly figures are seasonally adjusted annual rates
-

   -Domestic nonfinancial
sectors

-Nonfederal
  ---Households
Business
   Federal  Total  HomeConsumer
   Total  government  nonfederal  Total  mortgage   credit
Total  Corporate
_

1969 7.2-1.1 9.77.7   7.0   8.3
11.6   11.4
1970 6.9 4.2 7.64.4   4.4   3.4
10.3   12.9
1971 9.5 8.3 9.89.2   8.5  11.7
10.17.8
197210.0 4.611.4   11.3  11.2  13.1
12.59.9
197310.7 2.012.9   12.4  11.7  13.3
14.7   17.5
1974 9.2 3.410.58.8   9.7   4.6
13.0   11.5
_




Z.1, March 4, 2003
7
_

F.206 Money Market Mutual Fund Shares
Billions of dollars; quarterly figures are seasonally adjusted annual rates
_

  20022003
-2002-  -2003-
   Q3
Q4  Q1
_

 1  FA63405  Net issues   -16.8  -207.8  -124.0
201.5  -394.2 1

 2  FA63405  Net purchases-16.8  -207.8  -124.0
201.5  -394.2 2

 3  FA153034005Household sector   -40.2   -90.282.1
-164.0  -185.3 3
 4  FA103034003Nonfinancial corporate bu   26.9   -52.7   -47.6
163.5   -38.5 4
 5  FA113034003Nonfarm noncorporate busi2.3-8.2-6.6
14.9-5.5 5

 6  FA603034003Bank personal trusts and 1.3-9.2 1.3
1.3-9.2 6
 7  FA543034003Life insurance companies   -13.5-8.3   -55.8
7.4   -28.2 7
 8  FA573034003Private pension funds2.8 2.9 2.8
2.8 2.9 8
 9  FA503034003Funding corporations 3.6   -42.1  -100.3
175.5  -130.3 9
_


__

William Ampeh (x3939)
Federal Reserve Board


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




HOWTO: File Renaming and Directory Recursion

2004-04-01 Thread Morbus Iff

Earlier this morning, a friend of mine asked me for a script that would
given a list of files, replace underscores with spaces, to take this:

  Artist_Name-Track_Name.mp3

and rename it to this:

  Artist Name-Track Name.mp3

The script was mindlessly simple, and I felt it would be a good HOWTO
for the perl beginners crowd, if not to show some good code practices,
but also to counteract the . .. .. . controversial HOWTO that had
been posted a week or so ago. Certainly, if you find this as misguided
as his, complain onlist with better examples, or offlist with anger.

The first bit of code I wrote him was below. Save for
the additional explanatory comments, it's nearly exact.

 #!/usr/bin/perl

 # start all your scripts with these two lines.
 # they are the best teacher you will ever find for
 # writing perl code. they make you smarter, and
 # you'll last longer in bed; no drugs necessary.
 #
 use warnings;
 use strict;

 # he needed the script to read every file in a directory
 # and rename them based on whether they had underscores
 # in the name. to make the script as 'immediately runnable'
 # as possible, I assumed he would be placing the script
 # in the directory full of files, and running it there.
 # as such, we'll be opening the current working directory.
 # if anything goes wrong, we stop processing with the error.
 # ALWAYS CHECK FOR SUCCESS BEFORE CONTINUING.
 #
 opendir(DIR, .) or die $!;

 # next, we load all the files in that directory into
 # an array. at this point, we could also have used the
 # grep() function to filter out entries that weren't
 # relevant, but for readability I chose a more configurable
 # approach (see below).
 #
 my @files = readdir(DIR);
 close(DIR); # implicit.

 # now, we need to loop through all the directory files,
 # stored in @array. we're going to use $_ here, which
 # can be remembered as the thing we want to work with.
 # we could just as easily used an explicit variable name,
 # and in larger scripts, you usually want to.
 #
 while (@files) {

# so, the filename is now stored in $_, and since $_ is
# assumed for a number of Perl's functions, we don't
# have to explicitly mention it in the following filters.
# these filter serve one purpose: make sure we're working
# ONLY with files we should be. these are sanity checks:
# we're ensuring that we're not operating on anything we
# wouldn't. this is good practice: ALWAYS CHECK YOUR SANITY.
# rule out everything you don't want, and focus on everything
# you do. first, we skip directories with the -d check.
# the syntax I'm using below is far more readable than a bunch
# of if/else statements: we're not increasing our indents, and
# we don't have to worry about a zillion open/closing brackets.
# it also reads more like English.
#
next if -d;

# if we're still here, we've got a file. we'll automatically
# skip files that begin with a . as they're usually considered
# special, and renaming them can be a bad thing.
#
next if /^\./;

# and finally, if the file doesn't have any underscores in
# it, we can skip it immediately. again, this is for safety:
# the rest of our code could operate on the file and rename
# it with the same filename, but why waste that processing
# power? it's just dirty. it's how bad things happen.
#
next unless /_/;

# at this point, we're assuming that this is a file
# we're supposed to be working on. so, we copy the file
# name, do our underscore for space conversion, and
# issue a rename() from the original name to the new.
# again, if something goes wrong with the rename, we
# die immediately. this is probably overly cautious.
#
my $new_name = $_;
$new_name=~ s/_/ /g;
rename($_, $new_name) or die $!;
 }

And that's the script. For readability, no comments:

 #!/usr/bin/perl
 use warnings;
 use strict;

 opendir(DIR, .) or die $!;
 my @files = readdir(DIR);
 close(DIR);

 while (@files) {
next if -d;
next if /^\./;
next unless /_/;

my $new_name = $_;
$new_name=~ s/_/ /g;
rename($_, $new_name) or die $!;
 }

It worked fine for him, and we moved on. A few hours later, he
asked for a recursive version, and whether that would be hard
to do. While I wasn't around to help him out, the weak solution
was easy: just move the script into each new directory and run
it again. But, there are two other solutions to this new request:
the bad one, and the good one.

The bad one is to assume the first script is perfect: it's not.
It works if you're in the current directory, and the assumptions
are that no recursion is necessary. A bad approach to the recursive
problem is to start modifying the above script to manually support
it: people think hey, I got this working, recursion must be
simple as pie, right?!. Usually, they'll end up with something
like (pseudo non-working code follows):

 my DIRECTORIES = start_directory

 

Re: Strings with extended characters

2004-04-01 Thread JupiterHost.Net


[EMAIL PROTECTED] wrote:

Is there a simple way to reject any string that has extended characters in 
it? In other words, only accept the 88 (I think it's 88) regular keyboard 
characters and numbers. I can't find a simple way to do this.

Does this help?
 if($string !~ m/^\w+$/) { die I hate extended characters; }
Of course \w+ is letters , numbers, and underscores only, you will need 
to add any other characters you want tot he regex but that should get 
you started eh?

Lee.M - JupiterHost.Net

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: HOWTO: File Renaming and Directory Recursion

2004-04-01 Thread Paul Johnson
On Thu, Apr 01, 2004 at 07:05:51PM -0500, Morbus Iff wrote:

 Earlier this morning, a friend of mine asked me for a script that would
 given a list of files, replace underscores with spaces, to take this:
 
   Artist_Name-Track_Name.mp3
 
 and rename it to this:
 
   Artist Name-Track Name.mp3
 
 The script was mindlessly simple, and I felt it would be a good HOWTO
 for the perl beginners crowd, if not to show some good code practices,
 but also to counteract the . .. .. . controversial HOWTO that had
 been posted a week or so ago. Certainly, if you find this as misguided
 as his, complain onlist with better examples, or offlist with anger.
 
 The first bit of code I wrote him was below. Save for
 the additional explanatory comments, it's nearly exact.

[ snip ]

 And that's the script. For readability, no comments:
 
  #!/usr/bin/perl
  use warnings;
  use strict;
 
  opendir(DIR, .) or die $!;
  my @files = readdir(DIR);
  close(DIR);
 
  while (@files) {

Are you sure that's not:

   for (@files) {

?

 next if -d;
 next if /^\./;
 next unless /_/;
 
 my $new_name = $_;
 $new_name=~ s/_/ /g;
 rename($_, $new_name) or die $!;
  }
 
 It worked fine for him, and we moved on. A few hours later, he
 asked for a recursive version, and whether that would be hard
 to do. While I wasn't around to help him out, the weak solution
 was easy: just move the script into each new directory and run
 it again. But, there are two other solutions to this new request:
 the bad one, and the good one.

Here's a third:

  $ rename 'y/_/ /' **/*(.)

That's zsh globbing and rename that used to come with perl.  rename is
now part of debian, and google tells me it can be found at:

  http://www.hurontel.on.ca/~barryp/menu-mysql/music_rename-1.12c/rename

Though I'll admit that that solution doesn't provide so many
opportunities for learning Perl.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: HOWTO: File Renaming and Directory Recursion

2004-04-01 Thread Randy W. Sims
On 4/1/2004 7:05 PM, Morbus Iff wrote:

 # and here is that subroutine. it's nearly exactly
 # the same as our previous code, only this time, we
 # move into the directory that contains a file to
 # be renamed. this is actually a quick hack because
 # I knew this wouldn't be production-code: a more proper
 # solution would be to stay where we are in the directory
 # structure, and give full paths to our rename(). this
 # would require the help of another module, File::Spec.
 # find out more with perldoc File::Spec. it's handy.
 #
 sub underscores {
next if -d $_;
next if /^\./;
next unless /_/;
my $new_name = $_;
$new_name=~ s/_/ /g;
chdir($File::Find::dir);
rename($_, $new_name) or die $!;
 }
Nice work. Just two quick comments. 1) Above, the chdir is not neccesary 
because File::Find moves through the directory structure unless you 
specify no_chdir(?). 2) It might be instructive to follow up with one 
that handles the directory as a parameter; I agree it would have been 
distracting here, but as a follow-up it would be a good how-to for a 
common task (incl usage  pod also).

Again, this is a great example of a good How-To.

Regards,
Randy.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Can anyone help

2004-04-01 Thread Wiggins d'Anconia
Doug Guilding wrote:
I am trying to get perl scripts working on a win2k server - does anyone have
any good ideas.
 
My ISP say that they cannot support the use of web scripts However they
have told me the path to perl and sendmail.
 
/usr/bin/perl
/usr/sbin/sendmail
 
The problem is I can't get anything to work. I've downloaded perl and can
run scripts locally, but online is another story.
 
Do I need to create a CGI-BIN of my own, or do ISPs generally have a
communal one? If I need to create one, does it need to be within my site, or
on my top level (as the html files are obviously not in the top level of my
webspace.
 
In general this is handled in a couple of ways, a) with a cgi-bin that 
is pre-configured in the web server.  Within this 'bin' a file will be 
executed whenever it is requested.  Generally this is handled on a per 
account or even per domain basis, *if* it is enabled at all.  Most 
providers wouldn't use a communal cgi-bin these days.  or b) All of the 
directories under an account that are accessible have the option of 
having executable files, generally this is considered a bad idea and not 
provided.  Simply because Perl and sendmail are installed does not mean 
you will have privilege to run scripts over HTTP, and this may be what 
your ISP is telling you when they say they cannot support the use of 
web scripts. Otherwise I would imagine they have documented what their 
options are, you should check their online documentation.  In the case 
that neither is true, you may want to consider a new ISP.

http://danconia.org

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: HOWTO: File Renaming and Directory Recursion

2004-04-01 Thread Morbus Iff
  while (@files) {

Are you sure that's not:

   for (@files) {

Yup, for is right. An error in my memory recall.

-- 
Morbus Iff ( evil is my sour flavor )
Technical: http://www.oreillynet.com/pub/au/779
Culture: http://www.disobey.com/ and http://www.gamegrene.com/
icq: 2927491 / aim: akaMorbus / yahoo: morbus_iff / jabber.org: morbus

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Hash ref's of hash's

2004-04-01 Thread Wiggins d'Anconia
[EMAIL PROTECTED] wrote:
Hi all,
 I am trying to setup a hash who's values are referance to hash's. Data structure 
should look like this
hash
 1:
   setting 1
   setting 2
 2:
   setting 1
   setting 2

This does not look like a HoH, but a HoA.

  I would think it can be accomplished with following code, but when I try to print it out it only prints the last setting which it read. Any idea's ??

CODE:
#!perl -w
use strict;
open RD, input.txt;
Always check that open succeeded.

open RD, input.txt or die Can't open file: $!;

my ( $field,$portsetting, $value, $port, $portnum, %digi, $debug );
$debug=0;
Declaring all of your variables up front reduces the help that 'strict' 
can provide and generally leads to more problems.  It may be that $field 
is getting reused because even though you are emptying it, this isn't 
clear to me.

 while ( RD ) {
Let's dispense with $_ it adds confusion when we should be trying to be 
explicit. Once you don't have to ask questions about references then 
consider going back to it.

while (my $line = RD) {

 if(m/^(port)\s\=\s(.*)$/i){$portnum=$2;$portnum++}

Whitespace is our friend, why are we capturing a constant?

if ($line =~ m/^port\s=\s(.*)$/i) {
   $portnum = $1;
}
 $field = {};
 $digi{$portnum} = $field;
Double assignment?

m/^(.*)\s\=\s(.*)$/;
If we are going to capture we should double check that the string is 
formatted properly, put this into an if.

if ($line =~ m/^(.*)\s=\s(.*)$/) {

There's no real need for the temp variables but if you want them that is 
fine for readability.

$portsetting=$1;
$value=$2;
$field-{$portsetting}=$value;

print setting $portsetting - $digi{$portnum}{$portsetting}\n if $debug;

if($portsetting eq 'porttitle'){
$value =~ tr /-/ /;
$value =~ m/^(\w+)\s+(\w+)/i;
Again if you are going to run a match make sure it succeeds, especially 
when capturing.  As a side note your sample data did not contain this.

$field-{$portsetting}=$1;
$field-{'type'}=$2;
print 1:$digi{$portnum}{$portsetting}\t2:$digi{$portnum}{'type'}\n if $debug;
}
 }

# print the whole thing
 foreach $port ( keys %digi ) {
 print $port: { ;
 for $field ( keys %{ $digi{$port} } ) {
 print $field=$digi{$port}{$field} ;
 }
 print }\n;
 }
If this is just for debugging take a look at Data::Dumper it is much easier.

Sample DATA

port = 0
bmanset = 0
benable = 1
uarttype = 0
baudrate = 9600
stopbits = 1
databits = 8
parity = 0
flowcontrol = 0
protocol = 1
port = 1
bmanset = 0
benable = 1
uarttype = 0
baudrate = 9600
stopbits = 1
databits = 8
parity = 0
flowcontrol = 0
protocol = 1

Essentially something is very awkward about all of that code, and it can 
definitely be simplified by using better scoping.  You should consider 
reading, if you haven't already,

perldoc perldsc
perldoc perllol
perldoc perlreftut
perldoc perlref
Here is a stab, untested,

#!/usr/local/bin/perl
use strict;
use warnings;
my %ports;

my $current_port = '';
while (my $line = DATA) {
if ($line =~ /^port\s=\s(\d+)$/) {
$current_port = $1;
}
elsif ($line =~ /^(.*)\s=\s(.*)$/) {
die Port not set unless $current_port ne '';
$ports{$current_port}-{$1} = $2;
}
else {
warn Improperly formatted line: $line;
}
}
use Data::Dumper;
print Dumper(\%ports);
__DATA__
port = 0
bmanset = 0
benable = 1
uarttype = 0
baudrate = 9600
stopbits = 1
databits = 8
parity = 0
flowcontrol = 0
protocol = 1
port = 1
bmanset = 0
benable = 1
uarttype = 0
baudrate = 9600
stopbits = 1
databits = 8
parity = 0
flowcontrol = 0
protocol = 1
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: using strict

2004-04-01 Thread Wiggins d'Anconia
[EMAIL PROTECTED] wrote:
Does the following turn off strict for a vars?

no strict vars;

Could you also turn off strict for other things besides vars, refs and subs?  Say for a subroutine (for example).

Pragma are block/file scoped similar to a lexical. To answer your 
question below, yes you could turn off all or a subset of the strict 
pragma for a given block.  Suggested reading:

perldoc strict
perldoc -f use
perldoc perllexwarn
Just curious.  I've run into situations where I've come across badly maintained code and would like to do this for pieces instead of the whole deal.

That is probably the best use of them, at least until you cleanup the 
code sufficiently that they can go back to being file scoped.

http://danconia.org

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



RE: Is this possible? (file handles)

2004-04-01 Thread Venugopal P
Once you close the file, memory for the file handle will be deallocated.
You can unlink file using the original file name.
unlink (abc);

-Original Message-
From: Jeff Westman [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 01, 2004 2:02 AM
To: perl_help
Subject: Is this possible? (file handles)


Hi,

I want to remove an empty file using the file handle and not a
variable name or literal name referencing it.  Something like this:

 1  #!/bin/perl 
 2  use warnings;
 3  use strict;
 4  no strict 'subs';
 5
 6  open(F,  abc) or die cant create file: $!;
 7  close(F) or die cant close file: $!;
 8
 9  unlink(\*F) if -z (F);

But, in this case, I get an error:

$ runme.pl
-z on closed filehandle F at ./x line 9.


TIA,

Jeff

__
Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.
http://taxes.yahoo.com/filing.html

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




directory and file operations

2004-04-01 Thread MuthuKumar
Hi,
 I want to open all (.txt,.html,.js files) files in a particular directory
and replace a text in all that files.
 What I done so far was a script to replace text in all files in the current
directory.
 What I want was, When I run the script,it should ask for the path of a
particular directory and also the
 types(all files of its type in that dir) of files to open.

 I wrote a script to change the directory to I specified through
commandline.but again it lists only
 the files in current directory.
 Please help me in this issue,
 The code is

print Enter a path name: ;
my $path=STDIN;
chdir($path);

my $file='';
my @files=*.txt;

foreach $file (@files){
{
inner loop for pattern matchinh
};


Thanks for the help.
Muthukumar.




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Is this possible? (file handles)

2004-04-01 Thread Smoot Carl-Mitchell
On Fri, 2 Apr 2004 10:55:07 +0530
Venugopal P [EMAIL PROTECTED] wrote:

 Once you close the file, memory for the file handle will be
 deallocated. You can unlink file using the original file name.
 unlink (abc);

On Unix systems, you may unlink a file after opening it. The directory
entry for the file is deallocated, but the file is still open. When the
file is closed, the disk allocation for the file is reclaimed.

This is a handy method for creating temporary files that you want to be
sure get deallocatted when the program using the temporary file exits.

-- 
Smoot Carl-Mitchell
Systems/Network Architect
email: [EMAIL PROTECTED]
cell: +1 602 421 9005
home: +1 480 922 7313

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How to determine if STDIN has piped data?

2004-04-01 Thread Bryan Harris


 Alternatively, you can use the '-t' operator:
 
 exit 0 if -t STDIN
 
 I've been waiting for this for a LONG time, thanks Smoot.
 
 No problem.  It took me a while to find the correct operator as well.
 
 Please keep in mind that doing this breaks the de facto Unix standard
 for filters.  A simply command which is a filter (e.g takes
 input from STDIN and sends output to STDOUT) is written without any
 consideration whether the input is a terminal, pipe, socket or
 otherwise. This makes it very simple to use the command in a pipeline or
 standalone from the terminal.
 
 [stuff cut out]
 
 Strangely, I find that we almost always want our scripts to act this way.
 If any files or data is passed to the script, then it uses it.  Otherwise,
 it prints usage instructions (since we'd rather not have man pages for
 scripts, and I don't know how to build them anyway).
 
 Use POD.  See 'perldoc perlpod' for all the details.
 
 Then the user can just run 'perldoc scriptname' (provided 'scriptname'
 is in $PATH) and get a nicely formatted manpage.


Thanks for the tip, Morten, I'll look into it.  The only problem I see is
that my users forget things very quickly.  They'll never remember perldoc
when they forget how to use a command.

The only thing I lose by doing it the way above is the ability to type a
command, then have it wait for your input terminated by a ctrl-D (which my
users forget too).

I'll look into it, though, I hadn't even considered it.

- B


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Is this possible? (file handles)

2004-04-01 Thread Jeff Westman
Venugopal P [EMAIL PROTECTED] wrote:

 Once you close the file, memory for the file handle will be
 deallocated.
 You can unlink file using the original file name.
 unlink (abc);

This doesn't answer my question.  I wanted to know if it is
possible to remove a file using the FH name, not the variable name
referencing it.  Please see my original post below.

Thanks again,

JW

 
 -Original Message-
 From: Jeff Westman [mailto:[EMAIL PROTECTED]
 Sent: Thursday, April 01, 2004 2:02 AM
 To: perl_help
 Subject: Is this possible? (file handles)
 
 
 Hi,
 
 I want to remove an empty file using the file handle and not a
 variable name or literal name referencing it.  Something like
 this:
 
  1  #!/bin/perl 
  2  use warnings;
  3  use strict;
  4  no strict 'subs';
  5
  6  open(F,  abc) or die cant create file: $!;
  7  close(F) or die cant close file: $!;
  8
  9  unlink(\*F) if -z (F);
 
 But, in this case, I get an error:
 
 $ runme.pl
 -z on closed filehandle F at ./x line 9.
 
 
 TIA,
 
 Jeff


__
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway 
http://promotions.yahoo.com/design_giveaway/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: directory and file operations

2004-04-01 Thread WC -Sx- Jones
MuthuKumar wrote:
print Enter a path name: ;
my $path=STDIN;
chdir($path);


chdir never stays in the directory...

Proof:

print Enter a path name: ;
my $path=STDIN;
chdir($path);
print `pwd`;
You want -
perldoc -f opendir
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Is this possible? (file handles)

2004-04-01 Thread WC -Sx- Jones
Jeff Westman wrote:
Venugopal P [EMAIL PROTECTED] wrote:


Once you close the file, memory for the file handle will be
deallocated.
You can unlink file using the original file name.
unlink (abc);


This doesn't answer my question.  I wanted to know if it is
possible to remove a file using the FH name, not the variable name
referencing it.  Please see my original post below.


No, you cannot delete a file via it's handle;
you can do this however -
use 5.004;
use Fcntl qw(:DEFAULT :flock);
sysopen(BLACKHOLE, $path, O_WRONLY | O_CREAT)
or die can't create $path: $!;
flock(BLACKHOLE, LOCK_EX)
or die can't lock $path: $!;
truncate(BLACKHOLE, 0)
or die can't truncate $path: $!;
Then use unlink(filename) to delete it...
-Sx-
However, don't take my word for it -
test all this yourself:
open(TESTFILE, atestfile) or die cant $!;
print TESTFILE Im data - not the android.;
close(TESTFILE);
# try to delete it by FH only -
open(TF2, atestfile) or die cant $!;
unlink(TF2);
close(TESTFILE);
# File still exists -
print `ls -l`;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response