Re: System call for openssl

2005-11-10 Thread Pete Emerson
If you don't specify -out the openssl command (I think, untested) will spit the results to STDOUT, in which case you could do this: $results = `openssl smime smime -sign -outform der -nodetach -signer $certificate -in $encoded`; and then you probably want to chomp $results, or parse them in

threading stability concerns

2005-11-09 Thread Pete Emerson
I'd love to take advantage of threading in my production environment. The local perl expert cautions that '"common" knowledge is that threads in perl are not production ready - i.e. are not very stable'. perldoc perlthrtut says that the older threading (5.005) was buggy, ithreads has been

Re: env vars using perl

2003-09-25 Thread Pete Emerson
Asif Iqbal wrote: I can use this to get all the env variables ... Now how can I use this trick to get all the web env variables ? I am using apache on unix (solaris 8) ? It's the same way. Here's code that works for me: #!/usr/bin/perl -w use strict; use CGI qw(:standard); print header; print st

PDF content extraction

2003-09-25 Thread Pete Emerson
I've browsed CPAN. I've Googled. I'm stumped. I've successfully used PDF::Parse to get at PDF metadata. But I can't get at the content. Is there a way in perl to extract the contents of a PDF file? Last resort will be to use pdftotext or a similar converter, but if I can go native, so much the

Re: Rename files script - a first effort

2003-07-10 Thread Pete Emerson
John W. Krahn wrote: Just a couple of comments if you don't mind. (I knew you wouldn't :-) Of course not, that's how I keep on learning! :) Due to way some file systems work I would store the file names in an array and use the array to rename the files instead of renaming them in the File::Fi

Re: Rename files script - a first effort

2003-07-10 Thread Pete Emerson
Barry, I just wrote my own version of your script. Not that it's better than yours, just different. I've learned a lot from this list by seeing how people do things differently than me! I hope you find my version helpful. A couple of notes about mine: 1) The directory is taken from the command

Re: make errors with RPM::Database on redhat 9.0

2003-06-02 Thread Pete Emerson
ecture being the one I was particularly missing). There have been other packages that have not installed for me under RH9. Mail::SpamAssassin and HTML::Parser being two. I installed perl from source, and that helped, although I still had to force install HTML::Parser. Pete -- http://emerson.

Re: HASH PRINTING

2003-04-03 Thread Pete Emerson
3pm from Eric Walker: EW> I don't know if I am reading the data dumper help code right but it seems you EW> have to provide a list of the hash keys to get the values. I need a way to EW> just print out all keys and values no matter how many levels of hierachy there EW> may be i

Re: $from_address

2003-03-28 Thread Pete Emerson
27;, RS> ); RS> RS> $mail{body} = < RS> First Name: $fname RS> Last Name: $lname RS> Email: $email RS> Organization: $org RS> Scientific Interest: $sci_int RS> Mailing List? $check RS> RS> sendmail(%mail) || print "Error: $Mail::Sendmail::error\n"; RS> RS> RS> -- http://emerson.wss.yale.edu/perl Pete Emerson WSS AM&T Yale University -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: Statement execution...

2003-03-27 Thread Pete Emerson
Here you go, and your guess as to what prints out is right on; subroutines don't run until they're called, and placement in this situation doesn't affect anything. #!/usr/bin/perl -w use strict; print "one\n"; sub aa { print "two\n"; } print "three\n"; print "four\n"; sub bb { prin

Re: Filling out forms on the web.

2003-03-20 Thread Pete Emerson
rite, drawn heavily from the Burke book, LW> for the edification (or amusement) of others. Again, any insight will be LW> greatly appreciated. -- http://emerson.wss.yale.edu/perl Pete Emerson WSS AM&T Yale University -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: Evaluating parts of a string

2003-03-18 Thread Pete Emerson
if $var='1>>$fileName'. I was NM> hoping there would be a simple way getting around this NM> without using any regexps. NM> NM> Navid M. NM> NM> --- Pete Emerson <[EMAIL PROTECTED]> wrote: > NM> Your first perl script sends '1>>$filename'

Re: Evaluating parts of a string

