Bolding and Underlining.

2003-07-21 Thread Sara
I have an input coming from scrolling textbox eg.

$description = qq~
This is my description. Here goes a couple of headings in it
Heading abc: 
this is the heading one and needs to bold and underlined
Heading xyz: 
needs to bold and underlined too.
description continues here
~;

I am producing HTML files from input. I need to underline and make bold these headings 
when the output is 
generated. Any ideas how to extract and make the changes in headings only for output?

The two definate markers for these headings are there is always a line break before 
and after the heading and it always contains the colon at the end :

Thanks for any input

Sara.




RE: Unix style to move and write two level up

2003-07-21 Thread Marcos . Rebelo
I don't know if you have permissions but this shell give a path to you

use File::Spec;
use FindBin;
use lib (File::Spec-join($FindBin::Bin, .., ..));

File::Specgives allot of path function
FindBin   gives information about the script directory
$FindBin::Bin directory where your script is,

Marcos

-Original Message-
From: Voodoo Raja [mailto:[EMAIL PROTECTED]
Sent: Monday, July 21, 2003 7:15 AM
To: [EMAIL PROTECTED]
Subject: Unix style to move and write two level up


Hi all

I am wandering if there is a way to specify my cgi script to=20
write a file in a directory which is two level up..

curently I am able to write to images folder which is located in My =
/cgi-bin/images.

instead I would like to move two level up and write to the Root where =
the cgi-bin is side by side the another images folder.

any piece of code will be appreciated.


thanxz

sam

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



anyone found the code from the new Learning Perl 2 O'Reilly book?

2003-07-21 Thread Kevin Pfeiffer
I posted to the O'Reilly errata page for this, but have not seen an answer 
yet. Has anyone else found the referenced code from the new Learning Perl 
Objects, References, and Modules book?

-K
-- 
Kevin Pfeiffer
International University Bremen

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



why no stat output via Perl for one file?

2003-07-21 Thread Kevin Pfeiffer
Hi all,

(long, answer below)

I have this bit of code:

for my $file (@files) {
   my @stat = (stat $file);
   my $mtime = (stat $file)[9];
   my $when = localtime $mtime;
   print $when: $file -- @stat\n;
}

And from my array of three files I get this as output:

sputnik:~/perl/learning_more_perl/06chap - ./01ex-06chap
Use of uninitialized value in localtime at ./01ex-06chap line 47.
Thu Jan  1 01:00:00 1970: log-check_web --
Mon Jul 21 13:44:57 2003: 01ex-06chap~ -- 770 169066 33261 1 500 100 0 1069 1058787902 
1058787897 1058787897 4096 8
Mon Jul 21 13:45:07 2003: 01ex-06chap -- 770 168406 33261 1 500 100 0 1068 1058787909 
1058787907 1058787907 4096 8

But if I run stat on the CL I get:

  File: `log-check_web'
  Size: 26631   Blocks: 56 IO Block: 4096   Regular File
Device: 302h/770d   Inode: 112617  Links: 1
Access: (0644/-rw-r--r--)  Uid: (  500/pfeiffer)   Gid: (  100/   users)
Access: 2003-07-21 13:35:39.0 +0200
Modify: 2003-07-21 13:46:54.0 +0200
Change: 2003-07-21 13:46:54.0 +0200

What obvious (Aha!) thing am I missing?

[time passes]

Okay, I modified my stat line:
   my @stat = (stat $file) or warn Stat error ($file): $!\n;

And now I see a useful message: 
Stat error (log-check_web): No such file or directory

Which leads me to realize that I am trying to stat a file that is 
not in the CWD... (hmmm... I think I was warned about that, too.)

(Anyhow, question answered, but maybe someone else will find this useful)

-K

-- 
Kevin Pfeiffer

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



writing to file

2003-07-21 Thread awarsd
Hi,

I'm curious to know if it is possible to write to file with overwritting
information without putting into an array
if i have in a file
a
b
c
d
e
and i want to add  g-r-t-u-x i would get
now in the file
g
r
t
u
x
e -- stays the same no overwrite.

any help is appreciated
Anthony



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



Removing duplicate lines.

2003-07-21 Thread jonathan . musto
I have a text file which contains a list of companies:
 
NORTH DOWN AND ARDS INSTITUTE
NOTTINGHAM HEALTH AUTHORITY
1ST CONTACT GROUP LTD
1ST CONTACT GROUP LTD
1ST CONTACT GROUP LTD
1ST CONTACT GROUP LTD
4D TELECOM  KINGSTON INMEDIA
A E COOK LTD
A E COOK LTD
 
etc..
 
How can a write a simple perl script to remove the duplicates and leave just
one of each customer?
Any help would be great.
 
Regards,
 
 
Jonathan Musto

 

BT Global Services
Telephone - 0113 237 3277
Fax - 0113 244 1413
E-mail -  mailto:[EMAIL PROTECTED] [EMAIL PROTECTED]
http://www.technet.bt.com/sit/public http://www.technet.bt.com/sit/public 


British Telecommunications plc 
Registered office: 81 Newgate Street London EC1A 7AJ 
Registered in England no. 180 
This electronic message contains information from British Telecommunications
plc which may be privileged or  confidential. The information is intended to
be for the use of the individual(s) or entity named above. If you  are not
the intended recipient be aware that any disclosure, copying, distribution
or use of the contents of  this information is prohibited. If you have
received this electronic message in error, please notify us by  telephone or
email (to the numbers or address above) immediately.




 


RE: Short silly question

2003-07-21 Thread Bob Showalter
Gabor Urban wrote:
 Hi,
 
 
 could someone give me a quick info whar __END__ and __DATA__ lines
 are good for? 

They are used to tell Perl to stop compiling the script at that point,
because whatever follows is either:

a) data to be read in to the script using the special DATA filehandle (see
perldoc perldata)

b) code that should be compiled only on demand (see perldoc SelfLoader)

I would guess the latter is probably rarely used in this day of speedy
processors and systems.

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



Re: Removing duplicate lines.

2003-07-21 Thread Janek Schleicher
Jonathan Musto wrote at Mon, 21 Jul 2003 13:11:10 +0100:

 I have a text file which contains a list of companies:
  
 NORTH DOWN AND ARDS INSTITUTE
 NOTTINGHAM HEALTH AUTHORITY
 1ST CONTACT GROUP LTD
 1ST CONTACT GROUP LTD
 1ST CONTACT GROUP LTD
 1ST CONTACT GROUP LTD
 4D TELECOM  KINGSTON INMEDIA
 A E COOK LTD
 A E COOK LTD
  
 etc..
  
 How can a write a simple perl script to remove the duplicates and leave just
 one of each customer?
 Any help would be great.

What have you tried so far?
Have you read
perldoc -q duplicate

[untested]
my %seen;
while () {
   print unless $seen{$_}++;
}


Greetings,
Janek

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



RE: methods

2003-07-21 Thread Bob Showalter
[EMAIL PROTECTED] wrote:
 Hi all,
 
 Whats the difference between class methods and instance methods on
 perl ? 

A class method can be called without reference to a specific instance. Any
data it accesses is global. Constructors are class methods. An instance
method accesses member data of a specific class instance, and must be called
with reference to that instance.

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



Re: Removing duplicate lines.

2003-07-21 Thread Jenda Krynicky
From: [EMAIL PROTECTED]
 I have a text file which contains a list of companies:
 
 NORTH DOWN AND ARDS INSTITUTE
 NOTTINGHAM HEALTH AUTHORITY
 1ST CONTACT GROUP LTD
 1ST CONTACT GROUP LTD
 1ST CONTACT GROUP LTD
 1ST CONTACT GROUP LTD
 4D TELECOM  KINGSTON INMEDIA
 A E COOK LTD
 A E COOK LTD
 
 etc..
 
 How can a write a simple perl script to remove the duplicates and
 leave just one of each customer? Any help would be great.

Is it safe to assume that all duplicates are together like this? If 
so all you have to do is to
1) read the file line by line
2) only print the line you just read if it's different from the last 
one
3) remember the line

or if I word it differently. 
1) read the file
2) skip the line if it's the same as the last one
3) print it and remember it

my $last = '';
while () {
next if $_ eq $last;
print $_;
$last = $;
}

If the duplicates are scattered all over the place, then the easiest 
solution is to use a hash, That will get rid of the duplicates for 
you:

while () {
chomp;
$seen{$_}++;
}

foreack my $item (keys %seen) {
print $item,\n;
}

If the list of companies is huge you may need to store the hash on 
disk to prevent swapping:

use DB_File;
tie %seen, 'DB_File', $filename;
...

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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



How to check data type in @_ ?

2003-07-21 Thread LI NGOK LAM
I am going to write a sub accept different types of data type.
My interface is some what like this :

$ret = mySub ( \%hash );
$ret = mySub ( [EMAIL PROTECTED] );
$ret = mySub ( \$calar );
$ret = mySub ( \Sub );
$ret = mySub ( $calar );
$ret = mySub ( %hash );
$ret = mySub ( @rray );

Is there anyway I can check what is the data type 
for each element inside @_ ?

TIA

RE: How to check data type in @_ ?

2003-07-21 Thread Bob Showalter
LI NGOK LAM wrote:
 I am going to write a sub accept different types of data type.
 My interface is some what like this :
 
 $ret = mySub ( \%hash );
 $ret = mySub ( [EMAIL PROTECTED] );
 $ret = mySub ( \$calar );
 $ret = mySub ( \Sub );
 $ret = mySub ( $calar );
 $ret = mySub ( %hash );
 $ret = mySub ( @rray );
 
 Is there anyway I can check what is the data type
 for each element inside @_ ?

Each element of @_ is a scalar. If you want to know whether that scalar is a
reference to something, use the ref() function.

When you call mySub(%h1, %h2), all the key/value pairs in %h1 and %h2 are
flattened into a single list and assigned to @_. There is no way to tell
that two separate hashes were passed or where one ends and the next one
begins. To achieve this you need to pass hash references (explicitly, or
implicitly through the use of prototypes).

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



Is $1 ever undefined or set to null?

2003-07-21 Thread Ed Christian
I assumed that, $1 would be reset (either undefined or set to null) once
I exited the scope of the while loop my regexp was called in. Sadly, I
was mistaken. :) Below is a test example of code I wrote, with $1 values
differing from those I expected. Do I need to explicitly set $1..$n to
an empty string before every regexp if I'm to test based on the results
of that regexp?

Thanks!
- Ed

-=-=-=-=-=-
#!/usr/bin/perl -w
use strict;
use warnings;

while (DATA) {
chomp;
/(\d+)/;
print \$1: $1\n;
}
__DATA__
1
2
a
3


Expected results:
$1: 1
$1: 2
$1: # --- was expecting an empty string
$1: 3

Actual results:
$1: 1
$1: 2
$1: 2   # --- value of $1 never reset from the last run
$1: 3

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



Re: Is $1 ever undefined or set to null?

2003-07-21 Thread Sudarshan Raghavan
Ed Christian wrote:

I assumed that, $1 would be reset (either undefined or set to null) once
I exited the scope of the while loop my regexp was called in. Sadly, I
was mistaken. :) Below is a test example of code I wrote, with $1 values
differing from those I expected. Do I need to explicitly set $1..$n to
an empty string before every regexp if I'm to test based on the results
of that regexp?
No you don't explicitly set or unset these variables, you must only use 
them if the regex succeeded.
In fact these variables are read-only (perldoc perlvar)
Also read through
perldoc perlretut
perldoc perlre

Thanks!
- Ed
-=-=-=-=-=-
#!/usr/bin/perl -w
use strict;
use warnings;
while (DATA) {
   chomp;
   /(\d+)/;
   print \$1: $1\n;
Change the above two lines to
if (/^(\d+)$/) {
   print \$1: $1\n;
} else {
   print Unexpected...\n;
}
It is also a good idea to add anchors to your regexes

}
__DATA__
1
2
a
3
Expected results:
$1: 1
$1: 2
$1: # --- was expecting an empty string
$1: 3
Actual results:
$1: 1
$1: 2
$1: 2   # --- value of $1 never reset from the last run
$1: 3
 



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


RE: Removing duplicate lines.

2003-07-21 Thread jonathan . musto
Thanks all, that worked a treat.

Jonathan Musto

 

BT Global Services
Telephone - 0113 237 3277
Fax - 0113 244 1413
E-mail - [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] 
http://www.technet.bt.com/sit/public


British Telecommunications plc 
Registered office: 81 Newgate Street London EC1A 7AJ 
Registered in England no. 180 
This electronic message contains information from British Telecommunications
plc which may be privileged or  confidential. The information is intended to
be for the use of the individual(s) or entity named above. If you  are not
the intended recipient be aware that any disclosure, copying, distribution
or use of the contents of  this information is prohibited. If you have
received this electronic message in error, please notify us by  telephone or
email (to the numbers or address above) immediately.






-Original Message-
From: Jenda Krynicky [mailto:[EMAIL PROTECTED]
Sent: Monday, July 21, 2003 13:33
To: [EMAIL PROTECTED]
Subject: Re: Removing duplicate lines.


From: [EMAIL PROTECTED]
 I have a text file which contains a list of companies:
 
 NORTH DOWN AND ARDS INSTITUTE
 NOTTINGHAM HEALTH AUTHORITY
 1ST CONTACT GROUP LTD
 1ST CONTACT GROUP LTD
 1ST CONTACT GROUP LTD
 1ST CONTACT GROUP LTD
 4D TELECOM  KINGSTON INMEDIA
 A E COOK LTD
 A E COOK LTD
 
 etc..
 
 How can a write a simple perl script to remove the duplicates and
 leave just one of each customer? Any help would be great.

Is it safe to assume that all duplicates are together like this? If 
so all you have to do is to
1) read the file line by line
2) only print the line you just read if it's different from the last

one
3) remember the line

or if I word it differently. 
1) read the file
2) skip the line if it's the same as the last one
3) print it and remember it

my $last = '';
while () {
next if $_ eq $last;
print $_;
$last = $;
}

If the duplicates are scattered all over the place, then the easiest 
solution is to use a hash, That will get rid of the duplicates for 
you:

while () {
chomp;
$seen{$_}++;
}

foreack my $item (keys %seen) {
print $item,\n;
}

If the list of companies is huge you may need to store the hash on 
disk to prevent swapping:

use DB_File;
tie %seen, 'DB_File', $filename;
...

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
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]



Comparing 2 lists

2003-07-21 Thread jonathan . musto
Hi all,
 
Sorry i'm very new to this.
I have 2 lists of companies, not neccessarly in order, and i want to produce
a list of companies which apear in both lists.
 
Eg.
 
List 1...
 
Macdonalds
HMV
Virgin
Dixons
 
Compared with List 2...
 
HMV
Flannels
Currys
Dixons
 
Will output...
 
HMV
Dixons
 
Jonathan Musto

 

BT Global Services
Telephone - 0113 237 3277
Fax - 0113 244 1413
E-mail -  mailto:[EMAIL PROTECTED] [EMAIL PROTECTED]
http://www.technet.bt.com/sit/public http://www.technet.bt.com/sit/public 


British Telecommunications plc 
Registered office: 81 Newgate Street London EC1A 7AJ 
Registered in England no. 180 
This electronic message contains information from British Telecommunications
plc which may be privileged or  confidential. The information is intended to
be for the use of the individual(s) or entity named above. If you  are not
the intended recipient be aware that any disclosure, copying, distribution
or use of the contents of  this information is prohibited. If you have
received this electronic message in error, please notify us by  telephone or
email (to the numbers or address above) immediately.




 


Re: Comparing 2 lists

2003-07-21 Thread awarsd
Hi,

you have an array say list1.
you have a second array say list2.

counter=0;
foreach $line(@list1){
foreach $sec_line(@list2){
  if($line eq $sec_line){
$counter++;
$new_list[$counter]=$line;
}
}
}
print @new_list;

something like that



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



Re: Is $1 ever undefined or set to null?

2003-07-21 Thread Jeff 'japhy' Pinyan
On Jul 21, Ed Christian said:

I assumed that, $1 would be reset (either undefined or set to null) once
I exited the scope of the while loop my regexp was called in. Sadly, I
was mistaken. :) Below is a test example of code I wrote, with $1 values
differing from those I expected. Do I need to explicitly set $1..$n to
an empty string before every regexp if I'm to test based on the results
of that regexp?

You assumed wrong. :)

The documentation states that the $DIGIT variables are set after each
SUCCESSFUL pattern match.  If a regex fails to match, the $DIGIT variables
retain their previous value.  You cannot set them to an empty string, like
you suggested.

Rather, test for the success of your regex:

  print digit = $1\n if /(\d)/;

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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



Appending File

2003-07-21 Thread Jonathan Dwerryhouse
Hi,

Could someone point me in the right direction?

I'd like to write a programme in Perl that will prompt questions and dump the answers 
into a templated piece of text.  E.g:

Userjonathan
Passwordshampoo
Call ID 8007835373

Each time i only want to change the user and password but inject it back into this 
basic template.  

Also, is there a way for the script to prompt for the questions and with the provided 
answers, append the file?

Many Thanks

Re: Comparing 2 lists

2003-07-21 Thread Jeff 'japhy' Pinyan
On Jul 21, [EMAIL PROTECTED] said:

I have 2 lists of companies, not neccessarly in order, and i want to produce
a list of companies which apear in both lists.

This is in the FAQ -- if you type 'perldoc -q intersection', you'll get an
answer from the FAQ about finding the intersection of two arrays.

The simplest approach is to use hashes (if at all possible, INSTEAD of
your arrays).  If you already have arrays, then it's probably easiest just
to do the following:

  my @set_a = (...);
  my @set_b = (...);
  my (%companies, @in_both);

  # first, we make each string in @set_a
  # a key in the %companies hash
  @companies{ @set_a } = ();

  # now, we go through @set_b, and if the string
  # exists as a key in the %companies hash, we
  # know it's also in @set_a
  @in_both = grep exists $companies{$_}, @set_b;

The FAQ provides a different, but more extensible, approach.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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



RE: Comparing 2 lists

2003-07-21 Thread Marcos . Rebelo
my @list1 = (...);
my @list2 = (...);
my @result;

foreach my $line (@list1){
foreach my $sec_line (@list2){
push (@result, $line) 
if $line eq $sec_line;
}
}
print @result;


or 

my @list1 = (...);
my @list2 = (...);
my @result;

my %list1Hash;
$list1Hash{$_}=1 foreach (@list1);

foreach my $match (@list2){
push(@result, $match) if $list1Hash{$match};
}
print @result;

-Original Message-
From: awarsd [mailto:[EMAIL PROTECTED]
Sent: Monday, July 21, 2003 4:35 PM
To: [EMAIL PROTECTED]
Subject: Re: Comparing 2 lists


Hi,

you have an array say list1.
you have a second array say list2.

counter=0;
foreach $line(@list1){
foreach $sec_line(@list2){
  if($line eq $sec_line){
$counter++;
$new_list[$counter]=$line;
}
}
}
print @new_list;

something like that



-- 
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: Comparing 2 lists

2003-07-21 Thread Jeff 'japhy' Pinyan
On Jul 21, awarsd said:

counter=0;
foreach $line(@list1){
foreach $sec_line(@list2){
  if($line eq $sec_line){
$counter++;
$new_list[$counter]=$line;
}
}
}
print @new_list;

There's no reason to use $counter.  Simply say

  push @new_list, $line;

But this is also a very slow way to compare two arrays.  If they're each
10 elements, you're doing 100 comparisons.  It's an O(N*M) operation
(where N and M are the sizes of the arrays).

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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



Re: methods

2003-07-21 Thread Peter Scott
In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] writes:
Hi all,

Whats the difference between class methods and instance methods on perl ?

In any language, the difference between an instance method and a class
method is that an instance method operates on an instance and a class method
operates on the class.  Now in Perl the usual kind of straightjackets that
other O-O languages have don't exist, so the lines get blurred; you can
write methods that are both class and instance methods.  Also, there is no
class data in the usual sense and the notion of object data is somewhat
different from the way other O-O languages see it.

An instance is a dynamically created data structure that is returned from
a class method called a constructor; the instance knows what class it
belongs to and when you call a method on it, Perl knows what package to
look in for that method.  An instance method ought to do something with
that instance, but nothing stops it from just going and doing something
else entirely.

Literally, though, the difference between the two types of method in Perl
is their first argument: a class method receives the name of the class in a
string as the first argument, an instance method receives the object it
was called on as the first argument.

-- 
Peter Scott
http://www.perldebugged.com

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



RE: Is $1 ever undefined or set to null?

2003-07-21 Thread Bob Showalter
Ed Christian wrote:
 I assumed that, $1 would be reset (either undefined or set to null)
 once I exited the scope of the while loop my regexp was called in.
 Sadly, I was mistaken. :) Below is a test example of code I wrote,
 with $1 values differing from those I expected. Do I need to
 explicitly set $1..$n to an empty string before every regexp if I'm
 to test based on the results of that regexp?
 
 Thanks!
 - Ed
 
 -=-=-=-=-=-
 #!/usr/bin/perl -w
 use strict;
 use warnings;
 
 while (DATA) {
 chomp;
 /(\d+)/;
 print \$1: $1\n;
 }
 __DATA__
 1
 2
 a
 3
 
 
 Expected results:
 $1: 1
 $1: 2
 $1:   # --- was expecting an empty string
 $1: 3

You've already gotten the answer on how $1 works. But, if you want to get
undef on a failed match, you can use the match in a list context:

   my ($number) = /(\d+)/;

Now $number will contain the matched string, or undef if there was no match.

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



time difference in milliseconds

2003-07-21 Thread Hemant Desai
hi ,

am trying to benchmark some code and it requires the time difference in
milliseconds


$st_time = {get time in milliseconds);
{
do something
}
$end_time = {get time in milliseconds);

get difference ($dlta = $end_time - st_time);



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



RE: time difference in milliseconds

2003-07-21 Thread wiggins


On Mon, 21 Jul 2003 20:39:36 +0530, Hemant Desai [EMAIL PROTECTED] wrote:

 hi ,
 
 am trying to benchmark some code and it requires the time difference in
 milliseconds
 
 
 $st_time = {get time in milliseconds);
 {
 do something
 }
 $end_time = {get time in milliseconds);
 
 get difference ($dlta = $end_time - st_time);
 

You didn't ask a question, so I assume you are trying to determine how to get the time 
in millisecond intervals, check out the Time::HiRes module on CPAN. (Might be default 
with 5.8.0).

http://search.cpan.org/author/JHI/Time-HiRes-1.49/HiRes.pm

http://danconia.org

http://danconia.org

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



RE: time difference in milliseconds

2003-07-21 Thread Hemant Desai

thanks a lot 

is it possible to do the same w/o using a package...


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Monday, July 21, 2003 8:49 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: time difference in milliseconds




On Mon, 21 Jul 2003 20:39:36 +0530, Hemant Desai [EMAIL PROTECTED]
wrote:

 hi ,

 am trying to benchmark some code and it requires the time difference in
 milliseconds


 $st_time = {get time in milliseconds);
 {
 do something
 }
 $end_time = {get time in milliseconds);

 get difference ($dlta = $end_time - st_time);


You didn't ask a question, so I assume you are trying to determine how to
get the time in millisecond intervals, check out the Time::HiRes module on
CPAN. (Might be default with 5.8.0).

http://search.cpan.org/author/JHI/Time-HiRes-1.49/HiRes.pm

http://danconia.org

http://danconia.org

--
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: time difference in milliseconds

2003-07-21 Thread Hemant Desai
thanks a lot.. :)

is HiRes.pm  s 'standard' module which is supported on all platforms ...

actually its been a really long time since i' have worked on perl (abt 3 yrs
now..) so am kinda really rusty..



-Original Message-
From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]
Sent: Monday, July 21, 2003 9:08 PM
To: Hemant Desai
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: time difference in milliseconds


On Jul 21, Hemant Desai said:

is it possible to do the same w/o using a package...

Well, the Time::HiRes module was created so that you COULD.  You need
access to finer-grain time than Perl has built-in.  You'll need some sort
of extension.

--
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


--
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]



File Find wrinkles

2003-07-21 Thread John Goodleaf
Here's the thing. I've written a script to recurse through a
directory tree and find all the changed files therein. I've got a db
file to hold checksums and so forth, but that's beside the point.
I'm using File::Find to do the recursion for me, but I can't seem to
figure out how to keep it from recursing through directories I don't
want. For example, I don't want stuff from dotdirectories or from
browser caches. I have been trying to use tests to ferret that out,
but the script seems to read the files anyway.
snip
if (-s
 -f
 $File::Find::dir !~ /[Cc]ache/
 $File::Find::dir !~ /\/\.*\//) {

print DEBUG: File found is : $_\n;

open(FILE, $_) or print REPORT Could not open
$File::Find::name: $!\n;
binmode(FILE);
my $digest=Digest::MD5-new-addfile(*FILE)-hexdigest;
close FILE;
Am I barking up the wrong tree? Any suggestion for other useful
modules?
snip
Thanks,
John

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



RE: Regex extraction skipping lines

2003-07-21 Thread Andrew Thomas
Of course I apologize - I had meant to include that. Here it is, the 
actual script is quite long so I've pared it down some to try and isolate 
the problem. This is the whole script now and it is still having the same 
problem.

Text file is ~2800 lines like the following:

Lastname, Firstname|1|137|10_3|10/13/01|...etc.
(I have examined this carefully, and every line although very long does end 
with a newline character)

And My script includes the following:

#!/usr/bin/perl

system clear;
print Welcome to Andy's Data Processor...\n;
open(WRITEFILE, Output.txt) or die Couldn't open WRITEFILE for 
preparation.;

print WRITEFILE Patient Name|Study ID|Date of Birth|Medical Rec Num|Obs End 
Date|Months of Obs|Month of Obs|Month of Year|Year|ID_Rec|CC Status|Acute 
OV|ED Visits|Telemed Visits|WCC Visits|Non-Acute OV|\n;

print Opening ReadFile(s)...\n\n\n;

open (READFILE,events.txt) or die Couldn't open READFILE.;

while(READFILE) {

	$string = READFILE;

$string =~ /^(\w+-*\w* *\w*, \w+)\|(\d+)\|(\d+)|/;
$patientName = $1;
	$studyID = $2;

	$dateOfBirth = $3;

  print WRITEFILE $patientName, $studyID, $dateOfBirth;
}
close READFILE;

close WRITEFILE;

That is the whole script - and it still outputs only half the lines. I'm 
pretty much stumped - and starting to think that maybe perl isn't the best 
solution for this project.. Hope someone out there can help.

-Andy

_
Add photos to your e-mail with MSN 8. Get 2 months FREE*.  
http://join.msn.com/?page=features/featuredemail

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


RE: Regex extraction skipping lines

2003-07-21 Thread Tara Calishain
At 11:38 AM 7/21/2003, Andrew Thomas wrote:

Of course I apologize - I had meant to include that. Here it is, the actual 
script is quite long so I've pared it down some to try and isolate the problem. This 
is the whole script now and it is still having the same problem.

I'm the most newbie Perler in the world, so I hope I'm not speaking out of turn 
here... 

... but instead of this...

while(READFILE) {

$string = READFILE;

$string =~ /^(\w+-*\w* *\w*, \w+)\|(\d+)\|(\d+)|/;
$patientName = $1;

$studyID = $2;

$dateOfBirth = $3;

  print WRITEFILE $patientName, $studyID, $dateOfBirth;
}

Have you tried this? 

while (READFILE) {
my $string = $_; #opening a line

my @patientinfo = split (/ | /, $string); 

my $patientName = $patientinfo[0];
my $studyID = $patientinfo[1]; 
my $dateOfBirth = $patientinfo[2]; 

print WRITEFILE $patientName, $studyID, $dateOfBirth \n; 
}

... since you've got each item on a line, and you've got a common delimiter, it just 
seems like it would be easier to go line-by-line, split the line along the common 
delimiter and just grab what you want that way. 

... but I'm a huge Perl newbie so there may be something really obvious I'm missing 
here! 

Tara



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



loading a module

2003-07-21 Thread Hemant Desai
cant' locate loadable object from module Time::HiRes in @INC (@INC
contains...a list of paths which are present in @INC)

this is the error I am getting while trying to use HiRes.pm (probably a
general error.

have made copies of HiRes.pm in
/usr/perl5/
/usr/perl5/5.00503/
/usr/perl5/5.00503/Time

please do let me know how a .pm can be loaded

thnx ..


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



RE: Regex extraction skipping lines

2003-07-21 Thread Jeff 'japhy' Pinyan
On Jul 21, Andrew Thomas said:

Of course I apologize - I had meant to include that. Here it is, the
actual script is quite long so I've pared it down some to try and isolate
the problem. This is the whole script now and it is still having the same
problem.

But the person (I think) you're replying to already TOLD you the problem.
You've got:

while(READFILE) {

and then you've got:

   $string = READFILE;

The while() line reads a line into $_, and then you read the NEXT line
into $string.

   $string =~ /^(\w+-*\w* *\w*, \w+)\|(\d+)\|(\d+)|/;

You've got a | at the end of your regex that I THINK you want to be \|.

   $patientName = $1;
   $studyID = $2;
   $dateOfBirth = $3;
   print WRITEFILE $patientName, $studyID, $dateOfBirth;

You're missing the newline after you print those things.  And you don't
need to use separate variables -- you could just use $1, $2, and $3.  And
don't you want a | between these fields still?

And you're using the $DIGIT variables without being sure the regex matched,
which isn't a smart idea.

}

I'd rewrite the loop as follows:

  while (READFILE) {
if (/^(\w+-*\w* *\w*, \w+)\|(\d+)\|(\d+)\|/) {
  print WRITEFILE $1|$2|$3\n;
}
  }

But maybe you could just write:

  while (READFILE) {
chomp;
my @fields = split /\|/;
print WRITEFILE join(|, @fields[0..2]), \n;
  }

Perhaps if you tell us exactly what your program is supposed to do, we can
help you write it better.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]



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



Re: loading a module

2003-07-21 Thread Casey West
It was Monday, July 21, 2003 when Hemant Desai took the soap box, saying:
: cant' locate loadable object from module Time::HiRes in @INC (@INC
: contains...a list of paths which are present in @INC)
: 
: this is the error I am getting while trying to use HiRes.pm (probably a
: general error.
: 
: have made copies of HiRes.pm in
: /usr/perl5/
: /usr/perl5/5.00503/
: /usr/perl5/5.00503/Time
: 
: please do let me know how a .pm can be loaded

Hi there, you need to install the module.

The short answer for installing a module is this (run from the command
line):

  perl -MCPAN -e'install Time::HiRes'

For more information, consult the documentation for CPAN.

  perldoc CPAN



  Casey West

-- 
Usenet is like a herd of performing elephants with diarrhea --
massive, difficult to redirect, awe-inspiring, entertaining, and a
source of mind-boggling amounts of excrement when you least expect
it. -- Gene Spafford


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



STDIN and STDOUT on Windows

2003-07-21 Thread LoBue, Mark
Hello,

I normally use perl on a unix platform, but I needed to run a quick utility
on a Windows PC.  Normal stdin and stdout doesn't seem to work, take this
simple program:

#
use warnings;
use strict;

while () {
print;
}

On Windows, if I run:
type test.txt | test.pl
I get:
The process tried to write to a nonexistent pipe.
or
test.pl  test.txt
I get nothing at all.  Any tricks to using stdin and stdout on Windows or do
I have to explicitly open files on that platform?

Using Activestate 5.6 on Windows NT.

-Mark


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



RE: STDIN and STDOUT on Windows

2003-07-21 Thread LoBue, Mark
 -Original Message-
 From: LoBue, Mark [mailto:[EMAIL PROTECTED]
 Sent: Monday, July 21, 2003 9:26 AM
 To: '[EMAIL PROTECTED]'
 Subject: STDIN and STDOUT on Windows
 
 
 Hello,
 
 I normally use perl on a unix platform, but I needed to run a 
 quick utility
 on a Windows PC.  Normal stdin and stdout doesn't seem to 
 work, take this
 simple program:
 
 #
 use warnings;
 use strict;
 
 while () {
 print;
 }
 
 On Windows, if I run:
   type test.txt | test.pl
 I get:
   The process tried to write to a nonexistent pipe.
 or
   test.pl  test.txt
 I get nothing at all.  Any tricks to using stdin and stdout 
 on Windows or do
 I have to explicitly open files on that platform?
 
Ok, I just found the trick, the registration of the .pl doesn't handle this
case, I have to run:
type test.txt | perl test.pl
-Mark


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



loading hash file

2003-07-21 Thread awarsd
Hi,

I'm curious because I really don't know how hash database works ( i know how
to add-edit-delete-get records for a hash dbm).
When we open a dbm
tie...
does it go trough all records first and put it into a hash, or it is just
THERE open ready to go.??

Is it quicker to open a hash dbm(tie.) or flat file( open(...))

Any insights are appreciated,
Thank You,



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



RE: Regex extraction skipping lines

2003-07-21 Thread Andrew Thomas
Thank you. Yes indeed that does solve the issue - of course I have to escape 
the pipe | character in order to make it work, but I don't run into any of 
the other issues anymore.

As for using the straight number variables {$1, $2, $3...} I actually will 
be doing much more processing work with these variables before they are 
outputted - that's the reason for writing them to recognizable named 
variable names.

The purpose of this script is to take one dataset of ~2600 separate research 
events and reformatting them to follow a patient through 24 months of 
observation by connecting all the events pertaining to a single patient.

Thank you all - this seems to be just the fix I needed to make it work.

-Andy

_
Tired of spam? Get advanced junk mail protection with MSN 8. 
http://join.msn.com/?page=features/junkmail

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


Re: STDIN and STDOUT on Windows

2003-07-21 Thread Rob Dixon
Mark Lobue wrote:
  -Original Message-
  From: LoBue, Mark [mailto:[EMAIL PROTECTED]
  Sent: Monday, July 21, 2003 9:26 AM
  To: '[EMAIL PROTECTED]'
  Subject: STDIN and STDOUT on Windows
 
 
  Hello,
 
  I normally use perl on a unix platform, but I needed to run a
  quick utility
  on a Windows PC.  Normal stdin and stdout doesn't seem to
  work, take this
  simple program:
 
  #
  use warnings;
  use strict;
 
  while () {
  print;
  }
 
  On Windows, if I run:
  type test.txt | test.pl
  I get:
  The process tried to write to a nonexistent pipe.
  or
  test.pl  test.txt
  I get nothing at all.  Any tricks to using stdin and stdout
  on Windows or do
  I have to explicitly open files on that platform?
 
 Ok, I just found the trick, the registration of the .pl doesn't
 handle this case, I have to run:
   type test.txt | perl test.pl

We Unix people find we Windows people very strange :)

Windows' handling of pipes and redirections is only vaguely
comparable to Unix. In fact, whether you are running 'cmd.exe'
or 'command.com' makes a big difference, and not just what you'd
expect from a change of shell.

One the other hand, Windowers would wonder why (sorry, no more
'W's) anybody would either pipe or redirect an input file to
its destination program. Think Run the interpreter on
file input file using input files file1 file2 ..

  test.pl  test.txt
and
  type test.txt | perl test.pl

are just two (increasingly weird) versions of

  perl test.pl test.txt


HTH,

Rob




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



Re: Is $1 ever undefined or set to null?

2003-07-21 Thread Steve Grazzini
On Mon, Jul 21, 2003 at 10:34:59AM -0400, Jeff 'japhy' Pinyan wrote:
 On Jul 21, Ed Christian said:
 
 I assumed that, $1 would be reset (either undefined or set to null) once
 I exited the scope of the while loop my regexp was called in. Sadly, I
 was mistaken. :) Below is a test example of code I wrote, with $1 values
 differing from those I expected. Do I need to explicitly set $1..$n to
 an empty string before every regexp if I'm to test based on the results
 of that regexp?
 
 You assumed wrong. :)
 
 The documentation states that the $DIGIT variables are set after
 each SUCCESSFUL pattern match.  If a regex fails to match, the $DIGIT
 variables retain their previous value.

The docs also claim that the digit variables will be dynamically
scoped to the current BLOCK, which isn't quite accurate, and is 
presumably what confused Ed.

We could ammend it to say:

   Perl's notion of the last successful match is dynamically scoped.
   
But, as demonstrated, that's not completely accurate either, since
PL_curpm isn't restored on loop iteration.

-- 
Steve

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



RE: Is $1 ever undefined or set to null?

2003-07-21 Thread Bob Showalter
Steve Grazzini wrote:
 On Mon, Jul 21, 2003 at 10:34:59AM -0400, Jeff 'japhy' Pinyan wrote:
  On Jul 21, Ed Christian said:
  
   I assumed that, $1 would be reset (either undefined or set to
   null) once I exited the scope of the while loop my regexp was
   called in. Sadly, I was mistaken. :) Below is a test example of
   code I wrote, with $1 values differing from those I expected. Do
   I need to explicitly set $1..$n to an empty string before every
   regexp if I'm to test based on the results of that regexp?
  
  You assumed wrong. :)
  
  The documentation states that the $DIGIT variables are set after
  each SUCCESSFUL pattern match.  If a regex fails to match, the
  $DIGIT variables retain their previous value.
 
 The docs also claim that the digit variables will be dynamically
 scoped to the current BLOCK, which isn't quite accurate, and is
 presumably what confused Ed. 

The docs are correct. $1 is dynamically scoped to the block. Ed's code
didn't leave the block, so this dynamic scoping didn't apply.

Example:

   bar =~ /(bar)/;
   print before block: \$1=$1\n;
   while (1) {
   foo =~ /(foo)/;
   print inside block: \$1=$1\n;
   last;
   }
   print after block: \$1=$1\n;

Prints:

   before block: $1=bar
   inside block: $1=foo
   after block: $1=bar

Thus, $1 is saved before entry to the block and restored afterward.

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



splitting an array into ???

2003-07-21 Thread Tim McGeary
Hi...  I have an array of pipe delimited data from a file.  I need to go 
item by item of the array, splitting up the fields into separate 
variables so that I can insert other pre-determined fields into an SQL 
statement to load into a MySQL db.  I feel pretty confident about the 
SQL part, but I'm not sure the best way to split the fields of the 
array.  I have 4 pipe-delimited fields in each line of the array.

is it as simple as doing:

foreach $item (@array) {
my ($key, $title, $url, $code) = split /\|/;
do other stuff;
}
--
Tim McGeary
Senior Library Systems Specialist
Lehigh University
610-758-4998
[EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Removing duplicate lines.

2003-07-21 Thread John W. Krahn
Hi Jenda  :-)

Jenda Krynicky wrote:
 
 Is it safe to assume that all duplicates are together like this? If
 so all you have to do is to
 1) read the file line by line
 2) only print the line you just read if it's different from the last
 one
 3) remember the line
 
 or if I word it differently.
 1) read the file
 2) skip the line if it's the same as the last one
 3) print it and remember it
 
 my $last = '';
 while () {
 next if $_ eq $last;
 print $_;
 $last = $;
  ^^
Assigning the value of $; to $last will not do what you want.  Note that
it is not a syntax error as $; is a valid variable name and the
semicolon is not required at the end of the block.

  $last = $_


 }


John
-- 
use Perl;
program
fulfillment

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



Re: splitting an array into ???

2003-07-21 Thread awarsd
Hi,


to me yes it is the best way, but look again at your split code.

foreach $item (@array) {
my ($key, $title, $url, $code) = split( /\|/,$item);
do other stuff;
}



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



RE: Regex extraction skipping lines

2003-07-21 Thread wiggins


On Mon, 21 Jul 2003 11:38:26 -0400, Andrew Thomas [EMAIL PROTECTED] wrote:

 Of course I apologize - I had meant to include that. Here it is, the 
 actual script is quite long so I've pared it down some to try and isolate 
 the problem. This is the whole script now and it is still having the same 
 problem.
 
 
 Text file is ~2800 lines like the following:
 
 Lastname, Firstname|1|137|10_3|10/13/01|...etc.
 (I have examined this carefully, and every line although very long does end 
 with a newline character)
 
 And My script includes the following:
 
 #!/usr/bin/perl
 

Always have these:

use strict;
use warnings; 

 system clear;

Not terribly portable but that is ok.

 print Welcome to Andy's Data Processor...\n;
 
 open(WRITEFILE, Output.txt) or die Couldn't open WRITEFILE for 
 preparation.;
 

You should include the special variable $! in your error strings so you know WHY the 
file couldn't be opened.

 print WRITEFILE Patient Name|Study ID|Date of Birth|Medical Rec Num|Obs End 
 Date|Months of Obs|Month of Obs|Month of Year|Year|ID_Rec|CC Status|Acute 
 OV|ED Visits|Telemed Visits|WCC Visits|Non-Acute OV|\n;
 
 print Opening ReadFile(s)...\n\n\n;
 
 open (READFILE,events.txt) or die Couldn't open READFILE.;
 

See $! above.

 while(READFILE) {
 
   $string = READFILE;
 

You are reading each line into the script twice with the above construct. First you 
read a line into the default $_ then read the next line into $string. This is why your 
script appears to skip lines (a common mistake).  You should combine the two.

while ($string = READFILE) {

Will do nicely.

   $string =~ /^(\w+-*\w* *\w*, \w+)\|(\d+)\|(\d+)|/;
   $patientName = $1;
 
   $studyID = $2;
 
   $dateOfBirth = $3;
 
print WRITEFILE $patientName, $studyID, $dateOfBirth;
 }
 
 close READFILE;
 
 close WRITEFILE;
 
 
 That is the whole script - and it still outputs only half the lines. I'm 
 pretty much stumped - and starting to think that maybe perl isn't the best 
 solution for this project.. Hope someone out there can help.
 

Whether Perl is the best solution is always up for debate, but it is definitely a good 
solution.  

http://danconia.org

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



inline editing non command line

2003-07-21 Thread Paul D. Kraus
How can you edit a file inline.

I can of course open it and then write it out back to a tmp file. Then
rename the files.

But is there a way to do it inline so that perl handles the temp files and
cleanup?

I have seen tons of examples using the command line but how can you do it in
a script.

For instance.

foreach (glob (*.pl){
open ( IN, $_ ) or die (Cannot open file $_ $!\n );
while (IN){
$_ =~ s/dbi:xxx:xxx/dbi:yyy:yyy/;
}
}

Paul Kraus



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



Please help me

2003-07-21 Thread S. Naqashzade
Dear Friends,
I need to trnaslate thid code to PHP.
Can any one help me?
Tnx

use constant MD5_CRYPT_MAGIC_STRING = '$1$';
use constant I_TO_A64 =
'./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';

sub _to_yahoo_base64
{
 pos($_[0]) = 0;

 my $res = join '', map( pack('u',$_)=~ /^.(\S*)/, ($_[0]=~/(.{1,45})/gs));
 $res =~ tr{` -_}{AA-Za-z0-9\._};

 my $padding = (3 - length($_[0]) % 3) % 3;
 $res =~ s/.{$padding}$/'-' x $padding/e if $padding;
 return $res;
}


