running CGI locally??

2004-03-04 Thread Freimuth,Robert
Hello,

I have very little experience with web programming, and even less with CGI,
so I'm really in need of help here.

I have an application that runs in batch mode and generates 5 output files
for every input file (all are flat text, and each of the 5 is in a different
directory).  I would like to build a simple browser-based UI that provides
links to each output file, so they can be opened and examined efficiently at
the end of a run, without forcing the user to navigate through directories
and search through output files from other runs.  In addition, I would like
to include links to the most recent output file of each type, in the event
that the user wants to review the results from an old run and then link to
the most recent output.  (Sorry if that's not clear...)  I know how to
collect the filenames I need - my problem is with the display.

Since I'm trying to generate dynamic HTML pages, I thought CGI would be the
way to go.  However, from what I understand of CGI, it requires a web server
and can't be run locally.  Since all of my code is in perl, I would prefer to
stick with it, if possible.  A coworker suggested java as an alternative, but
then I'd have to learn it first.  :)

Any ideas on how to do something like this are appreciated.  If this idea of
a UI is ludicrous, I'm open to others!

Thanks,

Bob

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




RE: running CGI locally??

2004-03-04 Thread Charles K. Clarkson
Freimuth,Robert [EMAIL PROTECTED] wrote:

: I have very little experience with web programming, and even less
: with CGI, so I'm really in need of help here.

Let's clarify some terminology. CGI is the Common Gateway
Interface. It is language independent. For the most part, web
programming is done through the CGI.


: I have an application that runs in batch mode and generates 5 output
: files for every input file (all are flat text, and each of the 5 is
: in a different directory).
: I would like to build a simple browser-based UI that provides links
: to each output file, so they can be opened and examined efficiently
: at the end of a run, without forcing the user to navigate through
: directories and search through output files from other runs.  In
: addition, I would like to include links to the most recent output
: file of each type, in the event that the user wants to review the
: results from an old run and then link to the most recent output.
: (Sorry if that's not clear ...)  I know how to collect the filenames
: I need - my problem is with the display.

You mention above that you have some web programming experience.
What are you experienced in?


: Since I'm trying to generate dynamic HTML pages, I thought CGI would
: be the way to go.  However, from what I understand of CGI, it
: requires a web server and can't be run locally.

Since CGI is an interface between a program on a server and a
browser it would by definition need a server. Many perl CGI programs
can be tested from the command line. I tested my perl programs from
the command line for about a year before I installed a local copy of
Apache.


: Since all of my code is in perl, I would prefer to stick with it, if
: possible.  A coworker suggested java as an alternative, but then I'd
: have to learn it first.  :)

Your Java program would still need the CGI to interact with the
browser.


: Any ideas on how to do something like this are appreciated.
: If this idea of a UI is ludicrous, I'm open to others!

You may be able to install a web server on your local computer.
You haven't mentioned the intended platform. Tell us what that
OS is and what OS is no your local box and we can help point you in
the right direction.

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: running CGI locally??

2004-03-04 Thread Freimuth,Robert
 : I have an application that runs in batch mode and generates 5 output
 : files for every input file (all are flat text, and each of the 5 is
 : in a different directory).
 : I would like to build a simple browser-based UI that provides links
 : to each output file, so they can be opened and examined efficiently
 : at the end of a run, without forcing the user to navigate through
 : directories and search through output files from other runs.  In
 : addition, I would like to include links to the most recent output
 : file of each type, in the event that the user wants to review the
 : results from an old run and then link to the most recent output.
 : (Sorry if that's not clear ...)  I know how to collect the filenames
 : I need - my problem is with the display.
 
 You mention above that you have some web programming experience.
 What are you experienced in?

I'm a biologist by training.  My programming experience is mostly with perl
(data mining and parsing), although I worked briefly with C and VB a few
years ago.  I've got a bit of experience with HTML (very basic) and
posting/retrieving data to/from web servers (LWP), but only what I've learned
by necessity.

 : Since I'm trying to generate dynamic HTML pages, I thought CGI would
 : be the way to go.  However, from what I understand of CGI, it
 : requires a web server and can't be run locally.
 
 Since CGI is an interface between a program on a server and a
 browser it would by definition need a server. Many perl CGI programs
 can be tested from the command line. I tested my perl programs from
 the command line for about a year before I installed a local copy of
 Apache.

I was hoping I could use the local computer as the 'server', and use CGI (or
something else) as a method of highly targeted directory/file navigation.

 : Any ideas on how to do something like this are appreciated.
 : If this idea of a UI is ludicrous, I'm open to others!
 
 You may be able to install a web server on your local computer.
 You haven't mentioned the intended platform. Tell us what that
 OS is and what OS is no your local box and we can help point you in
 the right direction.

I would really like to keep the number of dependencies to a minimum, so users
don't need to install a lot of other software and try to configure
everything.  My app is intended to be standalone, with perl (and a few
non-core modules from CPAN) as the only requirements.

I would guess the majority of my target user group (biologists) will be using
Winxx, although I'm sure there will be the occasional *nix user also.  I work
on a Windows XP machine, but I also have a boot option to linux that I use
occasionally.

To clarify my description above, I was envisioning a navigation system with a
layout similar to the ActiveState perl docs (two frames, with the TOC in the
left frame and the actual docs in the right frame).  In my case, the list of
genes that were analyzed in a given run would appear on the left, and
selecting (clicking on) a gene would produce a list of the output files from
that analysis in the right frame.  The output filenames would in turn link to
the actual output file.  In addition to the files produced in a given run,
I'd like to add links to the most recent output files produced, regardless of
run (the files can be created asynchronously, since different parts of the
program can be run independently).  Since the most recent filenames will
change over time, creating a static HTML file for each gene after each run
won't work.  Hence, my thoughts of using CGI (or similar) to query the output
files that are available in each directory and create the pages on the fly.  

I'm sure someone else can come up with a better method than the one I
described.  Thanks for all your help.

Bob

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




RE: running CGI locally??

2004-03-04 Thread Teresa Raymond
Hi,
I think what you are trying to do is imminently accomplishable with Perl if 
you are putting the interface on the web. With that being said, would you 
be sending this program to others or would they access a website to find 
the information? I don't how to write standalone Perl applications but if 
you are running a website, then you can test your scripts either by the 
command line as suggested or download the appropriate flavor of the free 
Apache web server (http://www.apache.org) to your computer. I have a WinXP 
myself and have both Perl and Apache locally but also am a relative newbie, 
but here's my stab at the possible code anyway for my own learning 
experience and I hope this helps somewhat. Remember too that you need to 
learn how to secure your CGI programs -- someone else needs to help with 
that. Anyone with criticism of this partial pseudoCode?

=PseudoCODE
#shebangLine, warnings and taint turned on
use CGI; # use the CGI.pm module installed with current versions of Perl 
library: some CGI.pm help (http://stein.cshl.org/~lstein/)
use CGI::Carp 'fatalsToBrowser';
use strict;

my $query = new CGI;

my $filename = $query - param('nameOfInputFieldWithFileName'); #if you 
give the name of the files in your html
my $geneticCodeToSearchFor = $query - 
param('geneticCodeToSearchForFromFormInputField');

print Content-type: text/html \n\n;

unless (param) #type in your conditional or if you want all input fields 
filled out use code as is
{
#BEGIN HTML
print PrintHTML;
html
head
titleSearch the Files/title
/head
body
form method=post action=cgi-bin/nameOfThisCGIScript
input type=text size=50 name=nameOfInputFieldWithFileName
input type=text size=100 
name=geneticCodeToSearchForFromFormInputField
input type=submit value=Submit
input type=reset value=Clear Form
/form
/body
/html
PrintHTML
#END HTML, you can use anything with print statement like EOF
#but it has to be spelled exactly the same (case matters) at the print 
statement and at the end of your html tags
#In this case, PrintHTML has to be on it's own line, by itself with only a 
carriage return
}
else
{
print PrintHTML;
html
headtitleAlert!/title/head
bodyh1All form fields must be filled out./h1
pPlease fill out the form a href=nameOfThisCGIScriptClick 
Here/a/p
/body
/html
PrintHTML
exit(0);
}

my @filepath = qw/ filepathToDirectory1 filepathToDirectory2 
filepathToDirectory3/;
my $filesInDirectory = 0;
my $match = 'no';
#CODE for searching directories for $file
#Loop through @filepath array, increment $filesInDirectory until 
reach end of @filepath array
#CODE to open $filepath[$filesInDirectory]
#Create hash with $filepath[$filesInDirectory]
# if ($filepath[$filesInDirectory] =~ 
/$filename/ig) #if you gave file name options
#if you didn't give filename 
options, loop through the hash then open, slurp, close each file
#CODE for opening $file, slurping 
$file, closing $file
#CODE for searching contents of $file
if (geneticCodeInFile =~ 
/$geneticCodeToSearchFor/ig)
$match = 'yes';
print 
htmltitleGenetic Code Found/title;
print 
bodyp$filename/p/body/html;
else {$match = 'no'}

if ($match = 'no)
{
print PrintHTML;
# type your html tags and messages here
a href=nameOfThisCGIScriptSearch Again/a
# rest of html tags
PrintHTML
}
=PseudoCODE
At 10:35 PM 3/4/2004, you wrote:
 : I have an application that runs in batch mode and generates 5 output
 : files for every input file (all are flat text, and each of the 5 is
 : in a different directory).
 : I would like to build a simple browser-based UI that provides links
 : to each output file, so they can be opened and examined efficiently
 : at the end of a run, without forcing the user to navigate through
 : directories and search through output files from other runs.  In
 : addition, I would like to include links to the most recent output
 : file of each type, in the event that the user wants to review the
 : results from an old run and then link to the most recent output.
 : (Sorry if that's not clear ...)  I know how to collect the filenames
 : I need - my problem is with the display.

 You mention above that you have some web programming experience.
 What are you experienced in?
I'm a biologist by training.  My programming experience is mostly with perl
(data mining and parsing), although I worked briefly with C and VB a few

Re: Metacharacter problem in regexp

2004-03-04 Thread Petri Rautakoski
I already tried that, but it didn't work for me, don't know why.
The \Q$pattern\E worked so my problem is solved.

Petri

 Petri Rautakoski wrote:
 
  
  $text =~ s|for example \(this\)|$toBeReplaced|;
  
  works fine, but how can I backslash the metacharacters in a scalar?
 
 Lookup quotemeta
 
 qr//;
 
 -Bill-
 __Sx__
 http://youve-reached-the.endoftheinternet.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: Exit

2004-03-04 Thread NYIMI Jose (BMB)
Thanks Rod for your great help in this list.
I was always impressed by your elegant coding.
You are one the best Perl Programmer I have seen.
And I learned a lot from you, thanks !

Wish you all the best for the future ...

José.

-Original Message-
From: Rob Dixon [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 03, 2004 7:18 PM
To: [EMAIL PROTECTED]
Subject: Exit


I hope, and think, that I've helped several people to
be more eloquent in Perl.

The language fascinates me in the way that nearly all
who can speak can use it: thanks to Larry, who knew
before we did what a programming language should have been.

I remain available through my email address, but I have
other, rather sad things to do. Thank you all for your intelligent questions and 
elaborations.

/R



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




 DISCLAIMER 

This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer.

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


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




Re: Reformatting the Date

2004-03-04 Thread Morten Liebach
On 2004-03-03 11:54:51 +0200, John wrote:
 I receive the date from the Oracle as DD/MM/YY and i want to insert
 that date in a mysql date field.
 
 I know that mysql date form is -MM-DD.
 
 Well, do you know if there is any date function to do the job?

Yes, Date::Manip, it can do almost anything with dates.

 Morten

-- 
http://m.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: Reformatting the Date

2004-03-04 Thread John
I fix it that with an Oracle Function (to_char()).

Thank you


- Original Message - 
From: Morten Liebach [EMAIL PROTECTED]
To: Perl Beginners [EMAIL PROTECTED]
Sent: Thursday, March 04, 2004 11:03 AM
Subject: Re: Reformatting the Date


 On 2004-03-03 11:54:51 +0200, John wrote:
  I receive the date from the Oracle as DD/MM/YY and i want to insert
  that date in a mysql date field.
  
  I know that mysql date form is -MM-DD.
  
  Well, do you know if there is any date function to do the job?
 
 Yes, Date::Manip, it can do almost anything with dates.
 
  Morten
 
 -- 
 http://m.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
 
 
 


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




RE: Exit

2004-03-04 Thread NYIMI Jose (BMB)
Thanks Rob for your great help in this list.
I was always impressed by your elegant coding.
You are one the best Perl Programmer I have seen.
And I learned a lot from you, thanks !

Wish you all the best for the future ...

José.

-Original Message-
From: Rob Dixon [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 03, 2004 7:18 PM
To: [EMAIL PROTECTED]
Subject: Exit


I hope, and think, that I've helped several people to
be more eloquent in Perl.

The language fascinates me in the way that nearly all
who can speak can use it: thanks to Larry, who knew
before we did what a programming language should have been.

I remain available through my email address, but I have
other, rather sad things to do. Thank you all for your intelligent questions and 
elaborations.

/R



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




 DISCLAIMER 

This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer.

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


-- 
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: Exit

2004-03-04 Thread Gabor Urban
We'll miss you, shure

Gabaux
Linux is like a wigwam: no gates, no windows, and an apache
inside!

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




Re: PERL concatenating directory names

2004-03-04 Thread PerlDiscuss - Perl Newsgroups and mailing lists
I'm on a Windows 2000 environment - and yes, I agree that using the PERL
conventions would be best.  Unfortunately, there is a specific request for
this command to be used in this basic format.  I've used the command in a
shell script (.sh) and it works fine, but no luck in PERL.

If you have any more suggestions I will be glad to try them - if not, I
thank you for your reply.

K

Rob Dixon wrote:

 [EMAIL PROTECTED] wrote:

 By the way,

  I'm having a problem when redirecting output from a system call to a text
  file.  A good example would be:
 
  command.com /c dir /O /a-d /s  dir.txt
 
  When I run this directly from the command line I will get the full path
  structure in the output file.  When I call this from a perl script in the
  form:
 
  system ('command.com /c dir /O /a-d /s  dir.txt');
 
  the output to the text file concatentates directory names longer than 8
  characters to 8 characters.  My desire is to have the output explicitly
  state the full path rather than the concatenation.
 
  Any ideas what I need to do to overcome this problem?

 Which Windows system are you working on? On my XP and 98
 systems this call returns the 8.3 file name in the first few
 characters of each column and the full file name at the end,
 whether it's a directory or a regular file.

 Anything that's written in native Perl is best in my book, so
 you really should read about reading directories with

   perldoc -f opendir
   perldoc -f readdir
   perldoc -f closedir

 But if you just need to traverse a directory tree then take a
 look at

   perldoc File::Find

 HTH,

 Rob



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




Problm encountered in using DBI

2004-03-04 Thread Nilay Puri, Noida
Hi All,

I am trying to connect to ORACLE thru perl
I have included use DBI.

On running script I get this error .

install_driver(Oracle) failed: Can't load
'/usr/local/lib/perl5/site_perl/5.005/sun4-solaris/auto/DBD/Oracle/Oracle.so
' for module DBD::Oracle: ld.so.1
: /usr/local/bin/perl: fatal: libclntsh.so.1.0: open failed: 
No such file or directory at
/usr/local/lib/perl5/5.00503/sun4-solaris/DynaLoader.pm line 169.

So, i guess libclntsh.so.1.0 is not present in the UNXI box.

When i searched for it, i was not able to find it.


I am rigth in my approach to the problem, how do i get the file in first of
all.

Thanks,
Nilay

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




problem in array accessing

2004-03-04 Thread N, Guruguhan \(GEAE, Foreign National, EACOE\)
Hi All,
   I have written a perl code for filtering data contained in a file 
($input_file_name) based on the filter expression($expr). While doing this, I face 
some problems. When I hard code the arrays @data and @col ( in red color) in the code, 
I am getting the results. But the moment I get the arrays @col and @data based on the 
user input file ($input_file_name) inside the if loop, there is no filter. The 
reason is @data array inside the if loop (red colored) when accessed outside has 
only one value and that doesn't satisfy the filter expression. Then I changed it look 
like the one given in blue color. Now I don't know how should I modify
1. the sub routine sub filterdata 
2. my @result array 
3. print join function 
All the three are highlighted in blue color.

Can some one please suggest me what changes I have to do, so that I can get the 
results? Any help in this regard is solicited.


#! /usr/bin/perl -w
use strict; #- matter of style
use warnings;   #- and again

my (@col,@data,$input_file_name,@temp,$header,$data_line,$i);
$input_file_name= MC_data.dat;

   if (-s $input_file_name ) {
open(INPUT, $input_file_name) || die Cannot open: \nReason: $!\n;
@temp = INPUT ;
chomp @temp;
$header = shift(@temp);
$header =~ s/^\s+(.*)/$1/; #Remove the leading white spaces
@col = split /\s+/, $header;

foreach $i ( 0 .. $#temp ) {
$data_line = $temp[$i];
$data_line =~ s/^\s+(.*)/$1/; #Remove the leading white spaces
@data = split /\s+/, $data_line;
$data[$i] = split /\s+/, $data_line;
}
   }

@col = qw (RUN a1 a2 a3 weight sig1 sig2 sig3);

@data=(
  [qw( 1   0.20   0.20   0.20   0.76568575881.9
29289.3 -46592.6)],
  [qw( 2   0.200345   0.20   0.200345   0.9175766.0
29268.4 -46497.6)],
  [qw( 3   0.20   0.200345   0.20   0.76603075867.1
29259.8 -46607.4)],
  [qw( 4   0.359575   0.253987   0.359575   1.27101943898.7
19675.6 -24223.1)],
  [qw( 5   0.359921   0.253987   0.359921   1.27199543861.3
19666.1 -24195.2)]
);

map{ my $i=$_; no strict 'refs'; *{filter::$col[$i]} = sub{$_-[$i]} }
0..$#col;


sub filterdata
{
my $cref=shift;
grep $cref,@_
}


sub filterspec
{
my $e = shift;
map{ $e =~ s/\b$_\b/filter::$_()/g } @col;
eval sub{ $e }
}

my $expr = weight  1.2  sig1  75800;


my $filter_handler = filterspec( $expr ) or die $@;

my @result = filterdata ($filter_handler,@data);  

print join($/,map{join( ,@$_)[EMAIL PROTECTED]).$/;

Thanks
Regards
Guruguhan
EACoE, India.


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




RE: Problm encountered in using DBI

2004-03-04 Thread Nilay Puri, Noida
No, I am on Sun Solaris m/c

And i have find out that I have libclntsh.so while the errro that script
throws is for libclntsh.so.1.0
So, any hint how to go about it Solaris experts ?

thanks

-Original Message-
From: Urvashi Mishra [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 04, 2004 5:04 PM
To: Nilay Puri, Noida
Subject: Re: Problm encountered in using DBI


If u are working in windows .. then i guess you have t6o do system dsn
settings...

- Original Message -
From: Nilay Puri, Noida [EMAIL PROTECTED]
To: Perl List (E-mail) [EMAIL PROTECTED]
Sent: Thursday, March 04, 2004 4:45 PM
Subject: Problm encountered in using DBI


 Hi All,

 I am trying to connect to ORACLE thru perl
 I have included use DBI.

 On running script I get this error .

 install_driver(Oracle) failed: Can't load

'/usr/local/lib/perl5/site_perl/5.005/sun4-solaris/auto/DBD/Oracle/Oracle.so
 ' for module DBD::Oracle: ld.so.1
 : /usr/local/bin/perl: fatal: libclntsh.so.1.0: open failed:
 No such file or directory at
 /usr/local/lib/perl5/5.00503/sun4-solaris/DynaLoader.pm line 169.

 So, i guess libclntsh.so.1.0 is not present in the UNXI box.

 When i searched for it, i was not able to find it.


 I am rigth in my approach to the problem, how do i get the file in first
of
 all.

 Thanks,
 Nilay

 --
 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: Metacharacter problem in regexp

2004-03-04 Thread John W. Krahn
Petri Rautakoski wrote:
 
 Hi!

Hello,

 I'm making a text replace and my text to search includes a metacharacter (.
 The text to be searched has been stored in a scalar for example $search.
 The text where the search will be made has been stored for example in a scalar
 $text. Here is what I'm doing:
 
 $search = for example (this);
 $text = looking for example (this);
 $toBeReplaced = that;
 
 $text =~ s|$search|$toBeReplaced|;
 
 That doesn't work, if you make it this way:
 
 $text =~ s|for example \(this\)|$toBeReplaced|;
 
 works fine, but how can I backslash the metacharacters in a scalar?

If you are just searching for plain text strings then you can do this instead:

substr $text, index( $text, $search ), length( $search ), $toBeReplaced;


John
-- 
use Perl;
program
fulfillment

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




RE: Problm encountered in using DBI

2004-03-04 Thread NYIMI Jose (BMB)
Try following commands and tell us what you see for each of them:

1)
ldd -s /usr/local/lib/perl5/site_perl/5.005/sun4-solaris/auto/DBD/Oracle/Oracle.so

2)
perl -v

3)
/usr/local/bin/perl -v

4)
perl -e 'use DBD::Oracle;'

5)
/usr/local/bin/perl -e 'use DBD::Oracle;'


José.
-Original Message-
From: Nilay Puri, Noida [mailto:[EMAIL PROTECTED] 
Sent: Thursday, March 04, 2004 12:46 PM
To: Urvashi Mishra
Cc: Perl List (E-mail)
Subject: RE: Problm encountered in using DBI


No, I am on Sun Solaris m/c

And i have find out that I have libclntsh.so while the errro that script throws is for 
libclntsh.so.1.0 So, any hint how to go about it Solaris experts ?

thanks

-Original Message-
From: Urvashi Mishra [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 04, 2004 5:04 PM
To: Nilay Puri, Noida
Subject: Re: Problm encountered in using DBI


If u are working in windows .. then i guess you have t6o do system dsn settings...

- Original Message -
From: Nilay Puri, Noida [EMAIL PROTECTED]
To: Perl List (E-mail) [EMAIL PROTECTED]
Sent: Thursday, March 04, 2004 4:45 PM
Subject: Problm encountered in using DBI


 Hi All,

 I am trying to connect to ORACLE thru perl
 I have included use DBI.

 On running script I get this error .

 install_driver(Oracle) failed: Can't load

'/usr/local/lib/perl5/site_perl/5.005/sun4-solaris/auto/DBD/Oracle/Oracle.so
 ' for module DBD::Oracle: ld.so.1
 : /usr/local/bin/perl: fatal: libclntsh.so.1.0: open failed: No such 
 file or directory at 
 /usr/local/lib/perl5/5.00503/sun4-solaris/DynaLoader.pm line 169.

 So, i guess libclntsh.so.1.0 is not present in the UNXI box.

 When i searched for it, i was not able to find it.


 I am rigth in my approach to the problem, how do i get the file in 
 first
of
 all.

 Thanks,
 Nilay

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




 DISCLAIMER 

This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer.

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


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




jump out of conditional loop

2004-03-04 Thread stephen kelly
hi there
what syntax do i use to jump out of a conditional loop
for c/java it break; return; what is it in perl syntax

thx
steve



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




Re: jump out of conditional loop

2004-03-04 Thread Beau E. Cox
On Thursday 04 March 2004 02:02 am, stephen kelly wrote:
 hi there
 what syntax do i use to jump out of a conditional loop
 for c/java it break; return; what is it in perl syntax

 thx
 steve

while( ... ) {  # or for, foreach, etc.
  ...
  last; # == break
  ...
  next; # == continue
  ...
}

Aloha = Beau;


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




Re: jump out of conditional loop

2004-03-04 Thread zsdc
stephen kelly wrote:

hi there
what syntax do i use to jump out of a conditional loop
for c/java it break; return; what is it in perl syntax
perldoc -f last

   last LABEL
   lastThe last command is like the break statement
   in C (as used in loops); it immediately exits the
   loop in question.  If the LABEL is omitted, the
   [...]
--
ZSDC


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



packages and variables

2004-03-04 Thread Ralf Schaa
Cheers all,

i am doing my first steps with writing packages/modules and of course 
there are problems:

the module holds a variable in a subroutine. this variable i like to 
pass to the callerprogram,
so it is in the @EXPORT_OK  and even in the @EXPORT. So far so good, i 
thought!
but nothing happens when i run the caller-program...

i  tried also defining with 'my ..' , or without 'use strict' ...

somebody has the clue?

thanx
-ralf
the module 'testMod.pm''
#==
package testMod;
use strict;
use Exporter;
our @ISA   = (Exporter);
our @EXPORT= qw($test testThis);
our @EXPORT_OK = qw($test testThis);
sub testThis{ our $test = test;}
1;
the caller-program 'test.pl'
#==
use lib E:/ddswork/process_data/_makeLevel2;
use testMod qw(testThis $test);
use strict;
print 1: $testThis::test\n;
print 2: $test\n;
== nothing is printed...

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



Help me out!!!

2004-03-04 Thread Urvashi Mishra
hi !

i am trying to implement multidimentional tree... and saw that a package called 
Tree::Nary already exits...

i am use the above module and i am getting the following error ...
Can't locate Tree/Nary.pm [EMAIL PROTECTED]  @INC contains: C:\perl\site\lib.
i have saved this module in this dir but its not working
if someone can help me??



Re: Reading File grep according item 5 and sorting

2004-03-04 Thread Bjorn Van Blanckenberg
On 3-mrt-04, at 09:56, R. Joseph Newton wrote:

Bjorn Van Blanckenberg wrote:


#!/usr/bin/perl

use strict;
use Getopt::Long;
GetOptions(\my %opt, 'filepath=s');

my $filepath = (%opt-{'filepath'});

my @fields = ();
my @sorted = ();
my $lastbit = 1;
my @bits = ();
open(INFILE,$filepath);

chomp(@fields = INFILE);

@sorted =
map { $_-[0] }
sort { $a-[5] cmp $b-[5] }
map { [ $_ , (split /\t/) ] } @fields;
foreach (@sorted){
@bits = split;
print \n if ($bits[4] ne $lastbit);
print $_\n;
$lastbit=$bits[4];
}
this is what I have know
Do you mind explaining a little about how the code you have so far 
accomplishes
its task.  It looks very similar to the example code posted on this 
thread.  If
I am not mistaken, the code was posted to encourage you to understand 
how those
operations work

but al it does is sorting according item 5 but
want it to look in all the items of column 5 and if it contains item 5
print it in one block and then the next block separated with an return
so that
Huh?

one  title   state   name   testing   number
two  title2   state2   name2   final   number2
one  title3   state3   name3   pre   number3
four  title4   state4   name4   tesing2   number4
six  title5   state5   name5   testing3   number5
dip  title6   state6   name6   pre2   number6
fun  title7   state7   name7   final2   number7
becomes

one  title   state   name   testing   number
four  title4   state4   name4   tesing2   number4
six  title5   state5   name5   testing3   number5
two  title2   state2   name2   final   number2
fun  title7   state7   name7   final2   number7
one  title3   state3   name3   pre   number3
dip  title6   state6   name6   pre2   number6
I don't quite understand.  In column 5, I see number, number4, , 
number5, then
back to number2.  Likewise with column 2:  I see state, then state2, 
thenOh,
I see [banging forehead with wet rutabaga]  you're using 1-based 
indexing.  So
you are calling column 0 column 1, etc.  OK.  Please warn us when you 
do that.

It sounds like you are going to need to do this in two steps, first 
getting the
groupings, then sorting each grouping in turn.   Unfortunately, I find 
it almost
impossible to understand cryptic coding style as you use above, but if 
you can
eplain how the code above is working for you, we can probably help you 
extend
that process to do the sub-sort on each grouping

Joseph


I understand how the code works

It reads the file end split every line according to the tabs and then 
sorts everything.
For returning the info it looks at colomn 5 (1-based indexing) and if 
colomn 5 of the
next line is the different print an extra newline. So it basically does 
what I want
if colomn 5 is exact the same not if it start with string from colomn 5.

So It is basically what I need but without reordering (sorting) and 
looking at every line that
starts with colomn 5 and then sorts that blok of tekst.

I hope I explaned it well enough.

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: Help me out!!!

2004-03-04 Thread Gary Stainburn
On Thursday 04 March 2004 1:17 pm, Urvashi Mishra wrote:
 hi !

 i am trying to implement multidimentional tree... and saw that a package
 called Tree::Nary already exits...

 i am use the above module and i am getting the following error ...
 Can't locate Tree/Nary.pm [EMAIL PROTECTED]  @INC contains: C:\perl\site\lib.
 i have saved this module in this dir but its not working
 if someone can help me??

Hi,

What do you mean when you've 'saved the module in this dir'?

If you mean that you've simply downloaded the .tgz and unzipped it into the 
current directory, then perl won't see it.

You may get away with adding

use lib './';
before the use Tree:Nary to tell Perl where to look, but you'd be better off 
installing the module properly.  (Assuming you're on some form of unix), as 
root run the command

perl -MCPAN -e 'install Tree::Nary'

This will download and install the module for you and make it available to 
everyone.  

Note that if it is the first time you've run CPAN, you will be asked to 
configure it.  Simply choose the most logical answers, and if you're not sure 
of a question, simlpy take the default.
-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 


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




Re: Exit

2004-03-04 Thread R. Joseph Newton
Rob Dixon wrote:

 I hope, and think, that I've helped several people to
 be more eloquent in Perl.

 The language fascinates me in the way that nearly all
 who can speak can use it: thanks to Larry, who knew
 before we did what a programming language should have been.

 I remain available through my email address, but I have
 other, rather sad things to do. Thank you all for your
 intelligent questions and elaborations.

 /R

HI Rob,

I will definitely miss your input, and particularly your catches whe I fail to
check my facts carefully.  I hope that whatever issues you are dealing with will
turn out for the best.

Joseph

You are a child of the Universe
No less than the trees and stars
You have a right to be here
And whether or not it is clear to you, no doubt the Universe is unfolding as it
should
Therfore be at peace with God, whatever you conceive Him [Her] to be
And whatever your toils and aspirations
In the noisy confusion of Life
Keep peace with your Soul
For all its sham, drudgery and broken dreams, it is still a beautifuol world
Be careful
*Strive* to be happy



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




Handling blank lines in while(CONF) construct

2004-03-04 Thread Michael Weber
I wrote a perl script that adds colors to text streams on the fly.  It's
really handy for watching log files as they run past. I watch my mail
log files after making config changes and can mark reject in red,
spam in blue, discard is red and my console beeps, etc.  It's REALLY
nice.

However, in the configuration file, the script balks if there is a
blank line in it.  My script reads the config file into an array before
beginning to parse any data.  If there is a blank line, it gives this
error:

Use of uninitialized value in pattern match (m//) at
/usr/local/bin/filter.pl line 43, CONF line 10.

I can probably come up with a kludge to get it to work, but what is the
correct perl way to handle it?

Here's the loop where I read in the config file:

open (CONF, $ARGV[0]) || die Can't open config file $ARGV[0], $!\n;

while (CONF) {
@conf_line=split(,);

push(@trigger_array, $conf_line[0]);
if ( $conf_line[1] =~ red ) {push(@color_array, $red)}
elsif ( $conf_line[1] =~ yellow ) {push(@color_array,
$yellow)}
elsif ( $conf_line[1] =~ blue ) {push(@color_array,
$blue)}
elsif ( $conf_line[1] =~ green ) {push(@color_array,
$green)}
elsif ( $conf_line[1] =~ cyan ) {push(@color_array,
$cyan)}
elsif ( $conf_line[1] =~ purple ) {push(@color_array,
$purple)}
elsif ( $conf_line[1] =~ gray ) {push(@color_array,
$gray)}
elsif ( $conf_line[1] =~ ltred ) {push(@color_array,
$ltred)}
elsif ( $conf_line[1] =~ yellow ) {push(@color_array,
$yellow)}
elsif ( $conf_line[1] =~ ltblue ) {push(@color_array,
$ltblue)}
elsif ( $conf_line[1] =~ ltgreen ) {push(@color_array,
$ltgreen)}
elsif ( $conf_line[1] =~ ltcyan ) {push(@color_array,
$ltcyan)}
elsif ( $conf_line[1] =~ ltpurple ) {push(@color_array,
$ltpurple)}
elsif ( $conf_line[1] =~ white ) {push(@color_array,
$white)}
elsif ( $conf_line[1] =~ ltgray ) {push(@color_array,
$ltgray)}
elsif ( $conf_line[1] =~ beep ) {push(@color_array,
$beep)}
else  {push(@color_array, $white)}
}

close (CONF);

BTW.  If anyone wants this script, I will re-post it after fixing this
bug.  I gave it as a gift to this list last year as a present for all
the help I get from y'all.

Thanx!

-Michael

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




Re: Handling blank lines in while(CONF) construct

2004-03-04 Thread James Edward Gray II
On Mar 4, 2004, at 9:16 AM, Michael Weber wrote:

[snip background]

Here's the loop where I read in the config file:

open (CONF, $ARGV[0]) || die Can't open config file $ARGV[0], $!\n;

while (CONF) {
Try adding:

	next if m/^\s*$/;

@conf_line=split(,);

push(@trigger_array, $conf_line[0]);
if ( $conf_line[1] =~ red ) {push(@color_array, $red)}
elsif ( $conf_line[1] =~ yellow ) {push(@color_array,
$yellow)}
elsif ( $conf_line[1] =~ blue ) {push(@color_array,
$blue)}
elsif ( $conf_line[1] =~ green ) {push(@color_array,
$green)}
elsif ( $conf_line[1] =~ cyan ) {push(@color_array,
$cyan)}
elsif ( $conf_line[1] =~ purple ) {push(@color_array,
$purple)}
elsif ( $conf_line[1] =~ gray ) {push(@color_array,
$gray)}
elsif ( $conf_line[1] =~ ltred ) {push(@color_array,
$ltred)}
elsif ( $conf_line[1] =~ yellow ) {push(@color_array,
$yellow)}
elsif ( $conf_line[1] =~ ltblue ) {push(@color_array,
$ltblue)}
elsif ( $conf_line[1] =~ ltgreen ) {push(@color_array,
$ltgreen)}
elsif ( $conf_line[1] =~ ltcyan ) {push(@color_array,
$ltcyan)}
elsif ( $conf_line[1] =~ ltpurple ) {push(@color_array,
$ltpurple)}
elsif ( $conf_line[1] =~ white ) {push(@color_array,
$white)}
elsif ( $conf_line[1] =~ ltgray ) {push(@color_array,
$ltgray)}
elsif ( $conf_line[1] =~ beep ) {push(@color_array,
$beep)}
else  {push(@color_array, $white)}
}
close (CONF);
Hope that helps.

James

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



what is similar to shell `du' in perl

2004-03-04 Thread Harry Putnam
I'm spending lots of time looking thru perl functions but not finding
something to give me a quick reading on the size of a directory.

How is that task handled in perl?

-- 
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 me out!!!

2004-03-04 Thread zsdc
Urvashi Mishra wrote:
i am trying to implement multidimentional tree... and saw that a package called Tree::Nary already exits...

i am use the above module and i am getting the following error ...
Can't locate Tree/Nary.pm [EMAIL PROTECTED]  @INC contains: C:\perl\site\lib.
i have saved this module in this dir but its not working
if someone can help me??
See: perldoc perlmodinst

http://www.perldoc.com/perl5.8.0/pod/perlmodinst.html

--
ZSDC


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



Re: packages and variables

2004-03-04 Thread zsdc
Ralf Schaa wrote:

the module 'testMod.pm''
#==
package testMod;
use strict;
use Exporter;
our @ISA   = (Exporter);
our @EXPORT= qw($test testThis);
our @EXPORT_OK = qw($test testThis);
sub testThis{ our $test = test;}
1;
the caller-program 'test.pl'
#==
use lib E:/ddswork/process_data/_makeLevel2;
use testMod qw(testThis $test);
use strict;
print 1: $testThis::test\n;
print 2: $test\n;
== nothing is printed...
If you had turned the warnings on, it would gave printed the warning 
about the Use of uninitialized value in string so first of all move 
use strict; to the top and add use warnings; in your script and in 
the module.

You don't run the subroutine in your script, so it never sets the $test 
variable. Also, you try to print $testThis::test but your module's 
package is testMod, not testThis, so it should be $testMod::test 
instead. Try this:

#!/usr/bin/perl
use strict;
use warnings;
use lib E:/ddswork/process_data/_makeLevel2;
use testMod qw(testThis $test);
testThis();

print 1: $testMod::test\n;
print 2: $test\n;
__END__

You might want to rename your module to TestMod.
See perldoc perlstyle:
  Perl informally reserves lowercase module names for
  pragma modules like integer and strict.  Other
  modules should begin with a capital letter and use
  mixed case, but probably without underscores due to
  limitations in primitive file systems' representations
  of module names as files that must fit into a few
  sparse bytes.
See also:

perldoc perlmod
perldoc perlmodlib
perldoc perlnewmod
http://www.perldoc.com/perl5.8.0/pod/perlmod.html
http://www.perldoc.com/perl5.8.0/pod/perlmodlib.html
http://www.perldoc.com/perl5.8.0/pod/perlnewmod.html
--
ZSDC


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



Re: what is similar to shell `du' in perl

2004-03-04 Thread Steve Mayer
Harry,

  Here's an implementation of du written in Perl.


 http://www.perl.com/language/ppt/src/du/du.hewgill


Steve

On Thu, Mar 04, 2004 at 10:07:05AM -0600, Harry Putnam wrote:
 I'm spending lots of time looking thru perl functions but not finding
 something to give me a quick reading on the size of a directory.
 
 How is that task handled in perl?
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 
 

=
Steve Mayer Oracle Corporation
Project Lead1211 SW 5th Ave.
Portland Development Center Suite 900
[EMAIL PROTECTED]   Portland, OR 97204 
Phone:  503-525-3127
=

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




RE: packages and variables

2004-03-04 Thread EUROSPACE SZARINDAR

Hi Ralf,

TMHO, you should create the $test before printing it.

In fact, change 
print 1: $testThis::test\n;
into 
testMod::testThis(); 

and afterwards, the $test will be available.

OR: 

having $test global is not so profitable because you want be able to have
your personal $test variable.
You should better create it localy to testMod with the my (outside the
testThis) and call it using $testMod::test or better using a accesor.

#==
package testMod;
use strict;
use Exporter;
my $Test; # blabla..

our @ISA   = (Exporter);
our @EXPORT= qw(getTest testThis);
our @EXPORT_OK = qw(getTest testThis);

sub testThis{ $test = test};
sub getTest { return $Test };
1;

the caller-program 'test.pl'
#==
use lib E:/ddswork/process_data/_makeLevel2;
use testMod qw(testThis $test);
use strict;

testMod::testThis();
print 1: .testMod::getTest(). \n;
print 2: $test\n;


hope it help

Michel


-Message d'origine-
De: Ralf Schaa [mailto:[EMAIL PROTECTED]
Date: jeudi 4 mars 2004 13:51
À: [EMAIL PROTECTED]
Objet: packages and variables


Cheers all,

i am doing my first steps with writing packages/modules and of course 
there are problems:

the module holds a variable in a subroutine. this variable i like to 
pass to the callerprogram,
so it is in the @EXPORT_OK  and even in the @EXPORT. So far so good, i 
thought!
but nothing happens when i run the caller-program...

i  tried also defining with 'my ..' , or without 'use strict' ...

somebody has the clue?

thanx
-ralf


the module 'testMod.pm''
#==
package testMod;
use strict;
use Exporter;
our @ISA   = (Exporter);
our @EXPORT= qw($test testThis);
our @EXPORT_OK = qw($test testThis);

sub testThis{ our $test = test;}
1;

the caller-program 'test.pl'
#==
use lib E:/ddswork/process_data/_makeLevel2;
use testMod qw(testThis $test);
use strict;

print 1: $testThis::test\n;
print 2: $test\n;

== nothing is printed...

-- 
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: what is similar to shell `du' in perl

2004-03-04 Thread zsdc
Harry Putnam wrote:

I'm spending lots of time looking thru perl functions but not finding
something to give me a quick reading on the size of a directory.
How is that task handled in perl?
First of all, you can use du:

$output = `du -sk /etc`;
($kilobytes) = $output =~/^(\d+)/ or die;
There's also Tie::DiskUsage module:
http://search.cpan.org/search?module=Tie::DiskUsage
You might also take a look at du from ppt:
http://search.cpan.org/src/SDAGUE/ppt-0.12/bin/du
--
ZSDC
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: what is similar to shell `du' in perl

2004-03-04 Thread Ralf Schaa
hi there,

i helped myself with : $volsize = `du -ms $item`
with the backticks-operator (``) the system-own function is used and 
output is written in the variable $volsize - check backtick-operator.

works also on windows when the unxutils are installed (sourceforge.net)

cheers,
-ralf
Harry Putnam wrote:
I'm spending lots of time looking thru perl functions but not finding
something to give me a quick reading on the size of a directory.
How is that task handled in perl?





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



loop until key is pressed

2004-03-04 Thread Peterson, Darren - Contractor.Westar
I'd like to use a while construct to loop until a key, any key, is pressed.
I'm aware of the STDIN source for input, but with what function do I check
for key presses regardless of Enter?



Re: Handling blank lines in while(CONF) construct

2004-03-04 Thread WC -Sx- Jones
Michael Weber wrote:

open (CONF, $ARGV[0]) || die Can't open config file $ARGV[0], $!\n;

while (CONF) {
while(CONF) {
chomp;
s/^\s+//;
s/\s+$//;
next unless length;
...

@conf_line=split(,);


As far as this:

$yellow)}
elsif ( $conf_line[1] =~ blue ) {push(@color_array,
Why not just:

sub push_Colors() {
my $color = shift;
push(@color_array,$color)
}
Called like:

push_Colors($conf_line[1]);

Unless of course your data input just has a color embedded:
sometextcolorredorbluebutwhoknows...
HTH;
-Bill-
__Sx__
http://youve-reached-the.endoftheinternet.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: Checking filenames? [:: ?Kinda Solved? ::]

2004-03-04 Thread Jas
Well seeing as how I am still really new to using perl I have 
accomplished what I set out to do and figured I would share it.

The goal, a simple perl script to backup a web directory, compress the 
archive and then ftp the file(s) to a remote server.

If anyone knows how to make this more robust, intuitive (by creating 
user defined variables etc.),  able to do better date checking please 
let me know.

I have used a few tutorials etc, but I learn better when someone steps 
through something I have already written and points out what can be 
improved etc.

Thanks in advance,
jas
[start script]
#!/usr/bin/perl
# Backup web directory to remote server via FTP
# Declare modules to use
use strict;
use warnings;
use POSIX qw(strftime);
use Archive::Tar;
use Compress::Zlib;
use File::Find;
use Net::FTP;
# Current date stamp
my $date = strftime('%Y%m%d', localtime());
# Create tarball from /path/to/www/ directory
my @files;
   find(sub { push @files,$File::Find::name },/path/to/www/);
   Archive::Tar-create_archive(www.tar,0,@files);
# Create Archive from recently created tarball
my $gz = system('gzip -9 www.tar');
   $gz = system('mv -f www.tar.gz ' . $date . '-www.tar.gz');
# Open connection to FTP server
my $ftp = Net::FTP-new(ftp.server.com, Debug = 1)or die Could not 
open Connection to ftp.server.com;
$ftp-login(user-name, 'password')or die Could not login to 
ftp.server.com: $@;

# Upload all archives in /path/to/backups/ directory
foreach my $bup (glob('/path/to/backups/*-www.tar.gz')) {
$ftp-put($bup) or die Could not transfer files , $ftp-message; }
# Create array of files on remote ftp server
my @alst = $ftp-ls;
# Create empty variables
my $year = ;
my $month = ;
my $day = ;
my $c_year = ;
my $c_month = ;
my $c_day = ;
# Extract individual variables from date variable
if ($date =~ /^(\d{4})(\d{2})(\d{2})$/) {
$c_year = $1;
$c_month = $2;
$c_day = $3; }
# Loop over array and check for matching files and anything older than 
30 days
my @list;
foreach my $file(@alst) {
if ($file =~ /^\d{8}-www\.t(?:ar\.)?gz$/i) {
if ($file =~ /^(\d{4})(\d{2})(\d{2})-www\.t(?:ar\.)?gz$/i) {
$year = $1;
$month = $2;
$day = $3;
if($month != $c_month) {
push @list, $file;
} else {
warn Skipping recent file: $file; }
}
} else {
warn Skipping improper file format: $file; }
}

# Loop over new array of items flagged for deletion and remove from ftp 
server
foreach my $fle(@list) {
$ftp-delete($fle)or warn Cannot delete remote file ($fle):  . 
$ftp-message; }

$ftp-quit;
[/end script]
Wc -Sx- Jones wrote:
Jenda?

This is the partial original post -

Jas wrote:

Wouldn't this be better?

my $year = ;
my $month = ;
my $day = ;
if($file =~ /^(\d{4})(\d{2})(\d{2})-www.tar.gz$/) {
  $year = $1;
  $month = $2;
  $day = $3;
my $chk = $month - 1;


Here - this is weird =)

03 in numerical context is 3.

File name was 20040301 - collapses to 200431 -
Not a match IMHO.
foreach($file ! $chk) {
  $ftp-delete($file); }
??? Not sure but I am going to test it out


Maybe I am totally confused - I have been working on WebSphere.  Yes, I 
plead complete insanity.

-Bill-
__Sx__
http://youve-reached-the.endoftheinternet.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: Checking filenames? [:: ?Kinda Solved? ::]

2004-03-04 Thread WC -Sx- Jones
In Cyberspace -- Jas wrote:

my @files;
   find(sub { push @files,$File::Find::name },/path/to/www/);
   Archive::Tar-create_archive(www.tar,0,@files);
Never hard-code your paths...
Eases maintenance later...
# Create Archive from recently created tarball
my $gz = system('gzip -9 www.tar');
   $gz = system('mv -f www.tar.gz ' . $date . '-www.tar.gz');
Always fully qualify your program paths...
Prevents userID based security attacks...

# Create empty variables
my $year = ;
my $month = ;
my $day = ;
my $c_year = ;
my $c_month = ;
my $c_day = ;


Less wordy...

my ( $year,
 $month,
 $day,
 $c_year,
 $c_month,
 $c_day ) = '';
-Bill-  :)
__Sx__
http://youve-reached-the.endoftheinternet.org/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Perl script to switch user to root.

2004-03-04 Thread Silky Manwani
Hello,

I want to write a perl script to switch user (to root). The problem is 
that since it asks for the password, I am not sure how I would pass it 
thru the script. I know I can run the su root with the system command 
in perl, but how do I take care of passing the password.

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: Problm encountered in using DBI

2004-03-04 Thread david
Nilay Puri wrote:

 I am trying to connect to ORACLE thru perl
 I have included use DBI.
 
 On running script I get this error .
 
 install_driver(Oracle) failed: Can't load
 
'/usr/local/lib/perl5/site_perl/5.005/sun4-solaris/auto/DBD/Oracle/Oracle.so
 ' for module DBD::Oracle: ld.so.1
 : /usr/local/bin/perl: fatal: libclntsh.so.1.0: open failed:
 No such file or directory at
 /usr/local/lib/perl5/5.00503/sun4-solaris/DynaLoader.pm line 169.
 
 So, i guess libclntsh.so.1.0 is not present in the UNXI box.
 
 When i searched for it, i was not able to find it.
 

Perl is saying it can't find Oracle.so. did you install the Oracle client 
libraries? if you haven't,  you need to. you have a very old Perl, you 
should consider upgrading that as well.

david
-- 
s$s*$+/tgmecJntgRtgjvqpCvuwL$;$;=qq$
\x24\x5f\x3d\x72\x65\x76\x65\x72\x73\x65
\x24\x5f\x3b\x73\x2f\x2e\x2f\x63\x68\x72
\x28\x6f\x72\x64\x28\x24\x26\x29\x2d\x32
\x29\x2f\x67\x65\x3b\x70\x72\x69\x6e\x74
\x22\x24\x5f\x5c\x6e\x22\x3b\x3b$;eval$;

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




Cache::Filecache Question

2004-03-04 Thread Michael C. Davis
Hi, I'm having trouble finding much documentation of namespaces as used
with Cache::FileCache.  I've read the CPAN page and it doesn't say much
about that particular issue.  Could anyone point me to anything more
explanatory.

My particular interest is in the relation between namespace and specific
cache_root (directory location in the host's filesystem).  A namespace is
defined relative to a specific cache_root ... right?  In other words, if I
switch to a different cache_root then I'm talking about a whole different
set of entries, even if the namespace identifier happens to have the same
value?  (Or does it somehow preserve keys relative to namespace, regardless
of where the cache is preserved in the filesystem?  That would be too wierd
... surely it wouldn't move a bunch of cached objects if I change the
cache_root ... )

TIA.

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




Re: [Perl-beginners] Perl script to switch user to root.

2004-03-04 Thread Silky Manwani
Actually, My program has a list of stuff to be done which needs to be 
done as say user x. Then I need to switch user to root as the rest of 
the program needs to do stuff as user root.

so, me doing

system(sudo su root);

doesn't help as it asks for the password.

On Mar 4, 2004, at 10:08 AM, Remko Lodder wrote:

perhaps you should let the script do something like SUDO,
and permit it to run a single command, or limited commandset
of root operations, even without password, (you dont want that actually
but since sudo can log stuff, it might be what you aim for)
Cheers

--

Kind regards,

Remko Lodder
Elvandar.org/DSINet.org
www.mostly-harmless.nl Dutch community for helping newcomers on the
hackerscene
-Oorspronkelijk bericht-
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Silky Manwani
Verzonden: donderdag 4 maart 2004 19:03
Aan: [EMAIL PROTECTED]
Onderwerp: [Perl-beginners] Perl script to switch user to root.
Hello,

I want to write a perl script to switch user (to root). The problem is
that since it asks for the password, I am not sure how I would pass it
thru the script. I know I can run the su root with the system command
in perl, but how do I take care of passing the password.
Thanks.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response
___
Perl-beginners mailing list
[EMAIL PROTECTED]
http://lists.elvandar.org/mailman/listinfo/perl-beginners


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



Re: loop until key is pressed

2004-03-04 Thread Tim
At 11:00 AM 3/4/04 -0600, you wrote:
I'd like to use a while construct to loop until a key, any key, is pressed.
I'm aware of the STDIN source for input, but with what function do I check
for key presses regardless of Enter?


Use the CPAN module Term::ReadKey, and try to read a key in non-blocking 
mode by passing it an argument of -1

if (defined ($char = ReadKey(-1)) ) {
# input was waiting and it was $char
} else {
# no input was waiting
}



Re: Array of objects

2004-03-04 Thread WC -Sx- Jones
Jayakumar Rajagopal wrote:
Hi ,
I have to store list of objects in Array. At the end, @arr contains n copies of last 
$obj, but not every $obj created.
I tried storing both object, ref of object. Array contains different references, but 
same data. Please help.
thanks,


OK, this URL is not your question, but it may help you understand your 
situation better  :)

http://search.cpan.org/~lbrocard/perl5.005_04/lib/Symbol.pm

-Bill-
__Sx__
http://youve-reached-the.endoftheinternet.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: Array of objects

2004-03-04 Thread Bob Showalter
Jayakumar Rajagopal wrote:
 Hi ,
 I have to store list of objects in Array. At the end, @arr contains n
 copies of last $obj, but not every $obj created. I tried storing both
 object, ref of object. Array contains different references, but same
 data. Please help.  
 thanks,
 Jay
 
 the current code looks like this :
 
 $n=0;
 my @arr=();
 while ( @results )
 {
 $n++;
 my $obj = RowClass-new();
 ...
 ...
 
 push @arr, $obj;
 }

each call to RowClass::new should be returning a unique bless()'d reference.
If that's the case, the rest of your code looks fine. What is
RowClass::new() doing?

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




Re: loop until key is pressed

2004-03-04 Thread Tim
At 11:00 AM 3/4/04 -0600, you wrote:
I'd like to use a while construct to loop until a key, any key, is pressed.
I'm aware of the STDIN source for input, but with what function do I check
for key presses regardless of Enter?
forgot to add :
ReadMode 'cbreak';
before, and
ReadMode 'normal';
after.
should read:

ReadMode 'cbreak';
$key = ReadKey(0);
ReadMode 'normal';
my booboo... 

Re: Checking filenames? [:: ?Kinda Solved? ::]

2004-03-04 Thread Jas


Wc -Sx- Jones wrote:

In Cyberspace -- Jas wrote:

my @files;
   find(sub { push @files,$File::Find::name },/path/to/www/);
   Archive::Tar-create_archive(www.tar,0,@files);


Never hard-code your paths...
Eases maintenance later...
 Can you show me an example of how to do this?


# Create Archive from recently created tarball
my $gz = system('gzip -9 www.tar');
   $gz = system('mv -f www.tar.gz ' . $date . '-www.tar.gz');


Always fully qualify your program paths...
Prevents userID based security attacks...
 Can you show me an example of how to do this as well?



# Create empty variables
my $year = ;
my $month = ;
my $day = ;
my $c_year = ;
my $c_month = ;
my $c_day = ;


Less wordy...

my ( $year,
 $month,
 $day,
 $c_year,
 $c_month,
 $c_day ) = '';
Awesome, I will use this on future scripts.

-Bill-  :)
__Sx__
http://youve-reached-the.endoftheinternet.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: [Perl-beginners] Perl script to switch user to root.

2004-03-04 Thread Remko Lodder
you obviously didn't read the sudo help pages, you can run the script as
user y
and let it do root things by using
sudo reboot
for example
the system should reboot when you have defined sudo correctly.

man sudo should help you further on the way :)

--

Kind regards,

Remko Lodder
Elvandar.org/DSINet.org
www.mostly-harmless.nl Dutch community for helping newcomers on the
hackerscene

-Oorspronkelijk bericht-
Van: Silky Manwani [mailto:[EMAIL PROTECTED]
Verzonden: donderdag 4 maart 2004 19:15
Aan: Remko Lodder
CC: [EMAIL PROTECTED]
Onderwerp: Re: [Perl-beginners] Perl script to switch user to root.


Actually, My program has a list of stuff to be done which needs to be
done as say user x. Then I need to switch user to root as the rest of
the program needs to do stuff as user root.

so, me doing

system(sudo su root);

doesn't help as it asks for the password.


On Mar 4, 2004, at 10:08 AM, Remko Lodder wrote:

 perhaps you should let the script do something like SUDO,
 and permit it to run a single command, or limited commandset
 of root operations, even without password, (you dont want that actually
 but since sudo can log stuff, it might be what you aim for)

 Cheers

 --

 Kind regards,

 Remko Lodder
 Elvandar.org/DSINet.org
 www.mostly-harmless.nl Dutch community for helping newcomers on the
 hackerscene

 -Oorspronkelijk bericht-
 Van: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] Silky Manwani
 Verzonden: donderdag 4 maart 2004 19:03
 Aan: [EMAIL PROTECTED]
 Onderwerp: [Perl-beginners] Perl script to switch user to root.


 Hello,

 I want to write a perl script to switch user (to root). The problem is
 that since it asks for the password, I am not sure how I would pass it
 thru the script. I know I can run the su root with the system command
 in perl, but how do I take care of passing the password.

 Thanks.


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


 ___
 Perl-beginners mailing list
 [EMAIL PROTECTED]
 http://lists.elvandar.org/mailman/listinfo/perl-beginners




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




Re: what is similar to shell `du' in perl

2004-03-04 Thread Harry Putnam
Steve Mayer [EMAIL PROTECTED] writes:

 Harry,

   Here's an implementation of du written in Perl.
  

 http://www.perl.com/language/ppt/src/du/du.hewgill

Nice ... 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: what is similar to shell `du' in perl

2004-03-04 Thread Harry Putnam

Ralf Schaa [EMAIL PROTECTED] writes:

 hi there,

 i helped myself with : $volsize = `du -ms $item`
 with the backticks-operator (``) the system-own function is used and
 output is written in the variable $volsize - check backtick-operator.

 works also on windows when the unxutils are installed (sourceforge.net)

I wanted to stay away form qx or back tics just to make sure it was
portable.   I see several answers here now... 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: Array of objects

2004-03-04 Thread Jayakumar Rajagopal
Bob,
  Thanks. Already I have been working out on the same row. I think I misunderstood 
significance of self reference, which is first parameter of methods. After finishing I 
would mail.
regards,
Jay

-Original Message-
From: Bob Showalter [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 04, 2004 1:38 PM
To: Jayakumar Rajagopal; [EMAIL PROTECTED]
Subject: RE: Array of objects


Jayakumar Rajagopal wrote:
 Hi ,
 I have to store list of objects in Array. At the end, @arr contains n
 copies of last $obj, but not every $obj created. I tried storing both
 object, ref of object. Array contains different references, but same
 data. Please help.  
 thanks,
 Jay
 
 the current code looks like this :
 
 $n=0;
 my @arr=();
 while ( @results )
 {
 $n++;
 my $obj = RowClass-new();
 ...
 ...
 
 push @arr, $obj;
 }

each call to RowClass::new should be returning a unique bless()'d reference.
If that's the case, the rest of your code looks fine. What is
RowClass::new() doing?

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




RE: Array of objects

2004-03-04 Thread Jayakumar Rajagopal
Bob,
   Your guess is perfect. Thanks a lot.
   All the problems happened due to misunderstanding of class behaviour. ( new() and 
get() functions).
cheers,
Jay

-Original Message-
From: Bob Showalter [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 04, 2004 1:38 PM
To: Jayakumar Rajagopal; [EMAIL PROTECTED]
Subject: RE: Array of objects


Jayakumar Rajagopal wrote:
 Hi ,
 I have to store list of objects in Array. At the end, @arr contains n
 copies of last $obj, but not every $obj created. I tried storing both
 object, ref of object. Array contains different references, but same
 data. Please help.  
 thanks,
 Jay
 
 the current code looks like this :
 
 $n=0;
 my @arr=();
 while ( @results )
 {
 $n++;
 my $obj = RowClass-new();
 ...
 ...
 
 push @arr, $obj;
 }

each call to RowClass::new should be returning a unique bless()'d reference.
If that's the case, the rest of your code looks fine. What is
RowClass::new() doing?

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




Re: Checking filenames? [:: ?Kinda Solved? ::]

2004-03-04 Thread WC -Sx- Jones
Jas wrote:


Wc -Sx- Jones wrote:

In Cyberspace -- Jas wrote:

my @files;
   find(sub { push @files,$File::Find::name },/path/to/www/);
   Archive::Tar-create_archive(www.tar,0,@files);
Never hard-code your paths...
Eases maintenance later...
 Can you show me an example of how to do this?
Either near the beginning of your code or in a separate include file 
(which is what I do) just name all the paths:

my $www = (-d /usr/local/Forsaken) ? '/usr/local/Forsaken'
 : die HOMEDIR Missing;
Then you use it in your code:

find(sub { push @files,$File::Find::name }, $www);




# Create Archive from recently created tarball
my $gz = system('gzip -9 www.tar');
   $gz = system('mv -f www.tar.gz ' . $date . '-www.tar.gz');
Always fully qualify your program paths...
Prevents userID based security attacks...
 Can you show me an example of how to do this as well?


Same deal here:

my $gzip = (-s /usr/bin/gzip) ? '/usr/bin/gzip'
: die gzip Missing;
All of these tests may likely not be needed if your system is the only 
place you will ever run your scripts -- but if you plan on sharing them 
you need to test a few things at least...

I mean, at one time or another, we are all guilty of:

chomp(my $userid = `/usr/ucb/whoami` || `/usr/bin/whoami` || 'root');

-Bill-
__Sx__
http://youve-reached-the.endoftheinternet.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: Handling blank lines in while(CONF) construct

2004-03-04 Thread John W. Krahn
Michael Weber wrote:
 
 I wrote a perl script that adds colors to text streams on the fly.  It's
 really handy for watching log files as they run past. I watch my mail
 log files after making config changes and can mark reject in red,
 spam in blue, discard is red and my console beeps, etc.  It's REALLY
 nice.
 
 However, in the configuration file, the script balks if there is a
 blank line in it.  My script reads the config file into an array before
 beginning to parse any data.  If there is a blank line, it gives this
 error:
 
 Use of uninitialized value in pattern match (m//) at
 /usr/local/bin/filter.pl line 43, CONF line 10.
 
 I can probably come up with a kludge to get it to work, but what is the
 correct perl way to handle it?
 
 Here's the loop where I read in the config file:
 
 open (CONF, $ARGV[0]) || die Can't open config file $ARGV[0], $!\n;
 
 while (CONF) {
 @conf_line=split(,);

This should work:

  my @conf_line = split /,/ or next;


 push(@trigger_array, $conf_line[0]);
   ^ ^
You don't need to convert $conf_line[0] to a string, it already is a
string!


John
-- 
use Perl;
program
fulfillment

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




Re: Checking filenames? [:: ?Kinda Solved? ::]

2004-03-04 Thread Jas


Wc -Sx- Jones wrote:

Jas wrote:



Wc -Sx- Jones wrote:

In Cyberspace -- Jas wrote:

my @files;
   find(sub { push @files,$File::Find::name },/path/to/www/);
   Archive::Tar-create_archive(www.tar,0,@files);


Never hard-code your paths...
Eases maintenance later...


 Can you show me an example of how to do this?


Either near the beginning of your code or in a separate include file 
(which is what I do) just name all the paths:

my $www = (-d /usr/local/Forsaken) ? '/usr/local/Forsaken'
 : die HOMEDIR Missing;
Then you use it in your code:

find(sub { push @files,$File::Find::name }, $www);




# Create Archive from recently created tarball
my $gz = system('gzip -9 www.tar');
   $gz = system('mv -f www.tar.gz ' . $date . '-www.tar.gz');


Always fully qualify your program paths...
Prevents userID based security attacks...


 Can you show me an example of how to do this as well?


Same deal here:

my $gzip = (-s /usr/bin/gzip) ? '/usr/bin/gzip'
: die gzip Missing;
All of these tests may likely not be needed if your system is the only 
place you will ever run your scripts -- but if you plan on sharing them 
you need to test a few things at least...

I mean, at one time or another, we are all guilty of:

chomp(my $userid = `/usr/ucb/whoami` || `/usr/bin/whoami` || 'root');
I am not sure what this means?  Is this the process ID or the perl 
script is running as a root user?




-Bill-
__Sx__
http://youve-reached-the.endoftheinternet.org/


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



Passing Data Between Servers

2004-03-04 Thread Paul Kraus
 I have a sco server which I hate to work on and I do not have full admin
 rights to. (We don't own it).
 
 I would like to be able to take any data that is sent to a perl script and
 then just send out to another perl script that would be waiting to accept
 it.
 
 Then based on the contents of input lunch another perl script and send in
 the data.
 
 I know this is vague but I will give you a for instance.
 
 Are archaic software is going to print an order out to a text file that is
 piped rather then written to a perl script. I want that the script to then
 send it to my linux server (Maybe with a daemon or something just waiting
 for input) which then would see it read the first line which tell it that
 hey we need to parse this data into this postscript template and then send
 it off using sendfax(Hylafax). That parsing and send would be its own
 script.
 
 The linux server would need to be able to accept more then 1 transaction
 at a time.
 
 Any help would be greatly appreciated.
 
 TIA,
 
  Paul Kraus
  ---
  PEL Supply Company
  Network Administrator
  ---
  800 321-1264 Toll Free
  216 267-5775 Voice
  216 267-6176 Fax
  www.pelsupply.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: Passing Data Between Servers

2004-03-04 Thread Tim
At 03:37 PM 3/4/04 -0500, you wrote:
 I have a sco server which I hate to work on and I do not have full admin
 rights to. (We don't own it).

 I would like to be able to take any data that is sent to a perl script and
 then just send out to another perl script that would be waiting to accept
 it.

 Then based on the contents of input lunch another perl script and send in
 the data.

 I know this is vague but I will give you a for instance.

 Are archaic software is going to print an order out to a text file that is
 piped rather then written to a perl script. I want that the script to then
 send it to my linux server (Maybe with a daemon or something just waiting
 for input) which then would see it read the first line which tell it that
 hey we need to parse this data into this postscript template and then send
 it off using sendfax(Hylafax). That parsing and send would be its own
 script.

 The linux server would need to be able to accept more then 1 transaction
 at a time.

 Any help would be greatly appreciated.

 TIA,

  Paul Kraus
  ---
  PEL Supply Company
  Network Administrator
  ---
  800 321-1264 Toll Free
  216 267-5775 Voice
  216 267-6176 Fax
  www.pelsupply.com
  ---
Paul,
Network Programming with Perl by Stein is a good place to start. It 
discusses forking children, blocking and non-blocking I/O, among others, 
which will be considerations you'll want to make.

Tim 

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



RE: Checking filenames? [:: ?Kinda Solved? ::]

2004-03-04 Thread Charles K. Clarkson
Jas [EMAIL PROTECTED] wrote:
: 
: Wc -Sx- Jones wrote:
: 
:  In Cyberspace -- Jas wrote:
:  
:   # Create empty variables
:   my $year = ;
:   my $month = ;
:   my $day = ;
:   my $c_year = ;
:   my $c_month = ;
:   my $c_day = ;
:  
:  Less wordy...
:  
:  my ( $year,
:   $month,
:   $day,
:   $c_year,
:   $c_month,
:   $c_day ) = '';
:  
: Awesome, I will use this on future scripts.

It doesn't do the same thing. You would need:

 my ( $year,
  $month,
  $day,
  $c_year,
  $c_month,
  $c_day ) = ('') x 6;


Though we only need one of them for this algorithm
(untested):

# Current date stamp
my $date = strftime '%Y%m%d', localtime $^T;

.
.
.

# Check for matching files not from this month
my $this_month = strftime '%m', localtime $^T;
my @list;
foreach my $file ( $ftp-ls ) {

unless ( $file =~ /^\d{4}(\d{2})\d{2}-www\.t(?:ar\.)?gz$/i ) {
warn Skipping improper file format: $file;
next;
}

unless ( $1 != $this_month ) {
warn Skipping recent file: $file;
next;
}

push @list, $file;
}


$^T is the time the script started. By using it for a time
stamp, instead of time(), we don't have to jump through hoops to
find the month and we have a constant time stamp in an easy to
use format.


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: Passing Data Between Servers

2004-03-04 Thread wolf blaum
On Thursday 04 March 2004 22:26, Tim generously enriched virtual reallity by 
making up this one:

 Paul,
 Network Programming with Perl by Stein is a good place to start. It
 discusses forking children, blocking and non-blocking I/O, among others,
 which will be considerations you'll want to make.


...and at least the scripts are available on the net:
http://modperl.com:9000/perl_networking

Have fun, Wolf


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




Re: Checking filenames? [:: ?Kinda Solved? ::]

2004-03-04 Thread WC -Sx- Jones
Jas wrote:

chomp(my $userid = `/usr/ucb/whoami` || `/usr/bin/whoami` || 'root');
I am not sure what this means?  Is this the process ID or the perl 
script is running as a root user?

Nope, it is a simple short circuit to see
who the UserID program of the program was;
It states that if I cant tell who I am (because, for
example, all the programs I tried for whoami failed
(but I ignored the errors)) then I will pretend I am
root -- doesnt mean I am root...
-Bill-
__Sx__
http://youve-reached-the.endoftheinternet.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: perl hex editor

2004-03-04 Thread Joel
Thanks, that works perfectly. Now I just have to figure out how to turn it
back into a valid file. I tried using pack 'b*' but I had no luck. Any
suggestions?

Joel

- Original Message - 
From: John W. Krahn [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, March 03, 2004 5:31 PM
Subject: Re: perl hex editor


 Joel wrote:
 
  I'm trying to write a program in perl that will take a binary file,
convert
  it to hex, then save it to a text file. So far I'm not having any luck.
The
  best I've been able to do is copy the file and open it in a text editor.
  Here is my code:
 
  #!/usr/bin/perl
 
  use warnings;
  use strict;
 
  print Enter path:\n;
  my $filename = ;
  chomp $filename;
  print Save as what?\n;
  my $savefile=;
  chomp $savefile;
  open (BINARY, $filename) || die Couldn't open file: $!;
  binmode BINARY;
  my $x=BINARY;
  open (SAVE,$savefile) || die Unable to save: $!;
  print SAVE 0b$x;
  close BINARY;
  close SAVE;
 
  Any ideas?

 Perhaps this is what you want:

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

 print 'Enter path: ';
 chomp( my $filename = STDIN );

 print 'Save as what? ';
 chomp( my $savefile = STDIN );

 open BINARY, '', $filename or die Couldn't open file: $!;
 binmode BINARY;
 open SAVE, '', $savefile or die Unable to save: $!;

 while ( BINARY ) {
 print SAVE unpack( 'H*', $_ ), \n;
 }

 close BINARY;
 close SAVE;

 __END__



 John
 -- 
 use Perl;
 program
 fulfillment

 -- 
 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: Checking filenames? [:: ?Kinda Solved? ::]

2004-03-04 Thread WC -Sx- Jones
Hmmm, I get 3 Indians in only the first variable anyways  =/

#! /usr/bin/perl -w

use strict;

# Make -w / use strict; happy...
my ($onelittle,
$twolittle,
$threelittle,
   ) = 'Indians' x 3;
print 1 $onelittle 2 $twolittle 3 $threelittle\n\n;

__END__

Output -

bash-2.05$ perl axxa
Use of uninitialized value in
concatenation (.) or string at axxa line 12.
Use of uninitialized value in
concatenation (.) or string at axxa line 12.
1 IndiansIndiansIndians 2  3
-Bill-
__Sx__
http://youve-reached-the.endoftheinternet.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: Checking filenames? [:: ?Kinda Solved? ::]

2004-03-04 Thread Charles K. Clarkson
WC -Sx- Jones [mailto:[EMAIL PROTECTED] 
: 
: Hmmm, I get 3 Indians in only the first variable anyways  =/
: 
: 
: #! /usr/bin/perl -w
: 
: use strict;
: 
: # Make -w / use strict; happy...
: my ($onelittle,
:  $twolittle,
:  $threelittle,
: ) = 'Indians' x 3;


Ahh! Grasshopper ...  :)

Make 'Indians' an array.

my( $onelittle,
$twolittle,
$threelittle, ) = ('Indians') x 3;


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: Checking filenames? [:: ?Kinda Solved? ::]

2004-03-04 Thread WC -Sx- Jones
Charles K. Clarkson wrote:

Make 'Indians' an array.

my( $onelittle,
$twolittle,
$threelittle, ) = ('Indians') x 3;


Create it with a HereDoc  =)

-Bill-
__Sx__
http://youve-reached-the.endoftheinternet.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: Checking filenames? [:: ?Kinda Solved? ::]

2004-03-04 Thread Sumit Kaur

Hi,

I have to write my first Perl script . This scripts Searches for rare =
codons in nucleotide sequence . The nucleotide sequence is entered by =
the user in the format ATTGCAA.. and then the program breaks this =
sequence in the groups of three alphabets like ATT,GCA...so no.=20

Please suggest .

Thanks
-Original Message-
From: Charles K. Clarkson [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 04, 2004 4:44 PM
To: [EMAIL PROTECTED]
Subject: RE: Checking filenames? [:: ?Kinda Solved? ::]


WC -Sx- Jones [mailto:[EMAIL PROTECTED] 
: 
: Hmmm, I get 3 Indians in only the first variable anyways  =/
: 
: 
: #! /usr/bin/perl -w
: 
: use strict;
: 
: # Make -w / use strict; happy...
: my ($onelittle,
:  $twolittle,
:  $threelittle,
: ) = 'Indians' x 3;


Ahh! Grasshopper ...  :)

Make 'Indians' an array.

my( $onelittle,
$twolittle,
$threelittle, ) = ('Indians') x 3;


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



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




Re: Checking filenames? [:: ?Kinda Solved? ::]

2004-03-04 Thread wolf blaum
On Friday 05 March 2004 02:03, Sumit Kaur generously enriched virtual reallity 
by making up this one:

 Hi,

Hi,

 I have to write my first Perl script . This scripts Searches for rare =
 codons in nucleotide sequence . The nucleotide sequence is entered by =
 the user in the format ATTGCAA.. and then the program breaks this =
 sequence in the groups of three alphabets like ATT,GCA...so no.=20

 Please suggest .

I first of all suggest you use new subject line...
Then: read Learning perl by Randal Schwartz and Tom Phoenix and tell us if you 
are learning perl as a first language or allready know about control 
structures, filehandles and regluar expressions

Then: what do you mean by rare - do you want the program to figure out, what 
the least frequent codons are and list/count/whatever them or do you have a 
prior definition of rare. Further (given your example above):

ATTGCAA
ATT
   TTG
      TGC

are all these codons or do you assume your user supplied sequence starts 
somewhere you know and goes on in triplets from there on? (That is, does the 
user supply only exons starting with the start tripplet?)

Once you get past the first steps: look at the bioperl modules at cpan and at 
www.Bioperl.org

Enjoy  -Wolf


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




nucleotide seq Was Re: Checking filenames? [:: ?Kinda Solved? ::]

2004-03-04 Thread WC -Sx- Jones
Sumit Kaur wrote:
Hi,

I have to write my first Perl script . This scripts Searches for rare =
codons in nucleotide sequence . The nucleotide sequence is entered by =
the user in the format ATTGCAA.. and then the program breaks this =
sequence in the groups of three alphabets like ATT,GCA...so no.=20
Please suggest .


Please dont piggy back post - it breaks the thread of the original 
conversation.

If the data will always be three - maybe this will give you an idea:

@array = split(//, 'ABCDEFGHIJKLMONPQRSTUVWXYZ');

my $index = -1;

while($#array  $index) {
  print \nSet $index ;
  print $array[++$index];
  print $array[++$index];
  print $array[++$index];
}
and so on...
-Bill-
__Sx__
http://youve-reached-the.endoftheinternet.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: Checking filenames? [:: ?Kinda Solved? ::]

2004-03-04 Thread John W. Krahn
Charles K. Clarkson wrote:
 
 WC -Sx- Jones [mailto:[EMAIL PROTECTED]
 :
 : Hmmm, I get 3 Indians in only the first variable anyways  =/
 :
 : # Make -w / use strict; happy...
 : my ($onelittle,
 :  $twolittle,
 :  $threelittle,
 : ) = 'Indians' x 3;
 
 Ahh! Grasshopper ...  :)
 
 Make 'Indians' an array.
 
 a list

perldoc -q What is the difference between a list and an array

 my( $onelittle,
 $twolittle,
 $threelittle, ) = ('Indians') x 3;


John
-- 
use Perl;
program
fulfillment

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




Re: Checking filenames? [:: ?Kinda Solved? ::]

2004-03-04 Thread John W. Krahn
Wc -Sx- Jones wrote:
 
 Charles K. Clarkson wrote:
 
  Make 'Indians' an array.
 
  my( $onelittle,
  $twolittle,
  $threelittle, ) = ('Indians') x 3;
 
 Create it with a HereDoc  =)

Oh, how do you do that?


John
-- 
use Perl;
program
fulfillment

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




Re: Checking filenames? [:: ?Kinda Solved? ::]

2004-03-04 Thread John W. Krahn
Wc -Sx- Jones wrote:
 
 Jas wrote:
 
  chomp(my $userid = `/usr/ucb/whoami` || `/usr/bin/whoami` || 'root');
 
  I am not sure what this means?  Is this the process ID or the perl
  script is running as a root user?
 
 Nope, it is a simple short circuit to see
 who the UserID program of the program was;
 
 It states that if I cant tell who I am (because, for
 example, all the programs I tried for whoami failed
 (but I ignored the errors)) then I will pretend I am
 root -- doesnt mean I am root...

Why not use $ to find out who you are?


John
-- 
use Perl;
program
fulfillment

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




Re: perl hex editor

2004-03-04 Thread R. Joseph Newton
Joel wrote:

 Thanks, that works perfectly. Now I just have to figure out how to turn it
 back into a valid file. I tried using pack 'b*' but I had no luck. Any
 suggestions?

 Joel

Depends on how the bytes are stored at the point where you are ready to print
them.  Presuming numerically by the byte, try something like

print OUT pack(C, $_) for @bytes;   # parens optional

Joseph

Note:  Please do not top post, and please trim any text to which you are not
responding.


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




RE: perl hex editor

2004-03-04 Thread David le Blanc

Does it need to be Hex?

Have you considered 'base64'??

(1) There are plenty of modules to do so
(2) It's a portable format
(3) It's a 30% growth in filesize rather than 100%
(ie, each 8 bits becomes 6 rather than 4)
(4) You can unpack the data with other utilities.


 sample code ---

sub EncodeBase64
{
my $s = shift ;
my $r = '';
while( $s =~ /(.{1,45})/gs ){
chop( $r .= substr(pack(u,$1),1) );
}
my $pad=(3-length($s)%3)%3;
$r =~ tr|` -_|AA-Za-z0-9+/|;
$r=~s/.{$pad}$/=x$pad/e if $pad;
$r=~s/(.{1,72})/$1\n/g;
$r;
}

sub DecodeBase64
{
my $d = shift;
$d =~ tr!A-Za-z0-9+/!!cd;
$d =~ s/=+$//;
$d =~ tr!A-Za-z0-9+/! -_!;
my $r = '';
while( $d =~ /(.{1,60})/gs ){
my $len = chr(32 + length($1)*3/4);
$r .= unpack(u, $len . $1 );
}
$r;
}



my $binary_data = Hello\nThere..\b\b\n;

my $ascii = EncodeBase64( $binary_data );

print ASCII = $ascii.$/;

my $binary = DecodeBase64( $ascii );

print binary = $binary.$/;

 snip --


 
 

Regards,

David le Blanc

--  
Senior Technical Specialist 
I d e n t i t y   S o l u t i o n s 

Level 1, 369 Camberwell Road, Melbourne, Vic 3124   
Ph 03 9813 1388 Fax 03 9813 1688 Mobile 0417 595 550
Email [EMAIL PROTECTED] 
 

 -Original Message-
 From: Joel [mailto:[EMAIL PROTECTED] 
 Sent: Friday, 5 March 2004 10:57 AM
 To: [EMAIL PROTECTED]; John W. Krahn
 Subject: Re: perl hex editor
 
 Thanks, that works perfectly. Now I just have to figure out 
 how to turn it
 back into a valid file. I tried using pack 'b*' but I had 
 no luck. Any
 suggestions?
 
 Joel
 
 - Original Message - 
 From: John W. Krahn [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Wednesday, March 03, 2004 5:31 PM
 Subject: Re: perl hex editor
 
 
  Joel wrote:
  
   I'm trying to write a program in perl that will take a 
 binary file,
 convert
   it to hex, then save it to a text file. So far I'm not 
 having any luck.
 The
   best I've been able to do is copy the file and open it in 
 a text editor.
   Here is my code:
  
   #!/usr/bin/perl
  
   use warnings;
   use strict;
  
   print Enter path:\n;
   my $filename = ;
   chomp $filename;
   print Save as what?\n;
   my $savefile=;
   chomp $savefile;
   open (BINARY, $filename) || die Couldn't open file: $!;
   binmode BINARY;
   my $x=BINARY;
   open (SAVE,$savefile) || die Unable to save: $!;
   print SAVE 0b$x;
   close BINARY;
   close SAVE;
  
   Any ideas?
 
  Perhaps this is what you want:
 
  #!/usr/bin/perl
  use warnings;
  use strict;
 
  print 'Enter path: ';
  chomp( my $filename = STDIN );
 
  print 'Save as what? ';
  chomp( my $savefile = STDIN );
 
  open BINARY, '', $filename or die Couldn't open file: $!;
  binmode BINARY;
  open SAVE, '', $savefile or die Unable to save: $!;
 
  while ( BINARY ) {
  print SAVE unpack( 'H*', $_ ), \n;
  }
 
  close BINARY;
  close SAVE;
 
  __END__
 
 
 
  John
  -- 
  use Perl;
  program
  fulfillment
 
  -- 
  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: perl hex editor

2004-03-04 Thread John W. Krahn
[ TOFU fixed ]


Joel wrote:
 
 From: John W. Krahn [EMAIL PROTECTED]
 
  Joel wrote:
  
   I'm trying to write a program in perl that will take a binary file,
   convert it to hex, then save it to a text file.
 
  Perhaps this is what you want:
 
  #!/usr/bin/perl
  use warnings;
  use strict;
 
  print 'Enter path: ';
  chomp( my $filename = STDIN );
 
  print 'Save as what? ';
  chomp( my $savefile = STDIN );
 
  open BINARY, '', $filename or die Couldn't open file: $!;
  binmode BINARY;
  open SAVE, '', $savefile or die Unable to save: $!;
 
  while ( BINARY ) {
  print SAVE unpack( 'H*', $_ ), \n;
  }
 
  close BINARY;
  close SAVE;
 
  __END__
 
 Thanks, that works perfectly. Now I just have to figure out how to turn it
 back into a valid file. I tried using pack 'b*' but I had no luck. Any
 suggestions?

while ( TEXT ) {
chomp;
print BINARY pack 'H*', $_;
}


John
-- 
use Perl;
program
fulfillment

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




Re: Any way for Perl to write RTF within email as the body of an email without attachments

2004-03-04 Thread R. Joseph Newton
Wagner, David --- Senior Programmer Analyst --- WGO wrote:


 I am just trying to give my user what they asked for and they do not want 
 any attachments. I was using what Jan K suggested, but obviously missing more than 
 just a little bit.

 Wags ;)

Sound like you're stuck with it.  You might point out to your clients that RTF cannot 
hold viri, since, AFAIK, it doesn't contain macros.  OTOH, using Outlook is sorta like 
holding your
door wide open and inviting them in.

In that case, I would default to the suggestion about Content-type.  Here is how an 
attachment I sent from my work to personal email appeared:

  Content-Type:
application/rtf; name=Resume_rjn.rtf
  Content-Transfer-Encoding:
 base64
 Content-Disposition:
 attachment; filename=Resume_rjn.rtf
Change the above to:
 inline
 Content-Description:
 Rich-Text-Format

Joseph


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




Re: Cache::Filecache Question

2004-03-04 Thread R. Joseph Newton
Michael C. Davis wrote:

 Hi, I'm having trouble finding much documentation of namespaces as used
 with Cache::FileCache.  I've read the CPAN page and it doesn't say much
 about that particular issue.  Could anyone point me to anything more
 explanatory.

 My particular interest is in the relation between namespace and specific
 cache_root (directory location in the host's filesystem).  A namespace is
 defined relative to a specific cache_root ... right?

No.  Perl namespaces do not relate to anything external to the language itself.
Namespace systems within any external system are not related to the scoping of
identifiers in Perl.

If you are using the Cache::FileCache package, the package-level functions
exorted by the package are available to you.  Any object blessed into this
package will have access to all methods defined in the package.  Remember that
anmespace is a general term which can be applied in different contexts.  I get
the impression that you are mixing the Perl namespace paradigm with the
namespace paradigm of some completely different system.

Can you be more specific about your issue?

 In other words, if I
 switch to a different cache_root then I'm talking about a whole different
 set of entries, even if the namespace identifier happens to have the same
 value?

No.  If you are still using Cache::FileCache to define those entries, they are
still in the same Perl namespace.

  (Or does it somehow preserve keys relative to namespace, regardless
 of where the cache is preserved in the filesystem?  That would be too wierd
 ... surely it wouldn't move a bunch of cached objects if I change the
 cache_root ... )

 TIA.

My suggestion would be to start thinking in terms of scope of identifier, rather
than namespace when dealing with namespace issues in Perl.  You are getting
hung up on the word and making false connections, on the basis of shared
terminology, between unrelated systems.  Do not mix programming constructs with
data content, even conceptually.

Joseph




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




Re: packages and variables

2004-03-04 Thread R. Joseph Newton
Ralf Schaa wrote:

 Cheers all,

 i am doing my first steps with writing packages/modules and of course
 there are problems:

 the module holds a variable in a subroutine. this variable i like to
 pass to the callerprogram,

Dont.  Just don't.  Use good design in your program instead.  Good design does
not require having global variables.


 so it is in the @EXPORT_OK  and even in the @EXPORT. So far so good, i
 thought!

Export functions, not variables.  Don't try to share variables between files, or
even between functions and you will save yourself a lot of grief.  Instead,
learn how to pass arguments to functions, and how to use references to allow
functions to access arrays, hashes, and objects.
perldoc perlref
perldoc perlsub
perldoc perlmod
perldoc perlobj



 but nothing happens when i run the caller-program...

 i  tried also defining with 'my ..' , or without 'use strict' ...

 somebody has the clue?

 thanx
 -ralf

If you explain what you are trying to accomplish, we can probably help you to
use modules appropriately to accomplish the task.  I would suggest that until
you are ready to take on serious object-oriented design, you should focus on
uisng subroutines well and passing arguments to and returning values from
subroutines.

Don't try to get around scoping restrictions.  Work with them instead.  The
discipline they impose is very healthy, and will make your programs much more
dependable.

Joseph


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




Re: problem in array accessing

2004-03-04 Thread R. Joseph Newton
N, Guruguhan (GEAE, Foreign National, EACOE) wrote:

 Hi All,
I have written a perl code for filtering data contained in a file 
 ($input_file_name) based on the filter expression($expr). While doing this, I face 
 some problems. When I hard code the arrays @data and @col

 ( in red color)

Please don't do that.  HTML is filtered out of postings to this list, so anything that 
relies on markup will be lost.

 in the code, I am getting the results. But the moment I get the arrays @col and 
 @data based on the user input file ($input_file_name) inside the if loop, there is 
 no filter. The reason is @data array inside the if loop (red colored) when 
 accessed outside has only one value and that doesn't satisfy the filter expression. 
 Then I changed it look like the one given in blue color. Now I don't know how should 
 I modify
 1. the sub routine sub filterdata
 2. my @result array
 3. print join function
 All the three are highlighted in blue color.

 Can some one please suggest me what changes I have to do, so that I can get the 
 results? Any help in this regard is solicited.


 #! /usr/bin/perl -w
 use strict; #- matter of style

Yes--do use strict, and no--it is not just amatter of style.

 use warnings;   #- and again

Likewise as above.  Not just a matter of style, but a critical necessity if you wish 
to learn how to write solid, orbust programs in Perl.



 my (@col,@data,$input_file_name,@temp,$header,$data_line,$i);

Don't do this.  Declaring all your variables in an unrelated lump defeats the purpose 
of using strict.  Declare your variables as close as possible to the place where they 
are initialized.


 $input_file_name= MC_data.dat;

if (-s $input_file_name ) {
 open(INPUT, $input_file_name) || die Cannot open: \nReason: $!\n;

Don't indent here.  Indentation should mark execution blocks.  The flow of execution 
does not change here, so all lines within this if statement should be vertically 
aligned.


 @temp = INPUT ;

Here is your immediate problem.  The line above puts the first line of the file into 
the first element of @temp.  If you must dump all your data into an array, then you 
will have to put the input operation into list context by enclosing it in parentheses:
 @temp = (INPUT);


 chomp @temp;
 $header = shift(@temp);
 $header =~ s/^\s+(.*)/$1/; #Remove the leading white spaces
 @col = split /\s+/, $header;

 foreach $i ( 0 .. $#temp ) {

Do indent here.  Everything within this for loop should be indented by however many 
spaces you are using as standard indentation.  Indent after the opening brace.  
Unindent the line that holds the closing brace.

perldoc perlstyle


 $data_line = $temp[$i];
 $data_line =~ s/^\s+(.*)/$1/; #Remove the leading white spaces
 @data = split /\s+/, $data_line;

@data, huh?  Is there anything you would be processing that is not data?!?  Use 
variable names that mean something.


 $data[$i] = split /\s+/, $data_line;
 }
}

 @col = qw (RUN a1 a2 a3 weight sig1 sig2 sig3);

 @data=(
   [qw( 1   0.20   0.20   0.20   0.76568575881.9
 29289.3 -46592.6)],

Why qw?  These all look like numbers to me.  Much more clear to write:
 [1,  0.2,   0.2,  0.2,   0.765685,75881.9, 29289.3, -46592.6],
Unless there is some very good reason why these *must* be stored as character strings 
rather than numbers.


   [qw( 2   0.200345   0.20   0.200345   0.9175766.0
 29268.4 -46497.6)],
   [qw( 3   0.20   0.200345   0.20   0.76603075867.1
 29259.8 -46607.4)],
   [qw( 4   0.359575   0.253987   0.359575   1.27101943898.7
 19675.6 -24223.1)],
   [qw( 5   0.359921   0.253987   0.359921   1.27199543861.3
 19666.1 -24195.2)]
 );

 map

What array is being assigned the return value of map?  If you are not trying to return 
an array, map is not an appropriate tool.  You should probably be using a for loop to 
iterate through the array.

 { my $i=$_;

What are you doing with $r?  Where are you using it?  Please don't assign things to 
variables that then vanish into thin air.

 no strict 'refs'; *{filter::$col[$i]} = sub{$_-[$i]} }

This probably does something.  It's really not worth it to try to figure out what, 
though.  Do you understand what it is doing?  If you do not, then don't use it.  Hint: 
 if you have to turn strict off, you probably are doing something that will be 
undependable.

Calling well-constructed subroutines is much more simple and clear than this
filterdata($validation_function_ref, @lines_to_be_tested);


 0..$#col;

 sub filterdata
 {
 my $cref=shift;
 grep $cref,@_
 }

 sub filterspec
 {
 my $e = shift;
 map{ $e =~ s/\b$_\b/filter::$_()/g } @col;
 eval sub{ $e }
 }

 my $expr = weight  1.2  sig1  75800;

 my $filter_handler = filterspec( $expr ) or die $@;

 my