2003-03-18 Thread Pete Emerson
Your first perl script sends '1>>$filename' (single quotes, this is NOT a variable) ... and you want to replace '$filename' with the contents of the variable $filename? If I have that correct, a regex will help: my $string='1>>$filename'; # This is coming from your first perl script. my $filename

Re: Fun with Regexes

2003-03-17 Thread Pete Emerson
t;Can't open $file: $!" if (!open INFILE, $file); or is this a different kettle of fish? By the way, I really appreciate that this list caters to multiple levels of "beginners"! I've not only been helped a lot on here, but I hope I've helped a few myself. :) -- http://

Re: Fun with Regexes

2003-03-16 Thread Pete Emerson
Thanks for your code, I've gotta look up \Q to make sure I understand what's happening, but it looks great. I'm still parsing your comments to make sure I understand everything. I'm not quite sure what you meant about side effects from my conditional being frowned upon...how else do you use the ()

Fun with Regexes

2003-03-15 Thread Pete Emerson
(@strings) { my $success=1; foreach my $match (@matches) { ($string=~/$match/) ? (next) : ($success=0); last; } ($success) ? (print "$string matches.\n") : (print "$string does not match.\n"); } Pete -- http://emerson.wss.yale.edu/perl Pete Em

Re: apache error

2003-03-14 Thread Pete Emerson
er; print start_html; print "Hello world!\n"; print end_html; Mar 14, 2003 at 8:16am from Francesco del Vecchio: FdV> [Fri Mar 14 17:03:11 2003] [error] [client 127.0.0.1] Premature end of script headers: hello.pl -- http://emerson.wss.yale.edu/perl Pete Emerson WSS AM&T Yale U

Re: getting the number of characters

2003-03-12 Thread Pete Emerson
The length() function is what you need. print length($num), "\n"; Mar 12, 2003 at 10:08am from David Gilden: DG> I am looking for the $num to treated as a string and get the number of characters, -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

RE: return a regex substitution in one line

2003-03-11 Thread Pete Emerson
Dan, I can do it in one line. But I'm not convinced it's the "right" way to do it; i.e. it seems like it's cheating: sub rmgtlt { $_[0] =~ s/^\<|\>$|\n|\r|\s$//g ? return $_[0] : return $_[0]; } There's got to be a better way that doesn't use this if-then-else approach. I'd vote for keepi

Re: Search and Replace

2003-03-11 Thread Pete Emerson
names. What I'm attempting to do is JK> read the first file of domains and run a search based JK> on the contents of that file against the second file JK> of domains. Then open a completely new file writing JK> the contents of the second file with the exception of JK> t

Re: Main email body

2003-03-08 Thread Pete Emerson
r something similar like the module Mail::POP3Client > 'Body()' function, to get the email main body of the email ?? > > thx's > > -- http://emerson.wss.yale.edu/perl Pete Emerson WSS AM&T Yale University -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

RE: trying to match variable names