sub _to64
{
 my ($v, $n) = @_;
 my $ret = '';
 while (--$n = 0) {
  $ret .= substr(I_TO_A64, $v  0x3f, 1);
  $v = 6;
 }
 $ret;
}


 my $Magic = MD5_CRYPT_MAGIC_STRING;
 $salt =~ s/^\Q$Magic//;
 $salt =~ s/^(.*)\$.*$/$1/;
 $salt = substr $salt, 0, 8;





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



date

2003-07-21 Thread Tim McGeary
Is there anyway to get the date from the system in perl?

Tim



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


Re: Is $1 ever undefined or set to null?

2003-07-21 Thread Steve Grazzini
On Mon, Jul 21, 2003 at 02:18:48PM -0400, Bob Showalter wrote:
 Steve Grazzini wrote:
  On Mon, Jul 21, 2003 at 10:34:59AM -0400, Jeff 'japhy' Pinyan wrote:
   The documentation states that the $DIGIT variables are set after
   each SUCCESSFUL pattern match.
  
  The docs also claim that the digit variables will be dynamically
  scoped to the current BLOCK, which isn't quite accurate, and is
  presumably what confused Ed. 
 
 The docs are correct. $1 is dynamically scoped to the block. Ed's code
 didn't leave the block, so this dynamic scoping didn't apply.

