Re: Dynamic Hash

2003-11-18 Thread R. Joseph Newton
Kent, Mr. John wrote:

 Greetings,

 Am using perl to dynamically write some JavaScript code
 that creates cool drop down button menus by Ger Versluis found
 on http://www.dynamicdrive.com  ( for those who want to
 know why).

 Have a directory structure in which the target files are located
 at various levels of sub-directories.

 Trying to create a dynamically sized hash of unknown dimensions
 where each sub directory name is a dimension of the hash and it
 gets assigned the file.

Please read the documentation on hashes before making assumptions about how they look. 
 There are ways to use a string as a
variable name, but that is a very advanced issue.  There are almost always better ways 
to do things



 For example
 my(%HASH);
 $HASH{$sub1}{$sub2}{$sub3} = $file1;
 $HASH{$sub1}{$sub2}{$sub3}{$sub4}{$sub5} = $file2;

Nope.  Hashes cannot be contained inside other structures.
The constructors for both arrays and hashes use lists of scalars.  When you put a hash 
or array directly into another
structure, you flatten it tpo a list of scalars, squeezing the magic out of it in 
the process:

   ***

Greetings! E:\d_drive\ocf\discuss\prototypeperl -w
my %ordianl_hash = (first = 1, second = 2, third = 3);
my @array = (5, 6, %ordianl_hash, 34, 'Jack Sprat');
print $_,  foreach @array;
print \b\b  \n\n;
print $array[2]\n;
^Z
5, 6, first, 1, second, 2, third, 3, 34, Jack Sprat

first

**
If you wish to make progress in the direction of multi-dimensional data structures, 
you *must* become adept at using
references.  Perl provides no alternate means of handling the issue.

 Here is what I tried, unsuccessfully

 no strict 'refs'

 # @TERMS is an array of each sub-directory name up to the one containing the target 
 file

 my(%NAV_HASH);
# Build the multi-dimensional hash
  my($hash_string) = NAV_HASH;
  foreach my $sub_dir (@TERMS){
  $hash_string .= {\$sub_dir\};
  }
  print hash_string = $hash_string\n if ($DEBUG == 1);  # - This looks 
 good
  # Producing a hash_string = 
 NAV_HASH{Africa}{focus_regions}{OEF_Somalia}{Overview}{high_low_cloud}

  # Now turn this string into a real hash and
  # assign it a value
  $$hash_string = $last,;

Strings are data.  Hashes and variables are programming structures.  Don't try to mix 
the two.

my $volume_root = {};

$volume_root-{'Program Files'} = {};
$volume_root-('WinBlows'} = {};
$volume_root-{'WinBlows'}-{'System32'} = {};

Actually, here you could skip the second statement, even, since the assignment to a 
sub-reference auto-vivifies the keys in
between.

Greetings! E:\d_drive\ocf\discuss\prototypeperl -w
my $volume_root = {};
$volume_root-{'WinBlows'}-{'System32'} = {};
$volume_root-{'WinBlows'}-{'System32'}-{'name'} = 'Dirty Tricks';
print $volume_root-{'WinBlows'}-{'System32'}-{'name'}\n;
^Z
Dirty Tricks

Note that this is all hard-coded, though.  The program structures were never strings 
per-se, in the same sense as data
strings.

A practical [and working] example from my current project:

#  In function launch_full_text_search:

  my $file_keys = [sort {$a = $b} keys %$files];   #  %$files = hash pointed to by 
$files
  while (my $file_key = shift @$file_keys) {   #  @$file_keys = array pointed 
to by $file_keys
seek_full_text_in_file($regex, $file_key, $files, $found_in)
  }

In the called function, seek_full_text_in_file:


sub seek_full_text_in_file {
  my ($regex, $file_key, $files, $found_in) = @_;

  my $file = $files-{$file_key};
  open IN, $file or die Could not open $file $!;
  my $line;
  $line = IN until $line and $line eq \x0A;
  {
local $/;
$line = IN;
$line =~ s/[\012\015]/ /g;
if (my $count = () = $line =~ /$regex/gi) {
  $found_in-{$file_key}-{filename} = $file if not $found_in-{$file_key};
  $found_in-{$file_key}-{count} += $count;
}
  }
}

This does not get as deeply nested as a directory tree, of course, but you should be 
able to see how references link together
the layers of the structure.  Once you get the hang of using references, you can use 
them to drill down as far into
structures as you want.  Note also that the original structures in the calling 
function are modified by the actions using the
reference.  This can be very powerful.

perldoc perlref
perldoc perlreftut

Joseph



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



Re: pagination of dbi results on html browser