2003-03-06 Thread Pete Emerson
t;); > } > > unless (open(OUTFILE, ">nospace.txt")) { > > die ("Cannot open output file nospace.txt.\n"); > } > > $line = ; > > while ($line ne "") { > > if ($line =~ / +/) { > print OUTFILE ('"'); >

Re: pattern matching problems

2003-03-06 Thread Pete Emerson
On Thu, 2003-03-06 at 09:32, Francesco del Vecchio wrote: > If I have a string as the following: > a xx b a x b > and I try a m/a(.*)b/g > $1 = xx b a x > what have I to do to obtain two matches each of one give me > $1 = x #!/usr/bin/perl -w u

Re: trying to match variable names

2003-03-06 Thread Pete Emerson
Daniel, Inside [ ] means "any of the following", so you don't use the | as an OR in this situation. Take the | out and you should be fine. Here's my example: #!/usr/bin/perl -w use strict; my $variable1; my @variable2; my %variable3; $variable1=1; @variable2=(1,2,3); %variable3=(1,2,3,4); # |SOME

Re: Using multiple test statements

2003-02-27 Thread Pete Emerson
On Fri, 28 Feb 2003, Stefan Lidman wrote: > > Note that you'll match on dudette and joeshmoe ... if you want an exact > > match, you could do: > > > > print "$_\n" if (/^joe|dude$/); > > I guess you ment: > > print "$_\n" if (/^(?:joe|dude)$/); > > Otherwise it matches if it begins with 'joe'

Re: Using multiple test statements

2003-02-27 Thread Pete Emerson
#!/usr/bin/perl -w use strict; my @list = qw(fred joe bob john dude eddie rob dudette joeshmoe); foreach (@list) { print "$_\n" if (/joe|dude/); } Note that you'll match on dudette and joeshmoe ... if you want an exact match, you could do: print "$_\n" if (/^joe|dude$/); On Thu, 2003-02-27 a

Re: Shifting

2003-02-25 Thread Pete Emerson
There are probably oodles of ways of doing this. Here are two: # An array slice @[EMAIL PROTECTED]; or # start at position 0, remove 9 elements splice @data, 0, 9; Pete On Tue, 2003-02-25 at 14:39, dan wrote: > onwards. My way of doing this was: > shift(@data); x 9 -- To unsubscribe, e-mail

Re: shlock and retrying

2003-02-20 Thread Pete Emerson
I'm not sure what might be the best way to approach this. I'm not comfy > with an indefinite loop, where if there is some problem removing the lockfile, > my program would wait forever. I'd rather try for a few minutes, then exit > with some error. > > Any pearls of

Re: How to display dir contents on web page?

2003-02-19 Thread Pete Emerson
On Wed, 19 Feb 2003, Scott, Deborah wrote: > Does anyone know where I can get a script that looks into the contents of a > directory and outputs the contents of the directory into a list that is > displayed on an HTML page? (Also, the names should contain hyperlinks to > those contents.) Deborah,

Re: regarding log() function

2003-02-05 Thread Pete Emerson
You probably have the module you need already installed. I did it successfully like this: perl -e 'use Math::Complex; print log(-2.8e-05);' On Wed, 2003-02-05 at 11:41, [EMAIL PROTECTED] wrote: > hi all, > i am using perl 5.8.0 on ix86. i was using an inbuilt function log(). > i am not able to g

Re: sorting hash numerically

2003-02-04 Thread Pete Emerson
perldoc -q sort foreach $empNo (sort {$a<=>$b} keys %empName) { On Tue, 2003-02-04 at 08:17, Rob wrote: > Hi, I want to sort a hash based on the employee number; I used a foreach > loop but it sorts the hash based on the ascii value. How would I get it > to sort on integer values? -- To unsu

Re: Even more regex

2003-01-31 Thread Pete Emerson
Dan, Here's my solution. I'm not capturing the days, hours, minutes, seconds as I go, but I'm sure you can see how to if it's really necessary. #!/usr/bin/perl -w use strict; my @list=('3d4h45m12s', '3h', '5h2m'); foreach (@list) { my $seconds=0; my $string=$_; while ($string=~s/(\

Re: uploading files

2003-01-31 Thread Pete Emerson
Here's a sample. The trick is to turn on autoflushing ($|=1;) so that your text gets printed out right away. #!/usr/bin/perl -w use strict; use CGI qw(:standard); $|=1; print header; print start_html; for (my $i=0; $i<100; $i++) { print "."; sleep 1; } print "\n"; print end_html; On Fri

Re: not getting any result...

2003-01-31 Thread Pete Emerson
The error results of useradd appear to go to STDERR instead of STDOUT. You can redirect them to STDOUT, and therefore capture the results, like this: my $username='username'; my $rescmd=`/usr/sbin/useradd -s /bin/false $username 2>&1`; chomp $rescmd; print "Result is $rescmd\n"; On Fri, 2003-01-3

Re: Hash of Hashes of Arrays?

2003-01-24 Thread Pete Emerson
I'd be tempted to use a hash of hash of hashes, storing it like this: $hash{$city}{$station}{add1}=$address1 $hash{$city}{$station}{add2}=$address2 $hash{$city}{$station}{state}=$state $hash{$city}{$station}{zip}=$zip $hash{$city}{$station}{phone}=$phone So my loop would look like this: foreach my

Re: Only numbers

2003-01-23 Thread Pete Emerson
if ($numexs=~/^\d+$/) { # do this if $numexs contains 1 or more numbers, nothing else } else { } Your regex just checks to make sure there's one number in your entire string. Anchor it at the beginning and the end, and then use a + to say "one or more occurances of" ... if ($numexs=~/^[0-9]+$

Re: cgi and symbolic links

2003-01-23 Thread Pete Emerson
I put a working test.pl in /var/www/cgi-bin. Then I symlinked test2.pl to it. When I loaded up test2.pl, the web page said: Forbidden You don't have permission to access /cgi-bin/test2.pl on this server. Then I put this in my section of httpd.conf: Options FollowSymLinks Now test2 works, and th

Re: looking for a string in multiple files

2003-01-21 Thread Pete Emerson
> if ($result eq $file1) This is checking to see if each line matches the filename itself, not the contents of file1. You were going for the contents of $file1, correct? Here's my stab. Read in the target files first, then match. When it walks through the source file, it will print out the name

Mail::IMAPClient with SSL

2003-01-18 Thread Pete Emerson
I'm trying to get Mail::IMAPClient working with SSL. I can get it working fine without SSL. Here's my attempt: # assume $server, $port, $username, $password are defined correctly my $ssl = IO::Socket::SSL->new(Proto=>'tcp', SSL_verify_mod=>0x00,

Re: Help with merging

2002-12-04 Thread Pete Emerson
if ACTION1 is a subset of (killed chopped smooshed knifed) etc.etc and ACTION2 is a subset of (with by for from) etc. etc. (or even better, is ACTION2 always the word "by" ??) then here is my sample program: #!/usr/bin/perl -w use strict; my $text='^7Kore^7Adam killed BEST I TEST by MOD_MACHINEG

Re: Help with merging

2002-12-04 Thread Pete Emerson
How do you determine which pair(s) of words to group together? Are you always grouping items 3 and 4, or might you sometimes want "monkey killed" or "killed elephant" or "with stone" ? There needs to be some way of determining when to pull out a pair and when not to. [EMAIL PROTECTED] wrote: b

Editing text on the CLI

2002-12-04 Thread Pete Emerson
Suppose I have the following program: 0 #!/usr/bin/perl -w 1 use strict; 2 my $var='Edit this'; 3 print "Edit \$var here --> "; 4 print $var; 5 $var=; chomp $var; 6 print "\$var has a new value: $var\n"; Can I insert a line in between line 3 and 4 which will make line for editable? i.e. right now

Re: Detecting module existence

2002-09-05 Thread Pete Emerson
If I put a lot of subroutines in the BEGIN { } section, so that they load at compile-time, what is the disadvantage? BEGIN { eval { require Tk; }; if ($@) { # Do the NoGUI stuff here exit; } sub LotsOfSharedSubsHere { } } use Tk; print "GUI section.\n"; Lo

Re: Detecting module existence

2002-09-05 Thread Pete Emerson
I think I'm going in circles. Sorry about the multiple postings. The program barfs on 'use Tk' even though by the time I get to the 'use Tk' the Tk module should be installed. I tried doing require Tk; import Tk; but then I get this message: Bareword "MainLoop" not allowed while "strict subs" in

Re: Detecting module existence

2002-09-05 Thread Pete Emerson
I think I may have answered my own question. Is there a "better way" (TM) or a more efficient way? eval { require Tk }; if ($@) { # module is NOT installed # code here to make sure user is root and wants to proceed system('perl -MCPAN -e \'CPAN::Shell->install("Tk")\''); } use Tk; etc. etc.

Detecting module existence

2002-09-05 Thread Pete Emerson
How do I detect whether a module is installed or not? For example, if a script is running as root, this would be useful: if (Tk is not installed ) { # This is what I need. print "Do you want to install the Tk perl module? (y/n) [n] >> "; my $answer=; exit if ($answer!~/^[Yy]/); print "You

use confusion

2002-05-31 Thread Pete Emerson
The following example does what is expected, i.e. prints out the word password on its own line. used.pm --- $password='password'; use.pl -- #!/usr/bin/perl require "./used.pm"; print "$password\n"; However, as soon as I turn on warnings and strict, and declare $password: #!/usr/bin/per

SSL and IMAP

2002-03-28 Thread Pete Emerson
I'm using Mail::IMAPClient to write a mail filter via IMAP. I'd like to connect to the server using SSL. The instructions in the man page don't help me: $imap=Mail::IMAPClient->new(User => $user, Password => $pass, Server => $host); # blah blah blah (doc's blah blah blah, not mine!) $imap->Socket

Re: Help reqd. for collecting data

2002-01-23 Thread Pete Emerson
Here's my stab at it: #!/usr/bin/perl -w use strict; my %info; open INFILE, "$ARGV[0]" or die "Can't open file: $!\n"; # Open file specified on command line while () { chomp; my ($date, @data)=split; # Capture the date, then the rest $date=~s/_\d{4}$//; # Re

Re: Using SMPT on Windows NT

2002-01-10 Thread Pete Emerson
ndle. which can be downloaded and installed from www.cpan.org. Good luck! Pete Emerson -- Mynd you, møøse bites Kan be pretty nasti... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

IMAP via SSL

2002-01-09 Thread Pete Emerson
I'm using Mail::IMAPClient to get at my mailbox: my $imap = Mail::IMAPClient->new(Server=>'my.mail.server', User=>'username', Password => 'password'); my $messages=$imap->unseen_count('INBOX'); print "$messages\n"; Does anybody have tips as to how to get this to work via SSL? I'm guessing I nee

Re: fun with regex/split

2001-12-12 Thread Pete Emerson
Jeff 'japhy' Pinyan wrote: > For the task of parsing quoted strings, my book suggests the inchworm > method: > > push @terms, $1 while > /\G\s*"([^"]*)"/g or > /\G\s*(\S+)/g; Hmmm...mine seems to go into an infinite loop: #!/usr/bin/perl -w use strict; my @terms; $_='"one two three"

Re: fun with regex/split

2001-12-12 Thread Pete Emerson
Thank you all for your quick responses. Splitting on the " was the key. I'm intrigued by Jon Molin's response, though: > my @ar = ($a =~ /((?:\"[^\"]*\"|[^\s]*))\s?/g); #should be possible to remove " > s/\"//g foreach (@ar); > print "$_\n" foreach (@ar); This works, too, but I don't understand w

fun with regex/split

2001-12-12 Thread Pete Emerson
I'd appreciate it if someone could help me wrap my brain around this one. I've got a string like this: $string='"one two" three "four five six"'; I'd like to wind up with an array like this: one two three four five six Essentially, I would like to split up the string on spaces, but ignore spaces

Digest::MD5

2001-12-11 Thread Pete Emerson
Is there a faster way to calculate the hex md5 of a file? sub md5 { my $file=shift; open (FILE, $file) or die "Can't open '$file': $!"; binmode(FILE); my $hash=Digest::MD5->new->addfile(*FILE)->hexdigest; close FILE; return $hash; } -- To unsubscribe, e-mail: [EMAIL PRO

detecting a hash of hashes

2001-12-06 Thread Pete Emerson
Here is an example of what I'm doing to detect whether I've got a scalar value in my hash or a hash of hashes: #!/usr/bin/perl -w use strict; my %hash; $hash{name}='Pete'; $hash{color}{favorite}='Blue'; $hash{color}{car}='Silver'; $hash{color}{house}='White'; foreach my $data (keys %hash) { i

Parsing HTML for SPSS

2001-11-27 Thread Pete Emerson
I am parsing an HTML page which has forms on it. I think maybe this belongs here instead of cgi-beginners? (Note, I'm parsing the form source, not the form results!) I am trying to extract the variable names as well as their labels so that I can write out an SPSS file which maps variable names t

Re: What is "bubble sort"?

2001-11-16 Thread Pete Emerson
Okay, so I'm trying to implement your radix sort, and something's going wrong. When I turn on warnings (I'm using Perl v5.6.0) I get: Multidimensional syntax $table[substr $_, $i, 1] not supported at ./sort3.pl line 31. and when I turn on strict: Can't use an undefined value as an ARRAY reference

Re: What is "bubble sort"?

2001-11-16 Thread Pete Emerson
Dave Storrs wrote: > Hmmm...this is interesting. A friend of mine who is in the > process of getting her graduate degree in CS/information theory stuff > recently told me that it has been mathematically proven that no sort can > run faster than O(n log n) unless you know something about

Re: What is "bubble sort"?

2001-11-16 Thread Pete Emerson
Jeff 'japhy' Pinyan wrote: > Ooh, radix sort. This is a cool technique, but it has a drawback: it > always runs in the same time. Sorting sorted data takes as long as > sorting UNsorted data. (Or sordid data!) I love the implementation, gotta examine it closely and your example by hand with

Re: What is "bubble sort"?

2001-11-16 Thread Pete Emerson
Since we're on the topic of sorts, what are the arguments for the implemented quicksort vs. a radix sort? Pete -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

extracting email addresses

2001-11-08 Thread Pete Emerson
When I send mail to a certain address, the mail gets piped to my perl script. I'm then using Mail::Internet to extract info, including the From header. For me, the header looks like this Pete Emerson <[EMAIL PROTECTED]> 1. I assume that they're all going to look different. Is tha

Re: imbed c programs in a perl script and vice versa

2001-11-02 Thread Pete Emerson
Well, suppose my C program does this: $ ./cprogram First Name: Pete Last Name: Emerson I could use a Perl program like this to analyse the output: The key is that the backticks execute any executable file and store the output. #!/usr/bin/perl -w use strict; my $cstuff=`./cprogram`; my $first

Re: imbed c programs in a perl script and vice versa

2001-11-02 Thread Pete Emerson
Yes, you can do it. Here's four files. First, Perl calling a C program: chelloworld.c gcc -o chelloworld chelloworld.c #include int main() { printf("Hello, World, in C!\n"); return; } perlprinter.pl ## #!/usr/bin/perl system("./chelloworld"); Now C calling a Perl pro

Re: Problem performing a split using triangular brackets

2001-11-01 Thread Pete Emerson
Stewart, I'm guessing it can be done with split, but I used a regex to do it, and that way I don't have to worry about taking out the extra ", <, and >. my $full_address='"My Name" <[EMAIL PROTECTED]>'; my ($user, $email); print "$full_address\n"; $full_address=~/^"(.+)" <(.+)>$/; $user=$1; $em

Re: returning more than 1 scalar from a subroutine

2001-10-31 Thread Pete Emerson
If I understand your question correctly, this will work: #!/usr/bin/perl -w use strict; my ($a, $b, $c, $one, $two, $three); $a=1; $b=2; $c=3; ($one, $two, $three)=Change($a, $b, $c); print "$one $two $three\n"; sub Change { my ($x, $y, $z)=@_; $x++; $y=0; $z=10; return ($x, $y, $z

File::Find and File::stat

2001-10-31 Thread Pete Emerson
I'm using Perl 5.6.0 on Linux. I've written a program to take a given directory passed in via command line, traverse the directory, and for each user who owns a file in that directory, print out their total usage. My first attempt captured the directory using `ls -alR` and storing the results in

Re: [Fwd: Stripping slashes in strings]

2001-10-29 Thread Pete Emerson
Does this do the trick? #!/usr/bin/perl -w use strict; my $string=q#Strip the \'slashes\' from the \"string\" if\and\only\if they're followed by a ' or ".#; print "Before: $string\n"; $string=~s#\\(['"])#$1#g; # match a \ followed by either a ' or ", and replace with just the ' or " print "After:

Re: How to split it?

2001-10-22 Thread Pete Emerson
I wonder why the use of sprintf? I would have done it this way: foreach (@list) { $_=":$_"; } Is there something that the sprintf does that I'm missing, or is this just another way to skin the same cat? Perhaps in other circumstances sprintf is superior? Just curious, Pete Etienne M

Re: RFC on my short recursive code

2001-06-18 Thread Pete Emerson
Jeff 'japhy' Pinyan wrote: > You could go over the entries from readdir() one at a time: > > opendir DIR, $dir or die "can't read $dir: $!"; > > while (defined(my $file = readdir DIR)) { > next if $file eq '.' or $file eq '..'; > my $full = "$dir/$file"; > # ... > } > > closed

Re: RFC on my short recursive code

2001-06-18 Thread Pete Emerson
Jeff 'japhy' Pinyan wrote: > ### ick -- use opendir() and readdir(), or glob() Okay, sounds good. I'm not quite sure how to use glob. opendir works: opendir(DIR, "$dir"); my @ls=readdir(DIR); closedir(DIR); except I get the directories . and .. , which doesn't cut it for recursion. Is the

RFC on my short recursive code

2001-06-18 Thread Pete Emerson
I've written a short program to recursively delete files/directories that haven't been modified in a certain length of time. It appears to work, but in the interest of improving my code/coding skills, I'd like to get any/all comments and criticisms, particularly about the way I handled getting the

Re: SWAPING COLUMNS

2001-06-08 Thread Pete Emerson
Sorry to reply to my own post, but I just looked carefully at Ondrej's solution, and the nice thing about it is that it doesn't matter what order the columns are in, it will always sort on the header. So his program is a lot more generic than mine. Nice! Pete Pete Emerson wrote: &

Re: SWAPING COLUMNS

2001-06-08 Thread Pete Emerson
Here's my version. It's pretty straightforward, but maybe Ondrej's solution is far better for some reason? #!/usr/bin/perl -w use strict; my $inputfile; my $outputfile; $inputfile='myinfile.txt'; $outputfile='myoutfile.txt'; open (INFILE, "$inputfile") || die "Can't open input file\n"; open (OU

Re: double quotes around a variable

2001-06-07 Thread Pete Emerson
Respectfully, I disagree with this: Peter Scott wrote: > They're bad mainly because they suggest that the author doesn't understand > Perl well. So if I see code like that, my spidey sense starts tingling and > I wonder how good the code is. Why would someone type unnecessary quotes > unless t

Re: regex question

2001-06-07 Thread Pete Emerson
I don't know about anybody else, but I would LOVE a blow by blow interpretation of this (by anyone). I assume q{} and qr{} are pattern matching, although my reference here (Nutshell) comments only briefly on q, not qr, is that a typo? It looks like you're setting up a regular expression ahead of t

Re: directory listing to array

2001-06-07 Thread Pete Emerson
...and just to include both .jpg and .jpeg like John's program: opendir DIR, "./" or die "can't open $directory: $!\n"; @files = grep /jpe?g$/i, readdir DIR; Nice code, Shawn. I must admit that my original way of doing this was even worse than John's (by not using opendir and closedir). Zoiks. G

Re: regexp question

2001-06-07 Thread Pete Emerson
Martin, Let me take a crack at it, and explain it so that it might help some beginners, too. I wrote this code: $text='supernova'; if ($text=~/.n+..?.?v*./) { print "match.\n"; } which just takes your regular expression and applies it. The if statement is true, I ran it just to make sure.

Re: the ENV command? parameter?

2001-06-07 Thread Pete Emerson
Brian, If you're looking for info about CGI, here's a very simple short CGI Perl script that will help answer your question. I'll put my comments at the end. #!/usr/bin/perl use CGI qw(:standard); if (!param()) { print header; print start_html; print "\n"; print "Red\n"; print "Blue\

Re: Getting results from MySQL

2001-06-07 Thread Pete Emerson
Thanks, Ondrej and Ian for the very useful information. A quick followup contribution, now that I understand what's going on and what to look for: When querying and only returning one row (see the second part of my original message), the following appear to be equivalent: $prep_query="SELECT date

Getting results from MySQL

2001-06-07 Thread Pete Emerson
I have some questions about the following code snippet (using DBI to connect to MySQL): 1. $prep_query="SELECT school_name,path from student_data where student_id=$student_id"; 2. $query=$dbh->prepare($prep_query); 3. $query->execute; 4. $temp=$query->fetchall_arrayref(); 5. foreach my $row (@$te

Re: How to truncate a string?

2001-06-06 Thread Pete Emerson
Use substr. This will leave you with 5 characters: $text='abcdefghijklmnopqrstuvwxyz'; $text=substr $text, 0, 5; print "$text\n"; Output: abcde Bruno Veldeman wrote: > Hi, > > I have been looking for a function to truncate a string at a given lenght, but am >lost. > > None of the functions see

Re: Link check problem.

2001-06-06 Thread Pete Emerson
Bruno, I used CGI and LWP::Simple to get ESPN's AL East baseball standings table and then rewrite that table into a format that I wanted. You can see it at http://jasper.cs.yale.edu if you're curious (insert shameless plug for the Red Sox here). But that sort of thing might help you to grab th