[ snip well-behaved example ]
 
 Thus, $1 is saved before entry to the block and restored afterward.

You can't prove that there isn't a bug by showing well-behaved
examples!  :-)

First: the digit variables are supposed to be dynamically scoped,
but really they're not scoped at all.  Compare these two examples,
which, according to perlvar, ought to be equivalent.

# local()ized variable -

our $x = 0;

sub F {
  local $x = $x + 1;
  print $x;
  F() if $x2;
  print $x;
}

F();# prints 1221


# digit variable 

0 =~ /(\d)/;

sub F {
  ($1 + 1) =~ /(\d)/;
  print $1;
  F() if $12;
  print $1;
}

F();# prints 1222

Now, you can almost explain this by saying that Perl's notion of the
last match is dynamically scoped, and that the digit variables just
refer to captured substrings from the last match.

[ Which leaves out a crucial part of the explanation, but at least 
  it's almost correct. ]

But then there's a second problem: the notional last match isn't
scoped to the body of the loop either.

#-- local()ized variable --

our $x = 1;
print $x;

for (1..3) {
  local $x = $x + 1;
  print $x;
}

print $x;   # output is 12221

#-- digit variable 

1 =~ /(\d)/;
print $1;

for (1..3) {
  ($1 + 1) =~ /(\d)/;
  print $1;
}

print $1;   # output is 12341

The actual behavior is more like what you said: the last match
is saved before loop entry and restored loop exit.  But that's a bit
of a cheat, since everything else that we call dynamically scoped
would get saved and restored with each iteration.

-- 
Steve

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



RE: date

2003-07-21 Thread Jaimee Spencer
Hello, Tim.

Try something like

#!/usr/bin/perl -w

use strict;

system(date);

Regards,
Jaimee

-Original Message-
From: Tim McGeary [mailto:[EMAIL PROTECTED]
Sent: Monday, July 21, 2003 12:18 PM
To: [EMAIL PROTECTED]
Subject: date


Is there anyway to get the date from the system in perl?

Tim




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


Re: splitting an array into ???

2003-07-21 Thread Kevin Pfeiffer
In article [EMAIL PROTECTED], Awarsd wrote:

 Hi,
 
 
 to me yes it is the best way, but look again at your split code.
 
 foreach $item (@array) {
 my ($key, $title, $url, $code) = split( /\|/,$item);
 do other stuff;
 }

or without $item...

foreach (@array) {
   my ($key, $title, $url, $code) = split /\|/;
   # do other stuff...
}




-- 
Kevin Pfeiffer
International University Bremen

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



Re: date

2003-07-21 Thread Kevin Pfeiffer
In article [EMAIL PROTECTED], Tim McGeary wrote:

 Is there anyway to get the date from the system in perl?
 
 Tim

Something like(?):

# system_date

my $date = localtime;

print $date\n;

sputnik:~/perl/perl.beg/new - ./system_date
Mon Jul 21 21:43:04 2003

perldoc -f localtime


-- 
Kevin Pfeiffer
International University Bremen

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



RE: Is $1 ever undefined or set to null?

2003-07-21 Thread Bob Showalter
Steve Grazzini wrote:
 On Mon, Jul 21, 2003 at 02:18:48PM -0400, Bob Showalter wrote:
  Steve Grazzini wrote:
   On Mon, Jul 21, 2003 at 10:34:59AM -0400, Jeff 'japhy'
 Pinyan wrote:
The documentation states that the $DIGIT variables are set after
each SUCCESSFUL pattern match.
   
   The docs also claim that the digit variables will be dynamically
   scoped to the current BLOCK, which isn't quite accurate, and is
   presumably what confused Ed.
  
  The docs are correct. $1 is dynamically scoped to the block. Ed's
  code didn't leave the block, so this dynamic scoping didn't apply.
 
 [ snip well-behaved example ]
 
  Thus, $1 is saved before entry to the block and restored afterward.
 
 You can't prove that there isn't a bug by showing well-behaved
 examples!  :-) 
 
 First: the digit variables are supposed to be dynamically scoped,
 but really they're not scoped at all.  Compare these two examples,
 which, according to perlvar, ought to be equivalent.

Where in the world does perldoc perlvar say these should be equivalent? I
disagree that these are or should be equivalent.

The dynamic scoping behavior of the $1..n variables works the same way that
$_ and foreach iterator variables works.

 
 # local()ized variable -
 
 our $x = 0;
 
 sub F {
   local $x = $x + 1;
   print $x;
   F() if $x2;
   print $x;
 }
 
 F();# prints 1221
 
 
 # digit variable 
 
 0 =~ /(\d)/;
 
 sub F {
   ($1 + 1) =~ /(\d)/;
   print $1;
   F() if $12;
   print $1;
 }
 
 F();# prints 1222
 
 Now, you can almost explain this by saying that Perl's notion of the
 last match is dynamically scoped, and that the digit variables just
 refer to captured substrings from the last match.
 
 [ Which leaves out a crucial part of the explanation, but at least  
 it's almost correct. ] 
 
 But then there's a second problem: the notional last match isn't
 scoped to the body of the loop either.
 
 #-- local()ized variable --
 
 our $x = 1;
 print $x;
 
 for (1..3) {
   local $x = $x + 1;
   print $x;
 }
 
 print $x;   # output is 12221
 
 #-- digit variable 
 
 1 =~ /(\d)/;
 print $1;
 
 for (1..3) {
   ($1 + 1) =~ /(\d)/;
   print $1;
 }
 
 print $1;   # output is 12341
 
 The actual behavior is more like what you said: the last match
 is saved before loop entry and restored loop exit.  But that's a bit
 of a cheat, since everything else that we call dynamically scoped
 would get saved and restored with each iteration.

Uh-uh. $_ and foreach iterators don't behave that way, nor should they. Look
at what $_ is doing in that example. $1 is doing the same thing.

 
 --
 Steve


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



Re: inline editing non command line

2003-07-21 Thread Jeff 'japhy' Pinyan
On Jul 21, Paul D. Kraus said:

How can you edit a file inline.

By using the $^I and @ARGV variables.

foreach (glob (*.pl){
open ( IN, $_ ) or die (Cannot open file $_ $!\n );
while (IN){
$_ =~ s/dbi:xxx:xxx/dbi:yyy:yyy/;
}
}

Like so:

  {
local @ARGV = glob *.pl;
local $^I = .bak;
while () {
  s/dbi:xxx:xxx/dbi:yyy:yyy/
  print;
}
  }

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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



RE: Regex extraction skipping lines

2003-07-21 Thread Jeff 'japhy' Pinyan
On Jul 21, [EMAIL PROTECTED] said:

 system clear;

Not terribly portable but that is ok.

Neither is 'use Win32::xxx', but that's not the point.  He's writing a
Perl program on (and for use on) a Windows machine.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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



Re: File Find wrinkles

2003-07-21 Thread John W. Krahn
John Goodleaf wrote:
 
 Here's the thing. I've written a script to recurse through a
 directory tree and find all the changed files therein. I've got a db
 file to hold checksums and so forth, but that's beside the point.
 I'm using File::Find to do the recursion for me, but I can't seem to
 figure out how to keep it from recursing through directories I don't
 want. For example, I don't want stuff from dotdirectories or from
 browser caches. I have been trying to use tests to ferret that out,
 but the script seems to read the files anyway.
 snip
 if (-s
  -f

You should use the _ special handle to avoid stat-ing the file more than
once.

   -f _


  $File::Find::dir !~ /[Cc]ache/
  $File::Find::dir !~ /\/\.*\//) {
 
 print DEBUG: File found is : $_\n;
 
 open(FILE, $_) or print REPORT Could not open
 $File::Find::name: $!\n;
 binmode(FILE);
 my $digest=Digest::MD5-new-addfile(*FILE)-hexdigest;
 close FILE;
 Am I barking up the wrong tree? Any suggestion for other useful
 modules?

You want to use $File::Find::prune to bypass subdirectories:

-d  /^\.|[Cc]ache/  ($File::Find::prune = 1)  return;



John
-- 
use Perl;
program
fulfillment

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



question about coderefs

2003-07-21 Thread Kevin Pfeiffer
I'm doing an exercise with coderefs and wondering if there is much 
difference between my answer and the one given...

Here is my subroutine that returns two coderefs...

sub gather_mtime_between {
   my ($start, $stop) = @_;
   my @files = ();
   return (sub {
 my $timestamp = (stat $_)[9];
 if ( -f and $timestamp = $start and $timestamp = $stop) {
push @files, $File::Find::name;
 }
  },
  sub { return @files });
}

The answer given is almost identical (but with error checking for the stat 
call). But it includes variables for the subroutines...

sub gather_mtime_between {
   # etc.
   my $gatherer = sub { #first coderef variable
  # sub much the same
   }
   my $fetcher = sub { # second
  # same
   }
}

In both cases the sub is called like this:
my($gatherer, $yield) = gather_mtime_between($start, $stop);

As I understand this, mine returns two anonymous coderefs and the given 
answer assigns the coderefs to two variables whose contents are then 
returned (and these two variable names go immediately out of scope)? Is 
there any reason to use the variables here?

And while I'm wasting bandwidth... this subroutine needs to always come 
first -- or be in a BEGIN block?

Thanks all!

-- 
Kevin Pfeiffer
International University Bremen

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



RE: date

2003-07-21 Thread wiggins
Please don't top post.


On Mon, 21 Jul 2003 12:25:26 -0700, Jaimee Spencer [EMAIL PROTECTED] wrote:

 Hello, Tim.
 
 Try something like
 
 #!/usr/bin/perl -w
 
 use strict;
 
 system(date);
 

Don't use this method unless you know of a *very* good reason to do it.  

If you are going to shell out to get the date which you shouldn't in the first place, 
at least use a full path to the command, check the return value of system, and if you 
intend to use the date for anything other than printing to stdout then you will want 
to use backticks instead of 'system'.

In general it is less portable, more error prone, slower, and insecure...

See Kevin's post for a better way.

http://danconia.org

 
 -Original Message-
 From: Tim McGeary [mailto:[EMAIL PROTECTED]
 Sent: Monday, July 21, 2003 12:18 PM
 To: [EMAIL PROTECTED]
 Subject: date
 
 
 Is there anyway to get the date from the system in perl?
 
 Tim
 
 
 
 
 -- 
 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: Is $1 ever undefined or set to null?

2003-07-21 Thread Jeff 'japhy' Pinyan
On Jul 21, Bob Showalter said:

Uh-uh. $_ and foreach iterators don't behave that way, nor should they. Look
at what $_ is doing in that example. $1 is doing the same thing.

His examples don't show what you're talking about, and you didn't provide
any examples yourself.  You can't iterate over a list of values for $1 to
get assigned to it, like you can with $_ or any other foreach iterator.

Here's the problem.  The $DIGIT variables are localized to a block, but
they're done so in a manner that I don't think you can achieve in Perl,
without adding an additional block to code:

  ($s = a) =~ /(.)/;
  for (0 .. 2) {
print $1.;
(++$s) =~ /(.)/;
  }

This code prints a.b.c..  One might argue that $1 should be a at the
start of EACH iteration of the block, but this is not the case.  But we
can't make local()ized values persist like that:

  $x = ($s = 10);
  for (0 .. 2) {
print $x.;
local $x = ++$s;
  }

This prints 10.10.10., as it should.  If we wanted it to print
10.11.12., we'd need to do more work:

  {
$x = ($s = 10);
local $x = $x;
for (0 .. 2) {
  print $x.;
  $x = ++$s;
}
  }

This prints 10.11.12., but we had to move the localization outside the
loop.  The localization of the $DIGIT variables is implicit, and seems to
be moved to JUST OUTSIDE the block.

This is the issue.  Why are the $DIGIT variables bound to the block
they're in IN TOTALITY, rather than for the life of the execution of the
block?

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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



Re: question about coderefs

2003-07-21 Thread Todd W.

Kevin Pfeiffer [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 I'm doing an exercise with coderefs and wondering if there is much
 difference between my answer and the one given...

 Here is my subroutine that returns two coderefs...

snip /

 In both cases the sub is called like this:
 my($gatherer, $yield) = gather_mtime_between($start, $stop);

 As I understand this, mine returns two anonymous coderefs and the given
 answer assigns the coderefs to two variables whose contents are then
 returned (and these two variable names go immediately out of scope)? Is
 there any reason to use the variables here?

Both of your examples returned anonymous code refs. Yes, $gatherer and
$fetcher from gather_mtime_between() go out of scope when the subroutine
returns. The reason for using the variables is to make the sub more
readable.

Todd W.



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



RE: Is $1 ever undefined or set to null?

2003-07-21 Thread Jeff 'japhy' Pinyan
On Jul 21, Jeff 'japhy' Pinyan said:

This is the issue.  Why are the $DIGIT variables bound to the block
they're in IN TOTALITY, rather than for the life of the execution of the
block?

It's actually slightly more complex than that.

Here's a piece of code like what Steve wrote:

  sub match {
($1 + 1) =~ /(\d+)/;
print $1;
match() if $1  2;
print $1;
  }

  0 =~ /(\d+)/;
  match();

Now, this code prints 1222.  Odd.  Baffling, even.  Why doesn't it print
1221?  Because the $DIGIT variables are not just magically scoped,
they're magic themselves.  They are connected to the last successful
pattern match, yes, but more importantly, they are DIRECTLY connected to
the last PMOP (an internal structure representing the pattern match).

Even though calling the function creates a new block, the underlying PMOP
is the SAME ONE.  Watch what happens when we do this:

  sub match {
$R++ ? ($1 + 1) =~ /(\d+)/ : ($1 + 1) =~ /(\d+)/;
print $1;
match() if $1  2;
print $1;
  }

  0 =~ /(\d+)/;
  $R = 0;
  match();

It prints 1221.  Why?  Because the second time match() is called, a
DIFFERENT PMOP is used.  It might be confusing, but it's the way things
go.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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



RE: date

2003-07-21 Thread Jaimee Spencer


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Monday, July 21, 2003 1:14 PM
To: Jaimee Spencer; '[EMAIL PROTECTED]'; [EMAIL PROTECTED]
Subject: RE: date


Please don't top post.


On Mon, 21 Jul 2003 12:25:26 -0700, Jaimee Spencer [EMAIL PROTECTED]
wrote:

 Hello, Tim.
 
 Try something like
 
 #!/usr/bin/perl -w
 
 use strict;
 
 system(date);
 

Don't use this method unless you know of a *very* good reason to do it.  

If you are going to shell out to get the date which you shouldn't in the
first place, at least use a full path to the command, check the return value
of system, and if you intend to use the date for anything other than
printing to stdout then you will want to use backticks instead of 'system'.

In general it is less portable, more error prone, slower, and insecure...

See Kevin's post for a better way.

http://danconia.org

Hello, once again.

  Wiggins is right in a way this is dangerous and you should check out
Kevin's post , I would be careful about using variables also,
as $file can contain something that will interpreted
by shell as an additional commands. For example $file might containt
something destructive as '; rm -rf /'.

If you specify a list than system() doesn't use shell and it's usage
is much safer:

system('cat', $file);

This will try to only print file specified by $file variable no matter
what $file contains.

p.s
   Wiggins didn't you just top post?  :o)

 
 -Original Message-
 From: Tim McGeary [mailto:[EMAIL PROTECTED]
 Sent: Monday, July 21, 2003 12:18 PM
 To: [EMAIL PROTECTED]
 Subject: date
 
 
 Is there anyway to get the date from the system in perl?
 
 Tim
 
 
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 


Re: Is $1 ever undefined or set to null?

2003-07-21 Thread Steve Grazzini
On Mon, Jul 21, 2003 at 04:40:19PM -0400, Jeff 'japhy' Pinyan wrote:
 On Jul 21, Jeff 'japhy' Pinyan said:
 
 This is the issue.  Why are the $DIGIT variables bound to the block
 they're in IN TOTALITY, rather than for the life of the execution of the
 block?
 
 It's actually slightly more complex than that.
 
 Here's a piece of code like what Steve wrote:
 
   sub match {
 ($1 + 1) =~ /(\d+)/;
 print $1;
 match() if $1  2;
 print $1;
   }
 
   0 =~ /(\d+)/;
   match();
 
 Now, this code prints 1222.  Odd.  Baffling, even.  Why doesn't it print
 1221?  Because the $DIGIT variables are not just magically scoped,
 they're magic themselves.  They are connected to the last successful
 pattern match, yes, but more importantly, they are DIRECTLY connected to
 the last PMOP (an internal structure representing the pattern match).

You're explaining this much more clearly than I had done, but 
let me jump in again -- 

The magic regex variables *themselves* live forever and don't obey
any scoping rules.  They don't have to worry about scope, since as
you said, they don't contain any data.  Their values are fetched 
dynamically by looking at the last match (which is what I've been
calling PL_curpm, which is the dynamically scoped PMOP pointer).

PL_curpm behaves consistently, although the way it's dynamically
scoped is slightly unusual, as you said.

But the PMOP doesn't contain any data *either*.  It has a pointer
to REGEXP structure, which contains, among other things, the compiled
pattern and what I'll call the match data.  The match data might
include a copy of the target string and offsets for each pair of
capturing parens, and it can be used to calculate the value of $1
or @- (or a host of other variables) dynamically.

The problem with this set-up is that PL_curpm is dynamically
scoped, but the REGEXP, which contains the data we're interested
in, isn't.

Tying the match data to the compiled pattern (and thence to the
PMOP, for pity's sake) is, arguably, bad design...

You can also see it misbehaving here:

my $rx = qr/(...)/;   # REGEXP 1

  foo =~ /$rx/; # PMOP 1 / REGEXP 1
{ bar =~ /$rx/; }   # PMOP 2 / REGEXP 1

print $1;   # bar 

In this one there are two distinct PMOPs (the m// operations) but
only one REGEXP, which is what we've stored in $rx.

When we print $1 the chain of references looks something like

   $1 - PL_curpm - PMOP #1 - $rx - match data

[ Really the PMOP points directly to the REGEXP inside $rx. ]

And the match data inside $rx comes from the time it matched bar,
since there's no mechanism for saving and restoring that kind of
thing.

Anyway, apologies for the blood and perlguts -- 

-- 
Steve

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



Re: Newbie help

2003-07-21 Thread Keith Olmstead
Thanks for all help.

This is what I now have:

#!/usr/bin/perl
my $startdir = /opt/log/hosts/;
use File::Find;
#use strict;
use warnings;
my @dirlist;
 
@logfile = (cron,messages,maillog,ldap);
foreach $log (@logfile) {
sub eachFile {
 if (-e $_  $_ =~ /$log$/) { push @log, $File::Find::name;}
}
 
 
find (\eachFile, $startdir);
}
foreach $file(@log){
system(gzip $file);
print $file done!\n;
 
}

I went a different route.  I am now using File::Find to search for the contents of the 
array @logfile and just gzip them.  Works the same, and easier to manage individual 
logs than direcories.

I now have run into another problem.  It is gziping any of the logs.  I only want it 
to gzip the previous days logs.  I thought about writing something that looks at the 
date and gzips anything with the previous days date, but i am noticing that some logs 
are are written to very often, like mail logs, they have a date stamp of the next day, 
but with a time of 00:00.

Any suggestions?

Again, thanks for the help before.

--Keith

On Thu, 17 Jul 2003, Keith Olmstead wrote:

Date: Thu, 17 Jul 2003 14:51:41 -0500 (CDT)
From: Keith Olmstead [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Newbie help

Hello,

Been searching though this list for awhile now, and now I am needing some help.  I am 
not asking for someone to do my code for me,  I am trying to learn perl and the only 
way for me to do that is to dive staight into it.

My problem is with the theory of the script that I am trying to write.  I am needing 
something to backup logs for me from a central log server.  They layout of these files 
are as follows.

/host/ip/year/month/day/log1, log2, etc

Every file and dir under dir1 is created dynamically by the logging program, syslog-ng.

What I am wanting to do is create a script that will tar and gzip the day dirs at the 
end of the day and remove the dir after it has been backed up.  After the month is 
finished, I would like the same done for it.

Currently there are 20ish host dirs, one of each server that is logging to this box.  
There will be more and when they get pointed to this server, the ip dir will be 
created for that host and each dir under that will also be created for the 
corresponding date.  The logs need to be kept for 2-3 months, and then deleted.

I am needing help thinking this script out, maybe get ideas of how to set it up.  From 
reading using File::Find, might be useful.  

I was thinking about writing a script that runs in cron each night that tars and gzp 
the log dirs.  Currently I have a script that is getting a list of the dir, but I 
don't really know  where to go from there.  I need to get it to dive into the dir to 
the day lvl and archive the previous days logs.

Here are 2 scripts that I have been playing with.  I don't even know if I am going in 
the right direction.

#!/usr/bin/perl
use strict;
use warnings;
 
my $dir = '/opt/log/hosts/';
 
opendir(DIR, $dir) or die Cannot open Directory;
 
# read the dir contents into a list, and grep out the . and .. dir entries
my @entries = grep (!/^\.\.?$/ , readdir (DIR));
closedir(DIR);
foreach (@entries)
{
  print $_\n;
}

and

#!/usr/bin/perl
 
use File::Find;
use strict;
use warnings;
my $startdir = $ARGV[0];
my @dirlist;
find(
sub {
return if -d and /^\.\.?$/;
push @dirlist, $_ if -d;
}, $startdir);
 
#my $file_list = join 'BR', @dirlist;
my $file_list = @dirlist;
print $file_list;

Like I said before, I am not asking for someone to do my work just some guidiance in 
the right direction.

TIA,

Keith Olmstead






-- 


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



Re: Regex extraction skipping lines

2003-07-21 Thread Wiggins d'Anconia
Jeff 'japhy' Pinyan wrote:
On Jul 21, [EMAIL PROTECTED] said:


system clear;
Not terribly portable but that is ok.


Neither is 'use Win32::xxx', but that's not the point.  He's writing a
Perl program on (and for use on) a Windows machine.
How was that determined? His original script didn't have any 'use 
Win32:xxx's in it, I was actually thinking it wasn't portable to windows 
since I wasn't aware 'clear' was available there.  It was meant more as 
a pointer rather than an issue, hence the words Not terribly and that 
is ok, as opposed to you should never do this

Just trying to prevent overuse of 'system' when it isn't needed, 
probably because of the code I had to look at for the last 6 months 
before I got to change it all ;-).

http://danconia.org

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


Re: Appending File

2003-07-21 Thread Wiggins d'Anconia
Jonathan Dwerryhouse wrote:
Hi,

Could someone point me in the right direction?

I'd like to write a programme in Perl that will prompt questions and dump the answers into a templated piece of text.  E.g:

Userjonathan
Passwordshampoo
Call ID 8007835373
Each time i only want to change the user and password but inject it back into this basic template.  

Also, is there a way for the script to prompt for the questions and with the provided answers, append the file?

I am somewhat confused on what you are attempting to do, you use the 
words inject append and dump, so we need to figure out a little 
more clearly what you are after.

Are you trying to change the values of the file as they currently are in 
place? Or are you trying to add the values combined with the template 
onto the end of a list? Or are you trying to create a new file similar 
to the template based on the format of the template with the new values 
added?

In any of the cases you are probably going to need the read, write and 
maybe append modes of 'open'. So you may want to start here:

perldoc perlopentut
perldoc -f open
As for your first question there are tons of ways to do that, Something 
simple like the following:

- UNTESTED -

my $value = '';
while ($value eq '') {
  print Please enter 'y' or 'n':\n;
  my $input = STDIN;
  chomp $input;
  # test for valid input, for example a yes or no answer
  if (($input =~ /^y/i) || ($input =~ /^n/i)) {
  $value = $input;
  }
  else {
  print Invalid entry: $input. Try again.\n;
  }
}
Or you can get as complex as needed, using modules from CPAN that handle 
terminal input, or CLI creation, etc.

http://danconia.org

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


RE: writing to file

2003-07-21 Thread Charles K. Clarkson
awarsd [EMAIL PROTECTED] wrote:
:
: I'm curious to know if it is possible to write
: to file with overwritting information without
: putting into an array if i have in a file
:
: a
: b
: c
: d
: e
: and i want to add  g-r-t-u-x i would get
: now in the file
:
: g
: r
: t
: u
: x
: e -- stays the same no overwrite.

Wrong. the original file has 5 lines and e
is the fifth line. The new file has 6 lines and
e is the sixth line. Line 5 has been overwritten
with x.

Why not tell us what you really want instead
of these letters?


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328


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



perl/tk compiling problem

2003-07-21 Thread aaron barclay
Hi all,

Have a question about compiling perl/Tk (please let me know if there is 
a more appropriate list for this - I could not find one).

I have attempted to compile

Tk800.015
Tk800.023
Tk804.024
all with the same errors. During compilation I get messages like these

[EMAIL PROTECTED] Tk800.015]# perl Makefile.PL
/usr/bin/perl is installed in 
/usr/lib/perl5/5.8.0/i386-linux-thread-multi okay
PPM for perl5.008
Test Compiling config/signedchar.c
Test Compiling config/Ksprintf.c
Test Compiling config/tod.c
Test Compiling -DTIMEOFDAY_TZ config/tod.c
TZ gettimeofday()
Using -L/usr/X11R6/lib to find /usr/X11R6/lib/libX11.so.6.2
Using -I/usr/X11R6/include to find /usr/X11R6/include/X11/Xlib.h
Skip Tkperl on x
Checking if your kit is complete...
Looks good
Note (probably harmless): No library found for -lpt
Generating Dependencies for linux, win_arch=x
Test Compiling config/Hstrtoul.c
Test Compiling config/Hstrdup.c
Test Compiling config/Hstrcasecmp.c
Extracting tkGrid.c
panic: end_shift at ../pTk/Tcl-pTk line 55,  line 584.

Then, when I attempt make I get the following error:

[EMAIL PROTECTED] Tk804.024]# make
Makefile:95: *** missing separator.  Stop.
I am using a dell Inpiron8200 with redhat.

Any help at all would be greatly appreciated. I am sure I am missing 
something simple due to lack of experience.

Thanks in advance.

aaron.

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


Re: subroutines

2003-07-21 Thread Stuart White
I tried reading the perldoc, but it came up all screwy
on my screen.  Lines ran over the end.  I'm having
trouble passing variables into a subroutine.Also,
once I get it passed, I want to pass it from there
back to the main function.  Can someone help me figure
this out?  This is the code that I have:

#!/usr/bin/perl

#
# Subroutine prototypes

sub FoulParser($$$);
#
# Main Program
#

use warnings;
use strict;
 
open(STATS, stats.txt) or die statfile\n;
#my %fouls; 
#my ($type, $totalFouls);
my $foul; 

#my $total;
my $foultype;
my $player;
my @stuff;
 while (STATS)
 {
if ($_ =~ /(\w+) (Foul:) (\w+)/)
#if ($_ =~ /Foul/)
{
 $foul = $_;
 $player = $1;
 $foultype = $3;
 print line to be passed: $foul; 
  # %fouls =  FoulParser($foul, $player, $foultype); 
FoulParser($foul, $player, $foultype);
  }
}


# Subroutine Definitions
###

sub FoulParser($$$)
{ 
 #my %foulsData;
 #my %fouls;
 my ($foul, $typefoul, $player, @stuff);
 # $fouls{$foultype}{$player}++;
 print from sub, passedLine: $foul\n;
 $stuff[0] = $foul;
 $stuff[1] = $typefoul;
 $stuff[2] = $player;
 #STDIN;
 print sub this arra: @stuff\n;
 return @stuff;
}







--- John W. Krahn [EMAIL PROTECTED] wrote:
 Stuart White wrote:
  
  Hello all,
 
 Hello,
 
  I seem to be stuck on subroutines.  I've read the
 Perl
  for Beginners Wrox chapter on them, and I'm still
 a
  bit lost.
 
 The first thing that you should read is the
 documentation supplied with
 Perl.  The document describing subroutines is
 perlsub.pod.
 
 perldoc perlsub
 
 
  My problem is passing a scalar to a
  subroutine, doing calculations therein, and then
  returning a value; or basically, subroutines in
  general.
 
 Subs in Perl are pretty simple.  All arguments to
 the sub are flattened
 to a list and are available inside the sub in the @_
 array but be
 careful because modifying the contents of @_ will
 modify the contents of
 the original variables.  All return values are also
 flattened to a list
 when the sub ends.
 
 
 John
 -- 
 use Perl;
 program
 fulfillment
 
 -- 
 To unsubscribe, e-mail:
 [EMAIL PROTECTED]
 For additional commands, e-mail:
 [EMAIL PROTECTED]
 


__
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

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



Re: writing to file

2003-07-21 Thread denis
open the file with 
This will cause an overwrite..


On Mon, 21 Jul 2003, awarsd wrote:

 Hi,
 
 I'm curious to know if it is possible to write to file with overwritting
 information without putting into an array
 if i have in a file
 a
 b
 c
 d
 e
 and i want to add  g-r-t-u-x i would get
 now in the file
 g
 r
 t
 u
 x
 e -- stays the same no overwrite.
 
 any help is appreciated
 Anthony
 
 
 
 


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



Is there a better way?

2003-07-21 Thread denis

I know I'm missing something here, but this code just looks to me like I 
shloud be doing it a better way..

Any ideas?


# -N
print Number of Hosts?  ;
# get user input and strip off CR-LF
chomp($n=);
$intel_num_hosts = join ( , -N,$n);
# if user did not enter a value, dont put the -N in
if ($n eq ){ $intel_num_hosts = }

# -n
print Number of processes?  ;
chomp($n=);
$intel_num_procs = join ( , -n,$n);
if ($n eq ){ $intel_num_procs = }

Thanks

Denis













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