2003-11-18 Thread R. Joseph Newton
A L wrote:

 Hi Everyone at [EMAIL PROTECTED],
 Threre are two main questions:
 1. How can I get to make results from mysql db to be displayed on web browser with 
 pagination?  Meaning, when there are too many results from the db, it only displays 
 20 results at a time-like that of google-and show links to rest of the results by 
 giving page numbers.  I've used Data::Page module from CPAN, but I can only get it 
 to print out the result to the web statically without giving links to other pages 
 and all the results are still displayed on one page when there should be 33 pages or 
 more (the total pages number changes as more stuff are added to the db).  Also, 
 DBIx::Pager from CPAN was looked (I'm still working on it to work), but it doesn't 
 seem like it is not going to do what I'm expecting.  Am I looking at the right 
 places?  If not, will you tell me what I should be looking at?

Try this:

Save the whole result set to a local temp file.  You'll need a routine for generating 
the temp file, and the folder should be used only for the temp files from your 
program, since you'll want to routinely unlink all files older than an hour or two.

Read the file twenty or so lines at a time, doing nothing but getting the line, then:
$offsets{$row_number} = tell DB_FILE;
for each set of twenty.  Store these offsets in a file as a set of name-value pairs
1=0   # trivial
21=1567  # not so trivial

You can open up and slurp the index file each time the user responds with a click on 
the Next or Previous link.  Your script should write the value for which is the 
current result set in the links for this information.  they should probably activate 
the submit command of some form, though so that they use POST when sending data to the 
server.

Don't expect to find all your answers here in one place.  The project you are taking 
on involves three distinct sytems at least--the web server, the clients browser 
environment, and the database engine.  Each has its own rules and its own modus 
operandi.

 2.  I'm trying to creat the select all button and deselect all button in one button. 
  Meaning, when I click on the button, it selects all the checkboxes displayed  and 
 turns to deselect all button; when I click on the button, again, with all the check 
 boxes checked, I uncheck all the boxes and return the button to select all button.  
 When I search for this on the web, most of them give javascript results.  I would 
 like to use Perl.  Is it possible to do this with Perl?  If so, what should I be 
 looking at?  At CPAN, only thing that results is toc and cgi where I couldn't get 
 what I'm looking for?  Have I not looked carefully and missed something?

As others have pointed out, Perl operates on the server.  for good reasons, content 
providers on the Internet to not have access to high-end APIs on the client side.  
Basically, that is the business of the owner of the client machine.
Browsers provide Javascript and the Java Virtual Machie as safely-circumscribed 
environments where web pages can run those functions necessary to properly display 
their content, without exposing the sytem to external attack.



 Okay, I'm not sure if I should insert my codes here because I haven't yet tried 
 something that would do what I want to do.  But, if you think that will help you 
 understand my questions better, I will do so.  Thanks for your time.

 Angela

For the kind of thing you want to do, you will probably have to use Javascript.  There 
are lists and groups available to help with the client-side issues.  We can help with 
some of the general Perl programming issues.  The folks at beginners-cgi group can 
help with more specific questions about server-side programming.

What is your overall Perl background?  Have you studied the basic concepts of 
command-line programming with Perl?  If not, you should make sure that you get some 
basic training in Perl before trying to build an online data access system.

Joseph



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



Re: pagination of dbi results on html browser

2003-11-18 Thread Hacksaw
 A L wrote:
 
 1. How can I get to make results from mysql db to be displayed on web 

 Try this:
 
 Save the whole result set to a local temp file.  You'll need a routine for  
 Read the file twenty or so lines at a time, doing nothing but getting the 

A simpler answer is to use the LIMIT qualifier on the SELECT line in the query 
into the database. See the MySQL documentation.


-- 
Music is a quality, organised in sound and in time.
http://www.hacksaw.org -- http://www.privatecircus.com -- KB1FVD



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



Re: Perl Equavlent

2003-11-18 Thread R. Joseph Newton
Tore Aursand wrote:

 On Sun, 16 Nov 2003 23:24:29 -0800, R. Joseph Newton wrote:
  If you want to round, use:
  my $rounded = int ($float_value + 0.5);

 ...which only works if you have a positive number.  You must make it a bit
 more foolproof;

   my $rounded = ($nr  0) ? int($nr + 0.5) : int($nr - 0.5);

 --
 Tore Aursand [EMAIL PROTECTED]

Good point.

Joseph


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



Re: pagination of dbi results on html browser

2003-11-18 Thread R. Joseph Newton
Jeff 'japhy' Pinyan wrote:


 The way I've done this is:

   use DBI;
   use CGI 'param';

   my $dbh = DBI-connect($dsn, $username, $password, { RaiseError = 1 });
   my $offset = param('offset') || 0;
   my $limit = 10;
   my ($prev, $next) = ($offset - $limit, $offset + $limit);
   $prev = 0 if $prev  0;

   my $query = qq{ SELECT * FROM table WHERE f=? LIMIT $offset, $limit };
   my $n_query = qq{ SELECT * FROM table WHERE f=? LIMIT $next, 1 };
   my $arg = param('arg');

Cool.  Definitely a neater solution than the one I proposed, as long as the DB
supports cursors.  I'm not sure,
how generally are they supported?  It seems like the result set would have to
be stored somewhere between
calls, too, in such a scenario.

Joseph


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



Strange characters

2003-11-18 Thread chetak.sasalu

Hi,
 
 when I open perldoc in cygwin ,I get some formatting characters like
ESC[1m...) along with the text.
   Below is a cp/paste of what I see on my screen.

--
1::NET::FTP(3)   User Contributed Perl Documentation
.1::NET::FTP(3)
ESC[1mNAMEESC[0m
   Net::FTP - FTP Client class
ESC[1mSYNOPSISESC[0m
   use Net::FTP;

--

  Can I use vi to open perldoc ?

Cheers,
Chetak

Confidentiality Notice

The information contained in this electronic message and any attachments to this 
message are intended
for the exclusive use of the addressee(s) and may contain confidential or privileged 
information. If
you are not the intended recipient, please notify the sender at Wipro or [EMAIL 
PROTECTED] immediately
and destroy all copies of this message and any attachments.

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



Re: pagination of dbi results on html browser

2003-11-18 Thread A L


R. Joseph Newton [EMAIL PROTECTED] wrote: A L wrote:

 Hi Everyone at [EMAIL PROTECTED],
 Threre are two main questions:
 1. How can I get to make results from mysql db to be displayed on web browser with 
 pagination? Meaning, when there are too many results from the db, it only displays 
 20 results at a time-like that of google-and show links to rest of the results by 
 giving page numbers. I've used Data::Page module from CPAN, but I can only get it to 
 print out the result to the web statically without giving links to other pages and 
 all the results are still displayed on one page when there should be 33 pages or 
 more (the total pages number changes as more stuff are added to the db). Also, 
 DBIx::Pager from CPAN was looked (I'm still working on it to work), but it doesn't 
 seem like it is not going to do what I'm expecting. Am I looking at the right 
 places? If not, will you tell me what I should be looking at?

Try this:

Save the whole result set to a local temp file. You'll need a routine for generating 
the temp file, and the folder should be used only for the temp files from your 
program, since you'll want to routinely unlink all files older than an hour or two.

Read the file twenty or so lines at a time, doing nothing but getting the line, then:
$offsets{$row_number} = tell DB_FILE;
for each set of twenty. Store these offsets in a file as a set of name-value pairs
1=0 # trivial
21=1567 # not so trivial

You can open up and slurp the index file each time the user responds with a click on 
the Next or Previous link. Your script should write the value for which is the current 
result set in the links for this information. they should probably activate the submit 
command of some form, though so that they use POST when sending data to the server.

Don't expect to find all your answers here in one place. The project you are taking on 
involves three distinct sytems at least--the web server, the clients browser 
environment, and the database engine. Each has its own rules and its own modus 
operandi.

###Lots of things that you have mentioned have to be looked up.  But, I do appreciate 
more possibilities of doing one thing in diffrerent ways.

snippet

 Okay, I'm not sure if I should insert my codes here because I haven't yet tried 
 something that would do what I want to do. But, if you think that will help you 
 understand my questions better, I will do so. Thanks for your time.

 Angela

For the kind of thing you want to do, you will probably have to use Javascript. There 
are lists and groups available to help with the client-side issues. We can help with 
some of the general Perl programming issues. The folks at beginners-cgi group can help 
with more specific questions about server-side programming.
###I'll post more specific cgi questions at beginners-cgi group.  However, I do see 
some people who are here are there as well:)


What is your overall Perl background? Have you studied the basic concepts of 
command-line programming with Perl? If not, you should make sure that you get some 
basic training in Perl before trying to build an online data access system.

Joseph
###My background...  Well, I had my first encounter with Perl in the Fall of 2000.  It 
was not pretty.  At the time, my only programming experience was Pascal taken as a 
high school student.  However, I really wanted to learn programming better, and was 
told that Perl is the language to learn to get things done.  But, I hated Perl the 
first time because I had a huge issue with debugging when it won't let me do things 
because I missed a period or something important, which I was unaware of.  Then, I 
learned a little bit of Java.  I liked Java with all its structures and class less 
than I did Perl.  Now, I'm trying to master Perl to an extent where I feel comfortable 
enough to create things I want to create without feeling at a total loss or 
frustration to call a computer stupid for not doing what I had written.  Also, I'm 
using Linux.  So, to answer your question about studying the basic concepts of 
command-line programming with Perl, I think that I do know a little bit to test my
 codes, but I do have my Perl reference manuals beside me to look up things whenever 
necessary, as I am always learning something new and cool.

Angela


-
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard

RE: File upload script

2003-11-18 Thread Dan Muey
 I'm trying to allow users to upload their own webpages. I 
 have both binary and text format. Although, its probably ok 
 to upload the webpages in binary mode and it would bother the 
 webserver.
 

If it's browser based uploads CGI can help you.
Otherwise you may be interested in Net::FTP.

So it depends on your needs, sorry to be so vague!

HTH
DMuey

 In any case, I'm wondering if use CGI is the package to use 
 and if there is a cpan module that someone can recommend?
 
 thanks
 

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



Re: matching

2003-11-18 Thread Eric Walker
The /g modifier worked thanks all.  I needed to take the quotes in the
file and backslash them so the file could be read into one of our tools
without a problem.  Thanks for the short version too.  I never thought
of it that way.

Newbie..

On Mon, 2003-11-17 at 20:37, Tore Aursand wrote:

On Mon, 17 Nov 2003 15:18:47 -0700, Eric Walker wrote:
 How do I get it to do more than one substitution in the string.

By using the /g modifier.

 $_ = $$Rules{$yes}{rule_desc};

No.  Don't _ever_ try to set $_ yourself, unless you _really_ have to
(which you don't in this case).

 $_ = $$Rules{$yes}{rule_desc};
 s//\\/;
 $$Rules{$yes}{rule_desc} = $_;

These three lines could easily have been shortened down to only one;

  $$Rules{$yes}{rule_desc} =~ s//\\/g;

However:  Why do you need to quote the  characters?


-- 
Tore Aursand [EMAIL PROTECTED]


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




CPAN or ?

2003-11-18 Thread Tim
Hi,
I need some help in using CPAN or other means to figure out what modules 
are on my system.

I just installed 5.8.1 after wiping the RedHat 9 distribution off of my new 
RH9 install, due to claims of slowness (and desire to keep an older version 
of Apache, mod_perl). I've tried the 'r' command, but Iam not sure if that 
refers only to what has been installed by CPAN.pm or what all is in @INC.
Any enlightenment would be most appreciated.

(While I'm at the well...) My pager in CPAM.pm (less) doesn't seem to page, 
at least when I do an 'r'.

Thanks, profusely.
Cheers,
Tim
email: mailto:[EMAIL PROTECTED]

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


Re: matching

2003-11-18 Thread Tim
At 03:18 PM 11/17/03 -0700, you wrote:
I have the following code to find a quote in a string and replace it
with a slashquote.
ie  goes to \

How do I get it to do more than one substitution in the string.

$_ = $$Rules{$yes}{rule_desc};
s//\\/;
$$Rules{$yes}{rule_desc} = $_;
newbie...
Put a g before the second semicolon above.



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


Can a regex match numbers?

2003-11-18 Thread Jabez Wilson


Hello, please can you help me. Is it possible to specify number matching in a regex, 
i.e. can you have something like:

my $match =~ m/match_number_if_number_is_less_than_255/

instead of my $match =~ m/(\d{3})/;

if ($1=255){my @array = @array +$1}?


-
Want to chat instantly with your online friends? Get the FREE Yahoo!Messenger

Re: CPAN or ?

2003-11-18 Thread Wiggins d Anconia


 Hi,
 I need some help in using CPAN or other means to figure out what modules 
 are on my system.
 
 I just installed 5.8.1 after wiping the RedHat 9 distribution off of
my new 
 RH9 install, due to claims of slowness (and desire to keep an older
version 
 of Apache, mod_perl). I've tried the 'r' command, but Iam not sure if
that 
 refers only to what has been installed by CPAN.pm or what all is in @INC.
 Any enlightenment would be most appreciated.
 
 (While I'm at the well...) My pager in CPAM.pm (less) doesn't seem to
page, 
 at least when I do an 'r'.
 
 Thanks, profusely.

perldoc CPAN

'r' refers to all of the modules (at least I believe) that are available
in @INC, *but* only checks for modules that have a new version on CPAN.

If you want to see everything that is available in @INC for a particular
 perl (remember this includes PERL5LIB and .) that has a .pm extension
you may want to try something such as:

find `perl -e 'print @INC'` -name '*.pm' -print

That combined with a grep (shell) generally tells me what I need to know.

A quick glance at the source for CPAN (5.8.0) indicates that the pager
is only used for viewing READMEs though I didn't remember this about it.

http://danconia.org

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



Re: Printing ASCII to Hex

2003-11-18 Thread James Edward Gray II
On Nov 18, 2003, at 10:33 AM, Jeff Westman wrote:

There must be an easier way to convert a basic ascii string to hex.  I 
tried
using ord/chr/unpack/sprintf(%x) combinations and just dug my hole 
deeper.
I'm not interested in using any additional modules, just straight, 
basic
perl. This works, but exactly elegant:
This one-liner produces identical output:

perl -e 'print x, unpack(H*, some string), \n'

That doesn't seem too complex, does it?

Hmm, let's take a look...

#!/bin/perl

use strict;
use warnings;
my $str = some string;
my $hex = unpack('H*', $str);
The line above is 100% of the hex conversion.  That's too cumbersome??? 
 I doubt we can do much better.

my $len = length($hex);
my $start = 0;
print x';
while ($start  $len) {
print substr($hex,$start,2);
$start += 2;
}
print '\n;
Ah, the long part!  Printing two characters at a time.  Any reason to 
do this?  Well, surely we can do it quicker:

print 'x';
for (my $i = 0; $i  length $hex; $i+=2) {
print substr $hex, $i, 2;
}
print \n;
Is that better?  I'll let you decide.  It's pretty C-looking, but that 
probably doesn't have to be a bad thing.

Any of this help?

James

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


Re: Can a regex match numbers?

2003-11-18 Thread Wiggins d Anconia


 
 
 
 Hello, please can you help me. Is it possible to specify number
matching in a regex, i.e. can you have something like:
 
 my $match =~ m/match_number_if_number_is_less_than_255/
 
 instead of my $match =~ m/(\d{3})/;
 
 if ($1=255){my @array = @array +$1}?
 

Well your example is a fairly common one and gets a lot of attention in
the Mastering Regular Expressions book (which is excellent), and
concludes with:

[01]?\d\d?|2[0-4]\d|25[0-5]

But you should really not just use this willy-nilly, if *you* don't
understand it the person coming after you (which might just be you!)
won't likely either.  So in many cases it is better to know your data,
do some pre-parsing then compare numbers using standard arithmetic as
you have shown.  The real question is what's wrong with what you have?

http://danconia.org

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



Portable unix du command

2003-11-18 Thread Dan Muey
Howdy group.

I have a need to get the size of a directory.
I could just execute unix's du command (my $sz = `du -sh /usr`;)
but was wondering if there's a better way to do it that is more portable.
I looked on cpan but didn't see anythign that jumped out at me.

TIA

Dan


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



Re: Can a regex match numbers?

2003-11-18 Thread Andrew Gaffney
Wiggins d Anconia wrote:



Hello, please can you help me. Is it possible to specify number
matching in a regex, i.e. can you have something like:

my $match =~ m/match_number_if_number_is_less_than_255/

instead of my $match =~ m/(\d{3})/;

if ($1=255){my @array = @array +$1}?



Well your example is a fairly common one and gets a lot of attention in
the Mastering Regular Expressions book (which is excellent), and
concludes with:
[01]?\d\d?|2[0-4]\d|25[0-5]

But you should really not just use this willy-nilly, if *you* don't
understand it the person coming after you (which might just be you!)
won't likely either.  So in many cases it is better to know your data,
do some pre-parsing then compare numbers using standard arithmetic as
you have shown.  The real question is what's wrong with what you have?
I've been in his position many times before while learning Perl. You see all of these 
amazing everything-and-the-kitchen-sink one-liners and if your code doesn't turn out like 
that then you are doing something wrong. Its now obvious to me that this is not true at 
all, but I believe that a lot of people who are learning Perl think like this.

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


Re: Portable unix du command

2003-11-18 Thread drieux
On Tuesday, Nov 18, 2003, at 09:20 US/Pacific, Dan Muey wrote:

Howdy group.

I have a need to get the size of a directory.
I could just execute unix's du command (my $sz = `du -sh /usr`;)
but was wondering if there's a better way to do it that is more 
portable.
I looked on cpan but didn't see anythign that jumped out at me.

a part of the problem is that the 'du' command
is basically implemented differently between the
BSD and SYSV styles of unix. One strategy that
I have adopted when I am looking at a 'common'(HA!)
unix utility that I would like to use, and
in your illustration, the 'flags' to it, that
are problematic, I create a wrapper class.
a quicky way to think about your problem would
be my WhackJob for dealing with my 'favorite'
set of flags to the 'ps' command:
cf
http://www.wetware.com/drieux/CS/Proj/PID/
To be honest, I use something like that, but more
cleaned up in a project I have. The trick of
course is getting 'illustrations' from all of the
OS's that you will want to be 'portable' with.
HTH.

ciao
drieux
---

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


Re: Printing ASCII to Hex

2003-11-18 Thread John W. Krahn
Jeff Westman wrote:
 
 Hi,

Hello,

 There must be an easier way to convert a basic ascii string to hex.  I tried
 using ord/chr/unpack/sprintf(%x) combinations and just dug my hole deeper.
 I'm not interested in using any additional modules, just straight, basic
 perl. This works, but exactly elegant:
 
 #!/bin/perl
 
 use strict;
 use warnings;
 
 my $str = some string;
 my $hex = unpack('H*', $str);
 
 my $len = length($hex);
 my $start = 0;
 
 print x';
 while ($start  $len) {
 print substr($hex,$start,2);
 $start += 2;
 }
 print '\n;
 
 Produces:
 x'736f6d6520737472696e67'

One way to do it:

my $str = 'some string';

$str =~ s/(.)/ sprintf '%02x', ord $1 /seg;

print x'$str'\n;



John
-- 
use Perl;
program
fulfillment

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



RE: Capture a range from a mp3 track ?

2003-11-18 Thread Dan Muey
 I am trying to write a script which plays a range (input) 
 from a mp3 file.
 
 Simply to say, a mp3 file is divided into 3 session, Audio 
 data, audio header, and IDvX tags.
 
 What I will deal with my script is to get the bit rate from 
 the header, and calc the start-end position of the data from 
 the audio data, after this, I will have to 
 modify the header, so to reform the complete file, and then 
 to play it as an 
 embedded media with html.
 
 But I have no idea on how to start with it while I am dealing 
 with is binary 
 data... Any approach could lead me to start ?

I'd say have a look here:
http://search.cpan.org/search?query=mp3mode=all

I'm not experienced with mp3 manipulation but that's where I'd start!

HTH

Dmuey

 
 Thanks a lot
 
 
 
 

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



RE: Portable unix du command

2003-11-18 Thread Dan Muey

 On Tuesday, Nov 18, 2003, at 09:20 US/Pacific, Dan Muey wrote:
 
  Howdy group.
 
  I have a need to get the size of a directory.
  I could just execute unix's du command (my $sz = `du -sh 
 /usr`;) but 
  was wondering if there's a better way to do it that is more 
 portable.
  I looked on cpan but didn't see anythign that jumped out at me.
 
 
 a part of the problem is that the 'du' command
 is basically implemented differently between the
 BSD and SYSV styles of unix. One strategy that
 I have adopted when I am looking at a 'common'(HA!)
 unix utility that I would like to use, and
 in your illustration, the 'flags' to it, that
 are problematic, I create a wrapper class.
 
 a quicky way to think about your problem would
 be my WhackJob for dealing with my 'favorite'
 set of flags to the 'ps' command:
 
 cf
 http://www.wetware.com/drieux/CS/Proj/PID/
 
 To be honest, I use something like that, but more
 cleaned up in a project I have. The trick of
 course is getting 'illustrations' from all of the
 OS's that you will want to be 'portable' with.
 

Thanks. What I really want to do is avoid system commands completely.
I could always traverse the directory adding the size of each file 
together and do that all in Perl with no system commands but I figured 
there'd already be a Module or something like this, so I want to do it 
that way. Somthign like:

 my $sz = $module-size(/home/joemama); 
# return sixze of file or of entire directory if specified file is a directory

 HTH.
 
 ciao
 drieux

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



Re: Portable unix du command

2003-11-18 Thread drieux
On Tuesday, Nov 18, 2003, at 09:35 US/Pacific, Dan Muey wrote:
[..]
Thanks. What I really want to do is avoid system commands completely.
I could always traverse the directory adding the size of each file
together and do that all in Perl with no system commands but I figured
there'd already be a Module or something like this, so I want to do it
that way. Somthign like:
 my $sz = $module-size(/home/joemama);
# return sixze of file or of entire directory if specified file is a 
directory
I can appreciate the desire, but remember that
systems applications - such as 'du' and 'ps'
are there so that folks do not have to know all
of the OS specific underlying 'system calls' that
will flop into 'kernal space'.
The fine folks who are maintaining the Proc::Table
module deliver XS code that gets converted into
the 'c' code that becomes the dynamically loadable
library that is referenced in the perl module
Which is why I opted to take the 'sillier' path
of simply working out which command line arguments
were the 'right ones' for Me based upon the four
or five basic *nix versions that I work with and
then go through the process that way.
If you want to have fun, then you will of course
want to become friends with stat(), cf perldoc -f stat
and/or read the POSIX module, cf perldoc POSIX.
Or download a copy of the open source for 'du'
and work out which parts of it you want to use
as the basis for your own perl module.
ciao
drieux
---

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


RE: Portable unix du command

2003-11-18 Thread david
Dan Muey wrote:

 
 On Tuesday, Nov 18, 2003, at 09:20 US/Pacific, Dan Muey wrote:
 
  Howdy group.
 
  I have a need to get the size of a directory.
  I could just execute unix's du command (my $sz = `du -sh
 /usr`;) but
  was wondering if there's a better way to do it that is more
 portable.
  I looked on cpan but didn't see anythign that jumped out at me.
 

[snip]

 Thanks. What I really want to do is avoid system commands completely.

good decision.

 I could always traverse the directory adding the size of each file
 together and do that all in Perl with no system commands but I figured
 there'd already be a Module or something like this, so I want to do it
 that way. Somthign like:
 
  my $sz = $module-size(/home/joemama);

try Filesys::DiskFree

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

use Filesys::DiskFree;

my $h = Filesys::DiskFree-new;

$h-df;
$h-device('/usr');

print /usr has ,$h-avail('/usr'), bytes available\n;

__END__

prints:

/usr has 1 bytes available

david
-- 
s,.*,,e,y,\n,,d,y,.s,10,,s
.ss.s.s...s.sss.s.ss
s.s.s...s...s..s
...s.ss..s.sss..ss.sss.s
s.s.s...ss.sss.s
..s..sss.s.ss.sss...
..ssss.sss.sss.s

,{4},|?{*=}_'y!'+0!$;
,ge,y,!#:$_(-*[./[EMAIL PROTECTED],b-t,
.y...,$~=q~=?,;^_#+?{~,,$~=~
y.!-*-/:[EMAIL PROTECTED] ().;s,;,
);,g,s,s,$~s,g,y,y,%,,g,eval

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



Re: Printing ASCII to Hex

2003-11-18 Thread Jeff Westman
James Edward Gray II [EMAIL PROTECTED] wrote:

 On Nov 18, 2003, at 10:33 AM, Jeff Westman wrote:
 
  There must be an easier way to convert a basic ascii string to hex.  I 
  tried
  using ord/chr/unpack/sprintf(%x) combinations and just dug my hole 
  deeper.
  I'm not interested in using any additional modules, just straight, 
  basic
  perl. This works, but exactly elegant:
 
 This one-liner produces identical output:
 
 perl -e 'print x, unpack(H*, some string), \n'

Looks great.  How could I have missed that?!
 
 That doesn't seem too complex, does it?
 
 Hmm, let's take a look...
 
  #!/bin/perl
 
  use strict;
  use warnings;
 
  my $str = some string;
  my $hex = unpack('H*', $str);
 
 The line above is 100% of the hex conversion.  That's too cumbersome??? 
   I doubt we can do much better.
 
  my $len = length($hex);
  my $start = 0;
 
  print x';
  while ($start  $len) {
  print substr($hex,$start,2);
  $start += 2;
  }
  print '\n;
 
 Ah, the long part!  Printing two characters at a time.  Any reason to 
 do this?

Originally, I wanted to print individually ASCII characters into hex, such
as,

x'73' x'6f' x'6d' (etc)

   Well, surely we can do it quicker:
 
 print 'x';
 for (my $i = 0; $i  length $hex; $i+=2) {
   print substr $hex, $i, 2;
 }
 print \n;
 
 Is that better?  I'll let you decide.  It's pretty C-looking, but that 
 probably doesn't have to be a bad thing.
 
 Any of this help?

Yep, thanks!

-Jeff

__
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree

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



RE: Portable unix du command

2003-11-18 Thread Bob Showalter
Dan Muey wrote:
 Howdy group.
 
 I have a need to get the size of a directory.
 I could just execute unix's du command (my $sz = `du -sh /usr`;)
 but was wondering if there's a better way to do it that is
 more portable.
 I looked on cpan but didn't see anythign that jumped out at me.

There's a group working on implementing a number of Unix utilities in Perl.
Here's their du page:

  http://www.perl.com/language/ppt/src/du/index.html

I don't know how portable it is...

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



RE: Portable unix du command

2003-11-18 Thread Dan Muey
 Dan Muey wrote:
  
  Thanks. What I really want to do is avoid system commands 
 completely. 
  I could always traverse the directory adding the size of each file 
  together and do that all in Perl with no system commands 
 but I figured 
  there'd already be a Module or something like this, so I 
 want to do it 
  that way. Somthign like:
 
 You mean something like (untested):
 
 use File::Find;
 
 my $dir = '/some/dir';
 my $size;
 
 find( sub { -f and ( $size += -s _ ) }, $dir );
 
 print Directory '$dir' contains $size bytes\n;
 
 

Awesome John! Works splendedly, this is exactly what I needed!

 
 John
 -- 
 use Perl;
 program
 fulfillment

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



Re: CPAN or ?

2003-11-18 Thread Tore Aursand
On Tue, 18 Nov 2003 11:29:39 -0500, Tim wrote:
 I need some help in using CPAN or other means to figure out what modules
 are on my system.

This is answered in the FAQ;

  perldoc -q installed

Note that you'll have a new set of @INC libraries when you install a new
Perl, which is a good thing; A lot of the modules may need to be
recompiled with the new Perl.


-- 
Tore Aursand [EMAIL PROTECTED]


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



Re: Strange characters

2003-11-18 Thread Viren Konde
Hi,
Install recent perldoc from CPAN..and try perldoc :)
HTH,
Virnya
Chetak Sasalu wrote:

Hi,
 

 when I open perldoc in cygwin ,I get some formatting characters like
ESC[1m...) along with the text.
   Below is a cp/paste of what I see on my screen.

--
1::NET::FTP(3)   User Contributed Perl Documentation
..1::NET::FTP(3)
ESC[1mNAMEESC[0m
   Net::FTP - FTP Client class
ESC[1mSYNOPSISESC[0m
   use Net::FTP;

--
  Can I use vi to open perldoc ?

Cheers,
Chetak
Confidentiality Notice

The information contained in this electronic message and any attachments to this 
message are intended
for the exclusive use of the addressee(s) and may contain confidential or privileged 
information. If
you are not the intended recipient, please notify the sender at Wipro or [EMAIL 
PROTECTED] immediately
and destroy all copies of this message and any attachments.


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


Re: Strange characters

2003-11-18 Thread Viren Konde
Hi,
Install recent Pod-Perldoc-3.12 module from CPAN..
http://search.cpan.org/~sburke/Pod-Perldoc-3.12/
and try perldoc again..
HTH,
Virnya
Chetak Sasalu wrote:
Hi,
 

 when I open perldoc in cygwin ,I get some formatting characters like
ESC[1m...) along with the text.
   Below is a cp/paste of what I see on my screen.

--
1::NET::FTP(3)   User Contributed Perl Documentation
..1::NET::FTP(3)
ESC[1mNAMEESC[0m
   Net::FTP - FTP Client class
ESC[1mSYNOPSISESC[0m
   use Net::FTP;

--
  Can I use vi to open perldoc ?

Cheers,
Chetak
Confidentiality Notice

The information contained in this electronic message and any attachments to this 
message are intended
for the exclusive use of the addressee(s) and may contain confidential or privileged 
information. If
you are not the intended recipient, please notify the sender at Wipro or [EMAIL 
PROTECTED] immediately
and destroy all copies of this message and any attachments.


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


Re: Can a regex match numbers?

2003-11-18 Thread Tore Aursand
On Tue, 18 Nov 2003 16:37:06 +, Jabez Wilson wrote:
 Is it possible to specify number matching in a regex, i.e. can you have
 something like:
 
 my $match =~ m/match_number_if_number_is_less_than_255/
 
 instead of my $match =~ m/(\d{3})/;
 
 if ($1=255){my @array = @array +$1}?

Yes, but would you?  IMO, using regular expressions to check the value of
something creates less readable code.  I tend to prefer to first check if
I'm really dealing with a number, and then checking the value of it in a
good old fashion way;

  if ( $nr =~ m,^[-+]?\d+$,  $nr  255 ) {
  # Match
  }

I don't need to write that regular expression every time, of course,
'cause I've been nice enough to put it in a module so that I only need to
write 'is_int($nr)' each time.

(And the actual implementation of the is_int() function is heavier; It
check if a number really _is_ a number - the above don't, really...)


-- 
Tore Aursand [EMAIL PROTECTED]


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



matching query.

2003-11-18 Thread Steve Massey
Hi all

I know this should be easy, but I'm at a loss

I want to match Help 

Help ## match this
Helps## not match this

I am using syntax below, but it's not working

$help = Help;

if ($source =~ /^$help/)

any ideas

Thanks in advance 

Steve

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



Re: matching query.

2003-11-18 Thread Steve Mayer
Steve,

  Change your regular expression to:

if ($source =~ /^\b$help\b)

  This sets up $help inside of a word boundry.

Steve

On Tue, Nov 18, 2003 at 09:22:07PM -, Steve Massey wrote:
 Hi all
 
 I know this should be easy, but I'm at a loss
 
 I want to match Help 
 
 Help ## match this
 Helps## not match this
 
 I am using syntax below, but it's not working
 
 $help = Help;
 
 if ($source =~ /^$help/)
 
 any ideas
 
 Thanks in advance 
 
 Steve
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 

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



Re: matching query.

2003-11-18 Thread James Edward Gray II
On Nov 18, 2003, at 3:22 PM, Steve Massey wrote:

Hi all
Howdy.

I know this should be easy, but I'm at a loss

I want to match Help

Help ## match this
Helps## not match this
I am using syntax below, but it's not working

$help = Help;

if ($source =~ /^$help/)
if ($source eq $help) ...

or maybe

if ($source =~ /\b$help\b/) ...

The first matches if $source equals help exactly.  The second matches 
if $source contains the word help, surrounded by word boundaries like 
spaces.

Hope that helps.

James

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


Word replacement

2003-11-18 Thread Jason Dusek
Hi There,

How do I read a file and replace all occurences of a word in it with 
another word.  For example, I want to read the file BUS_SCHEDULE and 
map bus to magic_bus.

- Jason

/
If A equals success, then the formula is:
X+Y+Z = A
X is work.  Y is play.  And Z is keep your mouth shut.
-Albert Einstein
 /

RE: Word replacement

2003-11-18 Thread Dan Muey
 Hi There,

Howdy

 
 How do I read a file and replace all occurences of a word in it with 
 another word.  For example, I want to read the file BUS_SCHEDULE and 
 map bus to magic_bus.
 

perl -pi -e 's/\bbus\b/magic_bus/g;' BUS_SCHEDULE

The pie tells perl tp  read the files that you 
have as arguments and process them line by line based 
on what's inbetween the ''.

So if you so a substitution that will do the trick!

HTH

Dmuey
 
 - Jason
 
 /
  If A equals success, then the formula is:
  X+Y+Z = A
  X is work.  Y is play.  And Z is keep your mouth shut.
  -Albert Einstein
   /
 

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



how do I create self aware functions

2003-11-18 Thread Dan Anderson
Is it possible to create self aware functions (possibly using a magic
variable)?  I.e. functions that know their own name.  Sort of the
oppossite of bless.

Basically, I want to create functions like:

sub foo {
  my $self = shift (@_);
  my $name = decode_blessing ($self);
}   

Does that make sense?

Thanks in advance,
Dan


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



Re: how do I create self aware functions

2003-11-18 Thread James Edward Gray II
On Nov 18, 2003, at 4:23 PM, Dan Anderson wrote:

Is it possible to create self aware functions (possibly using a magic
variable)?  I.e. functions that know their own name.  Sort of the
oppossite of bless.
You're looking for ref(), but first let me give you the This is often 
a bad idea warning.  What are you trying to use the object's name for?

James

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


Re: When MUST you use 'map' ?

2003-11-18 Thread Todd W.

Jeff Westman [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Hi,

 In my limited experience with perl, I've never had to use the 'amp'
command,
 even though I see it used all the time.  It seems to just be a short-cut
of
 other commands/keywords that I've used.

 So, when do you HAVE to use 'map', when no other option makes sense?!



Its a shortcut, so you never _have_ to use it. There was a post not too long
ago and I used map() in one of the examples.

Reverse an array without using reverse():

with an array slice and map():
[EMAIL PROTECTED] trwww]$ perl
@array = ( 1 .. 5 );
@array = @array[ map abs(), -$#array .. 0 ];
print( join(\n, @array), \n );
Ctrl-D
5
4
3
2
1

see
http://groups.google.com/groups?threadm=20030827112457.74911.qmail%40onion.perl.org

Todd W.



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



Re: [ADMIN] Re: File upload script

2003-11-18 Thread Todd W.

Casey West [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
snip /

   Casey West

 -- 
 f u cn rd ths, u cn gt a gd jb n cmptr prgmmng.


Where? =0)

Todd W.



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



Rephrasing the Question

2003-11-18 Thread Jason Dusek
Hi All,

I need to write a script that finds the uniq() function in code for a 
data manipulation language, and replaces it with hyd_uniq().  Here are 
some examples:

amend:  u= uniq( timetags.bin_start, s )
to: u= hyd_uniq( timetags.bin_start, s )
amend:  u_ens=fit_energy(uniq(fit_energy(*,i),s),i)
to: u_ens=fit_energy(hyd_uniq(fit_energy(*,i),s),i)
amend:  nxxi=n_elements(uniq(xxi(sort(xxi
to: nxxi=n_elements(hyd_uniq(xxi(sort(xxi
Now, in order to get these examples I have already written the regular 
expressions that do the trick:

s/\(uniq\(/\(hyd_uniq\(/;
s/(\W)uniq\(/$1hyd_uniq\(/;
So my script reads a file, and pulls out the lines with uniq() in them, 
and then it passes these lines to a hash organized by file name.  And 
then it goes through this hash, and prints out the filename and puts 
each line through the regular expressions given above to get the 
amend-to pairs that I printed up at the beginning of this message.  So 
the script let me know just how much work there was to do.  But I can't 
figure out how to write a script that will simply go through each of 
the files and change every

		/\Wuniq\(/

to a
/hyd_uniq(/
within the file!  How do I slurp in a file and amend it?  If this seems 
like an obscenely basic question, I apologize - I have no computer 
science training, just a copy of the Llama Book.

- Jason

/
If A equals success, then the formula is:
X+Y+Z = A
X is work.  Y is play.  And Z is keep your mouth shut.
-Albert Einstein
 /

Re: how do I create self aware functions

2003-11-18 Thread Dan Anderson
 You're looking for ref(), but first let me give you the This is often 
 a bad idea warning.  What are you trying to use the object's name for?

Debugging.  I have a function that writes errors / warnings / errata to
logs.  Sometimes it could be more transparent if I included things like
subroutine name / class /etc.

-Dan


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



Re: how do I create self aware functions

2003-11-18 Thread drieux
On Tuesday, Nov 18, 2003, at 14:27 US/Pacific, James Edward Gray II 
wrote:
On Nov 18, 2003, at 4:23 PM, Dan Anderson wrote:

Is it possible to create self aware functions (possibly using a magic
variable)?  I.e. functions that know their own name.  Sort of the
oppossite of bless.
You're looking for ref(), but first let me give you the
This is often a bad idea warning.  What are you trying
to use the object's name for?
yes and no actually. { most of the time I TOTALLY agree with you
on this point, so, well, uh... there is a time when it is useful }
He may also want to deal with say

	perldoc -f caller

since sometimes it is nice to have things like

	we were in  main, Foo::Bar::me_called, 14

the demonstration code is up at:
http://www.wetware.com/drieux/PR/blog2/Code/200311.html#id3152014937
ciao
drieux
---

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


Re: how do I create self aware functions

2003-11-18 Thread Todd W.

Dan Anderson [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
  You're looking for ref(), but first let me give you the This is often
  a bad idea warning.  What are you trying to use the object's name for?

 Debugging.  I have a function that writes errors / warnings / errata to
 logs.  Sometimes it could be more transparent if I included things like
 subroutine name / class /etc.


Make a debugging subroutine/method that uses the caller() function:

$ perldoc -f caller

it will return all the information you need to know. You can then make your
debugging subs generic.

For higher level stuff, check out Carp::Clan from CPAN. It does stack
traces.

Todd W.



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



Re: Rephrasing the Question

2003-11-18 Thread Chuck Fox
[EMAIL PROTECTED] wrote:

Hi All,
Hey Jason,

I need to write a script that finds the uniq() function in code for a 
data manipulation language, and replaces it with hyd_uniq().  Here are 
some examples:

amend:  u= uniq( timetags.bin_start, s )
to: u= hyd_uniq( timetags.bin_start, s )
amend:  u_ens=fit_energy(uniq(fit_energy(*,i),s),i)
to: u_ens=fit_energy(hyd_uniq(fit_energy(*,i),s),i)
amend:  nxxi=n_elements(uniq(xxi(sort(xxi
to: nxxi=n_elements(hyd_uniq(xxi(sort(xxi
Now, in order to get these examples I have already written the regular 
expressions that do the trick:

   s/\(uniq\(/\(hyd_uniq\(/;
   s/(\W)uniq\(/$1hyd_uniq\(/;
So my script reads a file, and pulls out the lines with uniq() in 
them, and then it passes these lines to a hash organized by file 
name.  And then it goes through this hash, and prints out the filename 
and puts each line through the regular expressions given above to get 
the amend-to pairs that I printed up at the beginning of this 
message.  So the script let me know just how much work there was to 
do.  But I can't figure out how to write a script that will simply go 
through each of the files and change every

   /\Wuniq\(/

to a
   /hyd_uniq(/
within the file!  How do I slurp in a file and amend it?  If this 
seems like an obscenely basic question, I apologize - I have no 
computer science training, just a copy of the Llama Book. 
The following one-liner should help. Many previous posts reference this 
technique.

perl -pi -e's/Wuniq\(/hyd_uniq\(/' *.c

Regards,

Chuck



- Jason

/
  If A equals success, then the formula is:
  X+Y+Z = A
  X is work.  Y is play.  And Z is keep your mouth shut.
  -Albert Einstein
 /


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


RE: Word replacement

2003-11-18 Thread Tim Johnson

Here's the textbook way to do it (TIMTOWTDI of course, but
nevertheless):

##

use strict;
use warnings;
open(INFILE,BUS_SCHEDULE) || die Couldn't open BUS_SCHEDULE for
reading!\n;
open(OUTFILE,BUS_SCHEDULE.new) || die Couldn't open BUS_SCHEDULE.new
for writing!\n;
while(INFILE){
$_ =~ s/bus/magic_bus/gi; #g for every occurrence, i for
case-insensitive
print OUTFILE $_;
}
close INFILE;
close OUTFILE;
rename(BUS_SCHEDULE.new,BUS_SCHEDULE) || die Couldn't rename the
new file!\n; #automatically kills the old file

###

Adding in the error checking and not using any magic may seem like extra
work, but in the end it really doesn't take much extra time and can save
you (or especially the next guy that has to look at your code) a lot of
time down the road.

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



fedora and findmodules script

2003-11-18 Thread Clint
I upgraded a RH9 machine to Fedora, and now the script I used to use for 
determing what CPAN modules are on my machine will not report anything 
but Perl. That is, I know I have many modules on the machine, but the 
script is not reporting them. I would appreciate any ideas about what I 
can change to fix things!

Here is the script (I found it elsewhere, and did not write it myself):

#!/usr/bin/perl -w

# This program will tell me what modules I have installed on my machine.

use ExtUtils::Installed;
my $instmod = ExtUtils::Installed-new();
foreach my $module ($instmod-modules()) {
my $version = $instmod-version($module) || ???;
   print $module -- $version\n;
}
Here is the relevant output:

[EMAIL PROTECTED] perlstuff]$ ./findmodules
Perl -- 5.8.1
However I have many up to date modules installed. I searched Redhat's 
Bugzilla for fedora perl modules but didn't turn up anything there.

Any advice would be appreciated!

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


Fedora and Findmodules Script

2003-11-18 Thread Clint
I upgraded a RH9 machine to Fedora, and now the script I used to use for 
determing what CPAN modules are on my machine will not report anything 
but Perl. That is, I know I have many modules on the machine, but the 
script is not reporting them. I would appreciate any ideas about what I 
can change to fix things!

Here is the script (I found it elsewhere, and did not write it myself):

use ExtUtils::Installed;
my $instmod = ExtUtils::Installed-new();
foreach my $module ($instmod-modules()) {
my $version = $instmod-version($module) || ???;
   print $module -- $version\n;
}
Here is the relevant output:

[EMAIL PROTECTED] perlstuff]$ ./findmodules
Perl -- 5.8.1
However I have many up to date modules installed. I searched Redhat's 
Bugzilla for fedora perl modules but didn't turn up anything there.

Any advice would be appreciated!

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


Re: Word replacement

2003-11-18 Thread John W. Krahn
Tim Johnson wrote:
 
 Here's the textbook way to do it (TIMTOWTDI of course, but
 nevertheless):

I guess it depends on your textbook.  :-)

 ##
 
 use strict;
 use warnings;
 open(INFILE,BUS_SCHEDULE) || die Couldn't open BUS_SCHEDULE for
 reading!\n;
 open(OUTFILE,BUS_SCHEDULE.new) || die Couldn't open BUS_SCHEDULE.new
 for writing!\n;
 while(INFILE){
 $_ =~ s/bus/magic_bus/gi; #g for every occurrence, i for
 case-insensitive
 print OUTFILE $_;
 }
 close INFILE;
 close OUTFILE;
 rename(BUS_SCHEDULE.new,BUS_SCHEDULE) || die Couldn't rename the
 new file!\n; #automatically kills the old file

{
local ( $^I, @ARGV ) = ( '.bak', 'BUS_SCHEDULE' );
s/\bbus\b/magic_bus/g while 
}
#  :-)


John
-- 
use Perl;
program
fulfillment

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



Re: pagination of dbi results on html browser

2003-11-18 Thread R. Joseph Newton
A L wrote:

 Joseph
 ###My background...  Well, I had my first encounter with
 Perl in the Fall of 2000.  It was not pretty.  At the
 time, my only programming experience was Pascal taken as a
 high school student.  However, I really wanted to learn
 programming better, and was told that Perl is the language
 to learn to get things done.  But, I hated Perl the first
 time because I had a huge issue with debugging when it
 won't let me do things because I missed a period or
 something important, which I was unaware of.

This is something that you will have to adapt to.
Programming is a pretty exact art.  Every character must be
there for a reason,  So is good writing for that matter.
Unfortunately, the speed with which we can send messages ahs
had its impact on the quality of proofreading.  It can be a
very healthy discipline to have to meet the demands of the
compiler.

[clip and save--I've said it before, I'll say it again]
I see the compiler as a sort of guru--a stern but fair
taskmaster that has no ego, no will or motivation of its
ownm and thus is able to reflect only what is offered to it.

[/clip]

Make the compiler your friend.  When it prints an error
message, it is because it is unable to understand the code
as written.  The Perl interpreter is particularly
forgiving.  If at all possible to make sense of the code, it
will.  Then its a bit of a detective game to locate the
errors cited.  Sometimes the errors will not be obvious,
since the compiler will read the code until it finds
something that just can't be translated.  The process of
finding those errors is also good for you.

  Then, I learned a little bit of Java.  I liked Java with
 all its structures and class less than I did Perl.

That's too bad.  Not that you prefer Perl, but to be put off
by classes and structures.  Structures and classes, and the
thinking required to develop them, are the most powerful
tools available to support creative programming.

 Now, I'm trying to master Perl to an extent where I feel
 comfortable enough to create things I want to create
 without feeling at a total loss or frustration to call a
 computer stupid for not doing what I had written.

A computer can only do what it is told.  When we see results
we don't like, we have to look at what we are telling the
compiler.

 Also, I'm using Linux.  So, to answer your question about
 studying the basic concepts of command-line programming
 with Perl, I think that I do know a little bit to test my
 codes, but I do have my Perl reference manuals beside me
 to look up things whenever necessary, as I am always
 learning something new and cool.

 Angela

It might be worth re-examining your approach to
problem-solving.  Any problem can be either a burden or a
challenge.  a lot of the difference comes in how you
approach it.  If you just get angry at the compiler for
sending you error messages, then you miss out on the help it
is offering you.  For me, it is actually a great
convenience.  When I am on a roll with the logic, I take
only moderate care about the code.  I don't intentionally
neglect sysntax, but I focus on logic.  Then each time I
finish a new function body, I:
perl -c my_program_name.pl
before I try to run.  I just accept that I may have to run
this command and toggle back to the script to catch my
errors.  It's just part of the process, and I've learned to
enjoy it.

By using highly structured code, I can usually keep the
complications to a minimum for the process I am working on
at any given time.  My current project just went beyond 1500
lines.  I can't imagine trying to keep track of all that if
it was unstructured.  As it is, it's no problem.  There is
not a single function in that file that can't be viewed in
whole in a single screen.  This makes it very easy to
isolate problems.

I would recommend at a minimum that you test the DBI and CGI
modules each in isolation before trying to do an integrated
web-based data access system.  Each tool Perl offers has its
own purpose characteristics, and quirks.  It is easiest to
get familiar with them one at a time.  The deeper your
familiarity with each, the more readily you will be able to
make them integrate smoothly.

Joseph


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