Punishing Your Server With Perl
Hello, All: A couple of years ago there was a great article by the title of "Punishing Your Server With Perl". (I believe that either Randal Schwartz or Ruben Lerner wrote the article.) Anyhow, I can't find it. I've checked Google but found nothing. Where oh where did it go? -- Eric P. Sunnyvale, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Punishing Your Server With Perl
On Thu, 13 Mar 2003 [EMAIL PROTECTED] wrote: > A couple of years ago there was a great article by the title of "Punishing > Your Server With Perl". (I believe that either Randal Schwartz or Ruben > Lerner wrote the article.) Anyhow, I can't find it. I've checked Google > but found nothing. > > Where oh where did it go? Foiled again by having only half the facts: 1. The article's title is "Torture-testing Web Servers" 2. The article's author is Linconln Stein. The article can be found at: http://stein.cshl.org/~lstein/torture/torture.html There's also an article by Randal Schwartz that speaks to a related topic: http://www.stonehenge.com/merlyn/WebTechniques/col63.html -- Eric P. Sunnyvale, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Checking for .jpg/.gif/.png files
Hello, All: I need to check files to make sure that they are .gif, .jpg, or .png graphic files before processing them. How can I verify that? e.g., In unix, the 'type' command returns the file's type. -- Eric P. Sunnyvale, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: shell command
On Tue, 3 Sep 2002, David T-G wrote: > % all im trying to do is run the shell command: > % > % convert -quality 40 image.jpg resampled_image.jpg > > Better yet, you should grab the PerlMagick module and just run the > commands from within your perl script and forget the system call (or > backticks or, IIRC, qx quoting). Word to the wise: PerlMagick is _not_ the easiest thing in the world to use (especially if you have to install PerlMagick yourself instead of from .rpm). You can spend _a_lot_ of time installing/learning PerlMagick! If `convert` works for you, you might want to stay with that. -- Eric P. Sunnyvale, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Regex: Matching URL's
Hello, All: I'm curious about the behavior of backreferences in a regular expression that I've created: $url = m|^(http://)?((\.?[a-z0-9][a-z0-9\-]+)+(\.[a-z0-9]){2,3})/| What's unusual about this regex is that the backreferences for any sub-domains (i.e., www, ftp, &c.) are not caputured. e.g., Setting $url equal to http://www.pretorious.net returns... $1 = http:// $2 = www.pretorious.net $3 = .pretorious $4 = .net While $2 holds the value that I am searching for, I'm still curious: How can I flexibly capture any sub-domain portions of the hostnames. (Even the tricky ones like www.developers.earthweb.com...) -- Eric P. Sunnyvale, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Regular Expressions: Grouping and backreferences...
Hello, All: How can I capture all the words that contain 'at' in the string 'A fat cat sat on my hat.'? Any pointers? $sentence = 'A fat cat sat on my hat.' $sentence =~ m/(\wat)/; returns: $1 = 'fat' -- Eric P. Sunnyvale, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: converting a list into array
On Wed, 4 Sep 2002, Bob Showalter wrote: >chomp(@list = ); >print join(',', map "'$_'", @list), "\n"; >__DATA__ >AAPL >AMCO >IBM >ORCL What is the __DATA__? Please explain. -- Eric P. Sunnyvale, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Removing a directory
Hello, All: What's the simplest method to remove a directory *and* it's contents? (rmdir only works on empty directories.) -- Eric P. Sunnyvale, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Removing a directory
On Tue, 24 Sep 2002, Michael Fowler wrote: > On Tue, Sep 24, 2002 at 10:38:59AM +0800, [EMAIL PROTECTED] wrote: > > What's the simplest method to remove a directory *and* it's contents? > > (rmdir only works on empty directories.) > > I'm somewhat surprised by the advice given so far (rm -rf and File::Remove; > the first isn't portable, the second requires going to CPAN). The simplest > solution is to use rmtree from File::Path, which comes with Perl. See > perldoc File::Path. Oh that's good - Thanks! -- Eric P. Sunnyvale, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Looping through readdir()
Hello, All: When using... while ($x = readdir(DH)) { # What came before $x? # What will come after $x? } How can I look at the next item in the directory? -- Eric P. Sunnyvale, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Comparison: finding if a value is gt some value AND lt another
Hello, All: Is there a simple way to find if a variable's value is within a range? e.g., if (1 < $x < 5) { print 'foo'; } or do I have to join two separate comparisons using the logical AND operator? e.g., if (1 < $x and $x < 5) { print 'foo'; } -- Eric P. Sunnyvale, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
foreach() and while()
Hello, All: When using foreach or while() on an array, how can I access the index of the list that foreach()/while() is working upon? Is there an internal variable that stores this info like PHP's current()? -- Eric P. Sunnyvale, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Condition Evaluation
Hello, All: I'm testing to determine that a list of variables has been set and am baffled by how this conditional is evaluating: CODE SNIPPET: GetOptions( 'comment=s' => \$comment, # Req'd arg 'directory=s' => \$directory, # Req'd arg 'rows=i'=> \$max_rows, # Req'd arg 'cols=i'=> \$max_cols, # Req'd arg 'saturation:i' => \$saturation # Optional arg ); unless (defined $directory && defined $comment && defined $max_rows && defined $max_cols && (!defined $saturation || abs($saturation) < 100)) { # Print error messages } WHAT'S HAPPENING: Without setting $saturation... A. Everything works just fine if all of the *required* variables are set. B. Perl complains 'Use of uninitialized value in abs' if any of the *required* variables are not set. WHAT I EXPECT TO HAPPEN: Without setting $saturation... I thought that evaluation of the conditional would stop at the first occurence of an undefined variable and that (!$defined $saturation || abs($saturation) < 100) would _not_ be evaluated i.e., The abs() portion of the test would not be performed. HOW CAN I: 1. Check that each of the required variables has been set *and*then* 2. Check the value of $saturation _only_if_it_has_been_set_? -- Eric Pretorious Sunnyvale, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Condition Evaluation
On Mon, 30 Sep 2002, Michael Fowler wrote: > I cannot duplicate your problem. Given the code: > > perl -wle 'print "hi" if defined $bar && (!defined $foo || abs($foo) >< 100)' > > I see no 'Use of uninitialized value' warnings, and no print. Are you > certain the code you posted is what you're actually using? Is there > relevant code prior to what you posted, such as initializations of your > variables? The snippet that I included in the message was a reduced version of the script. I've attached the script to this message. (I hope that this isn't a breach of etiquete.) Here's the first 20 lines or so... #!/usr/bin/perl -w use Text::Template; use Image::Magick; use Getopt::Long; use File::Path; use FindBin qw($Bin); use POSIX; use strict; use vars qw($comment $directory $max_rows $max_cols $lg_dim $saturation $normal $last_index $indiv_template $index_template @files @html_files @old_indexes); GetOptions( 'comment=s' => \$comment, 'directory=s' => \$directory, 'rows=i'=> \$max_rows, 'cols=i'=> \$max_cols, 'largedim=i'=> \$lg_dim, 'normalize' => \$normal, 'saturation:i' => \$saturation ); unless (defined $directory && defined $comment && defined $max_rows && defined $max_cols && defined $lg_dim && $lg_dim =~ m/[1-9][0-9]?/ && (!defined $saturation || abs($saturation) < 100)) { # print individual error messages exit; } # continue if all req'd variables were defined and the optional variables # were within tolerances -- Eric P. Sunnyvale, CA #!/usr/bin/perl -w use Text::Template; use Image::Magick; use Getopt::Long; use File::Path; use FindBin qw($Bin); use POSIX; use strict; use vars qw($comment $directory $max_rows $max_cols $lg_dim $saturation $normal $last_index $indiv_template $index_template @files @html_files @old_indexes); my $copyright = 'Copyright 2002, Fun 4-Wheel Drive Association\nPretorious Networks - www.Pretorious.net'; GetOptions( 'comment=s' => \$comment, 'directory=s' => \$directory, 'rows=i'=> \$max_rows, 'cols=i'=> \$max_cols, 'largedim=i'=> \$lg_dim, 'normalize' => \$normal, 'saturation:i' => \$saturation ); unless (defined $directory && defined $comment && defined $max_rows && defined $max_cols && defined $lg_dim && $lg_dim =~ m/[1-9][0-9]?/ && (!defined $saturation || abs($saturation) < 100)) { print "Specify a directory to scan (e.g., --directory /etc)\n" unless $directory; print "Provide a comment for the photos (e.g., --comment foobar)\n" unless $comment; print "Specify the number of rows and columns in the indexes (e.g., --cols 5 --rows 5)\n" unless ($max_rows && $max_cols); print "Specify a number between -99 and 99 for the image saturation value (e.g., --saturation -50)\n" unless (abs($saturation) < 100); print "Specify a number between 1 and 99 for the images\' final size as a percentage of the beginning size (e.g., --largedim 75)\n" unless ($lg_dim > 0 && $lg_dim < 100); exit; } unless (-d "$Bin/$directory" or ($directory =~ m|^/| and -d $directory)) { print "Invalid directory: $directory\nDirectory $directory must exist within $Bin\n"; exit; } else { # Strip any trailing-slashes from $directory $directory =~ s|/$||; opendir(DIR, $directory) or die "Could not open $directory: $!\n"; # Create an array of the image files' names # Create a parallel array of HTML file names # Create an array of old index-#.html files to remove for (readdir(DIR)) { next unless ( -f "$directory/$_"); if ((my $file_base = $_) =~ s/\.(jpg|gif)$/\.html/i) { push (@files, $_); push (@html_files, "$file_base.html"); next; } push (@old_indexes, "$directory/$_") if (m/html$/); } closedir(DIR) or die "Could not close $directory: $!\n"; # Calculate the number of index files to create $last_index = ceil((scalar @files) / ($max_rows * $max_cols)); rmtree([@old_indexes, "$directory/html", "$directory/sm_images", "$directory/lg_images"]); mkpath(["$directory/html", "$directory/sm_images", "$directory/lg_images"]) or die "Could not create subdirectories within $directory: $!"; $index_template = Text::Template->new( TYPE=> 'FILE', SOURCE => "$Bin/index_template.tmpl" ); $indiv_template = Text::Template->new( TYPE=> 'FILE', SOURCE => "$Bin/indiv_template.tmpl" ); } my ($prev_href, $next_href, $prev_html, $next_html, $file_list, $index_hyperlist); my $curr_index = 1; for (my $x = 0 ; $files[$x] ; $
Re: Condition Evaluation
I found my mistake: I misread the line number in the error message. DOH!!! The complaints were related to the block that prints individualized error messages: unless (defined $directory && defined $comment && defined $max_rows && defined $max_cols && defined $lg_dim && $lg_dim =~ m/[1-9][0-9]?/ && (!defined $saturation || abs($saturation) < 100)) { print "Specify a directory to scan (e.g., --directory /etc)\n" unless $directory; print "Provide a comment for the photos (e.g., --comment foobar)\n" unless $comment; print "Specify the number of rows and columns in the indexes (e.g., --cols 5 --rows 5)\n" unless ($max_rows && $max_cols); print "Specify a number between -99 and 99 for the image saturation value (e.g., --saturation -50)\n" unless (abs($saturation) < 100); print "Specify a number between 1 and 99 for the images\' final size as a percentage of the beginning size (e.g., --largedim 75)\n" unless ($lg_dim > 0 && $lg_dim < 100); exit; } I've added a test for "defined-ness" to the conditional statement print "foobar" unless (defined $foo && abs($foo) > 100)' and everything works fine now. Thanks for all the help! -- Eric P. Sunnyvale, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Comparison: finding if a value is gt some value AND lt another
On Fri, 27 Sep 2002, Jeff 'japhy' Pinyan wrote: > On Sep 27, [EMAIL PROTECTED] said: > >Is there a simple way to find if a variable's value is within a range? > > if (1 < $x < 5) { print 'foo'; } > >...or do I have to join two separate comparisons using the logical AND > >operator? e.g., > > if (1 < $x and $x < 5) { print 'foo'; } > > You have to do that for now. Many thanks! -- Eric P. Sunnyvale, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Using map
Hello, All: I'm having a difficult time understanding the map function. I've got an array of file names that all end in 'jpg' or 'gif'. I'd like to create a parallel array of file names that end in 'html'. I'm creating the array this way... @new_names = map { ($x = $_) =~ s/(jpg|gif)$/html/i; $x } @old_names; Is there a more elegant way to accomplish this? It just doesn't seem elegant assigning $_ to $x, performing the substitution on $x, and then returning $x. -- Eric P. Sunnyvale, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
WHO IS NAVER-MAILER@naver.com ???
Hello, All: Every time I send a message to this list, I receive a message from [EMAIL PROTECTED] immediately afterwards. It appears to be garbage (lots of screwy characters...). Where is this coming from? Am I the only one receiving these? -- Eric P. Sunnyvale, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
PerlMagick: Errors and Set(compression, comment) (fwd)
Hello, All: I've been playin' around with IM for a few weeks now and am a bit confused. I've installed ImageMagick and PerlMagick from RPM (ImageMagick-5.2.7-2) on my RedHat Linux 7.1 machine and I'm attempting to read, modify, and save JPEG files but am having trouble with this series of commands: 1. If I use the Set method to set the comment - i.e., $image->Set(comment => 'foo') ...no comment is set. Only $image->Comment('foo') works. 2. There doesn't seem to be any difference in file-size when calling... $image->Set(compression => '30') 3. Is this a "good enough" approach to capturing any errors? <> $im = $image->Read(filename => "$directory/$files[$x]->{'image'}"); ($height, $width) = $image->Get('height', 'width'); $im .= $image->Resize(geometry => $height * $scale . 'x' . $width * $scale); $im .= $image->Normalize() if $normal; $im .= $image->Modulate(saturation => $saturation + 100) if $saturation; $im .= $image->Set(compression => 'JPEG', quality => $quality) if $quality; $im .= $image->Comment($copyright); $im .= $image->Write(filename => "$directory/lg_images/$files[$x]->{'image'}"); warn "$im" if $im; <> -- Eric P. Sunnyvale, CA <> 1. Read in a jpg image, 2. Set the comment, 3. Resize the image, and 4. Optionally... a. set the compression b. increase the saturation c. normalize the saturation 5. Write the image to a new file. <> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Condition Evaluation
On Tue, 1 Oct 2002, Michael Fowler wrote: > While this works, typically the way I do it is something along the lines of: > > usage("Specify a directory to scan ...\n") unless defined $directory; > usage("Provide a comment for the ...\n") unless defined $comment; > > and so on, where usage() is a subroutine that will print out the message > specified, as well as some basic usage information. > > The point being, you don't have to test the variables multiple times. There > is a disadvantage in that the errors will not all be printed out if there > are multiple problems. Thanks! I set-out to streamline the lenthy error checking/reporting and settled on this: my $err; $err .= "Error message #1\n" unless (defined $one); $err .= "Error message #2\n" unless (defined $two and $two eq 'foo'); $err .= "Error message #3\n" unless (defined $three and $three > 50); die "$err" if $err; -- Eric P. Sunnyvale, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Using CPAN.pm to Install Modules
Hello, All: I'm confounded by CPAN.pm's documentation. I've already configured the module but can't figure out how to 'install' a module. e.g., MIME::Lite. Starting with... %> perl -MCPAN -e shell cpan> i MIME/Lite tells me that there's a distribution called MIME/Lite BUT... cpan> install MIME/Lite tells me that the author MIME/Lite could not be found. How can I install this module/distribution? -- Eric P. Sunnyvale, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Using CPAN.pm to Install Modules
On Wed, 23 Oct 2002, Jenda Krynicky wrote: > > I'm confounded by CPAN.pm's documentation. I've already configured the > > module but can't figure out how to 'install' a module. e.g., > > MIME::Lite. > > Try > cpan> install MIME::Lite That was the first thing that I tried. CPAN complained that there were "no objects found of any type for argument MIME::Lite" cpan> i MIME/Lite reports... distribution id = MIME/Lite CALLED_FORMIME/Lite Maybe I'm using a bad mirror? CPAN is complaining that it can't find the file. (I'm using cloud9.net.) How can I update the list? -- Eric P. Sunnyvale, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Using CPAN.pm to Install Modules
On Thu, 24 Oct 2002, Jenda Krynicky wrote: > Maybe you should try a different mirror. Is there a command to update my urllist *interactively* (just like during the initial configuration)? If not: Where can I find a list of mirrors? -- Eric P. Sunnyvale, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Testing for filehandles
Hello, All: I've looked around for an answer to this (The Camel Book, The Ram Book, perldoc, google.com, etc.) but can't find a thing: Is it possible to test for the existence of a filehandle? I've got a small script that opens a filehandle. If that filehandle exists, I'd like to print to it. Otherwise, don't. e.g., use Getopts::Std; getopts("n"); open(OPT_LOG,">/tmp/foo.txt") if ($opt_n); while (<>) { print OPT_LOG $_ if OPT_LOG; } close(OPT_LOG) if OPT_LOG; -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Testing for filehandles
Tim: I know, I know: I excluded the "or die" portion for readability/simplicity. On Wed, 27 Mar 2002, Timothy Johnson wrote: > You'd probably have better luck testing for the open() command's success I wrote: >> use Getopts::Std; >> getopts("n"); >> open(OPT_LOG,">/tmp/foo.txt") if ($opt_n); >> while (<>) { >> print OPT_LOG $_ if OPT_LOG; >> } >> close(OPT_LOG) if OPT_LOG; -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Testing for filehandles
On Wed, 27 Mar 2002, Agustin Rivera wrote: > How would that work with use strict;? I tried it once and when I declared my > $opt_n before using getopts, it wouldn't work. Agustin: >From the Getopt::Std man page: Note that, if your code is running under the recommended `use strict 'vars'' pragma, you will need to declare these package variables with "our": our($opt_foo, $opt_bar); -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Testing for filehandles
On 27 Mar 2002, Chas Owens wrote: > Getopt::Std creates the $opt_n variables. To use it with use strict; in > place you must use the use vars ($opt_n); pragma as well. or just use > the getopts('n', \%opts); call. Then you can say $opts{n}. Agustin: Also from the Getopt::Std man page: For those of you who don't like additional global vari- ables being created, getopt() and getopts() will also accept a hash reference as an optional second argument. Hash keys will be x (where x is the switch name) with key values the value of the argument or 1 if no argument is specified. -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Testing for filehandles
On Wed, 27 Mar 2002, Agustin Rivera wrote: > Ok, I've tried it both ways and it returns 1 (true) as the value. What am I > doing wrong? Agustin: 1. What *exactly* do you mean "both" ways? 2. References... >From the Getopt::Std man page: getopt('oDI'); # -o, -D & -I take arg. Sets opt_*... getopts('oif:');# -o & -i are boolean flags, -f takes an argument # Sets opt_*... Pass one argument which is a string containing all switches that take an argument. For each switch found, sets $opt_x (where x is the switch name) to the value of the argument, or 1 if no argument. >From "The Ram Book": Getop::Std also provides the getopts function which lets you specify whether each option is Boolean or takes a value. Arguments that take a value... are indicated by a ':' In summary: getopts() will set BOOLEAN values OR the value supplied *if* the option is followed by a ':' in the function call getopts("x:"). getopt() will set the command-line value. -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Testing for filehandles
On Wed, 27 Mar 2002, Bob Showalter wrote: > You can pass a filehandle glob to IO::Handle::opened(): Thanks, Bob! After reading the IO::Handle man page, I decided to distill this approach a bit further: print F if fileno(F); -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Quieting 'Name "main::foo" only used once..."
Hello, All: Is there a simple way to stop perl from complaining that a variable is only used once (possible typo at...)? e.g., #! /usr/bin/perl -w use Getopts::Std; getopts('d'); print "foo" if ($opt_d); If I use 'my()' perl complains that the variable is used in a void context. Since I'm testing for truth, I suppose that I could set $opt_d to zero before calling getopts('d')... -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Testing for filehandles
On Thu, 28 Mar 2002, Bob Showalter wrote: > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] > > Thanks, Bob! After reading the IO::Handle man page, I decided > > to distill this approach a bit further: > > > > print F if fileno(F); > > Of course, that's even simpler! Just to be nitpicky, the test maybe > should be > >defined(fileno(F)) > > Since 0 is a valid file number (STDIN). So, technically, I should be testing for "definedness" instead of "truth". i.e., From `perldoc -f fileno`: Returns the file descriptor for a filehandle, or undefined if the filehandle is not open. > If you're just going to do the test on the print statement, it's > not accomplishing all that much, since the print() will silently > fail if the file isn't open. But a test like this would be useful > if you want to avoid doing a lengthy operation to generate the > data to be printed. Printing to a non-existant filehandle (while using the -w switch) generates a warning message: Filehandle main::FOO never opened at... -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Global Variables: 'my' vs 'use vars'
Hello, All: I've never been very good at scoping so it it's no surprise that this confuses me: When declaring variables at the beginning of a script, what is the difference between 'my' and 'use vars'? -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Looping through elements of an anonymous array
Hello, All: I have an unusual question: If I have an anonymous array stored in a hash, is there a more graceful way of iterating through each item in the anonymous array than using a counter? i.e., @all_records{q} = [1, 2, 3] $j = 0; while ($all_records{q}->[$j]) { print $all_records{$i}->[$j]; $j++; } -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Script execution via email
On Thu, 16 May 2002, Dan Fish wrote: > What I'd *like* to do is be able to generate these reports "on-demand" from > remote locations by setting up some sort of email trigger that will run the > script when an email is sent to specially designated address and then return > the results via email Dan: If you're using a Unix system, you can simply add a line to your /etc/aliases file (for sendmail users) or /etc/postfix/aliases file (for postfix users) like such: username: | /usr/bin/script.pl sendmail/postfix will pipe the contents of the message to the script /usr/bin/script.pl when it receives an email for [EMAIL PROTECTED] -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [ Something Funnie to Read ;) ]
On Thu, 16 May 2002, Bob wrote: > What could a url do, it isn't a document, just a link. Two words: Code Red. -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Looping through variables
Hello, All: I'm trying to loop through a list of variables and print their values. e.g., print $name, $age, $phone. What's the best way to do this? I've tried foreach (qw(name age phone)) { print ${$_}; } but that doesn't seem to work. -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Looping through variables
On Fri, 17 May 2002, Mark Anderson wrote: > It works for me (using perl 5.6.1), what seems to be the problem? > Why do you want to do this instead of just having three print statements? > Are you sure that you have data in the thre variables? FWIW: Looking back at my original script, I had declared the variables $name, $age, $phone *OUTSIDE*OF* the foreach loop. That's why they were undefined!!! my ($name, $age, $phone); foreach (qw(name age phone)) { print ${$_}; } (What a bone-head!) Actually, what I was *trying* to do was dereference variables and pass their values to DBI->quote() to build a string. e.g., # Build the value string 'eric','34','555-1212' foreach ($age $name $phone) { $values .= $dbh->quote($_) . ','; } # Remove the extra comma at the end chop $values; $dbh->do(INSERT INTO $dbfile ($column_names) VALUES ($values)); I suppose that I should just pass the variable's *value* to quote() instead of trying to pass the variable itself. Thanks! -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Looping through variables
On Sat, 18 May 2002, Michael Fowler wrote: > Given your code above, that isn't the problem. Where they're declared has > no effect on the definedness; it does, however, cause compile-time errors > when use strict is in effect. That is not the problem you were > encountering, though. The variables are undefined for a very simple reason: > you never assigned a value to them. I could have sworn that I gave them values... Hm. That bit of code is gone now. > Instead of using DBI's quote method use placeholders: > $dbh->do( > "INSERT INTO $dbfile ($column_names) VALUES (?, ?, ?)", > {}, > $age, $name, $phone > ); > It saves most of your work. See perldoc DBI. The quoting is necessary because many of the values that are stored contain white-space and punctuation. Thanks for the tip, though. -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Looping through variables
FWIW: This is the solution that I finally settled upon (in full context): $column_names = "COMPANY_NAME,JOB_TITLE,JOB_ID,URL,MAIL_TO,ATTACH,DATE"; foreach (qw(company_name job_title job_id url mail_to attach)), time) { # Append the quote'd parameter-value || the time-value in the list $new_values .= $dbh->quote(param($_) || $_) . ','; } # Remove the final comma from $new_values chop $new_values; $sth = $dbh->do("INSERT INTO $db_file ($column_names) VALUES ($new_values)") or die "Could not prepare statement: " . DBI->errstr; -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
SQL: Insert column?
Hello, All: I'm using DBI.pm to interact with flat-file database and want to add a new column to the database. Is there an SQL statement for such a task or do I need to transfer the contents of the file to another file and insert the column during the transfer? -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DB_file help.
On 31 May 2002, Postman Pat wrote: > I am trying to create a small database... > > How would I go about storing and retrieving this information? Any examples > please?? Pat: If you haven't already: Read "Programming the Perl DBI". It's actually a quick read and does a great job of introducing the reader to database concepts. (The book used to have a Web site - stonehenge.com - but the site doesn't appear to be available any longer.) The DBI.pm is finicky enough that you'll really need this reference. -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Initializing CPAN
Hello, All: Does CPAN use http? I'm using it on a machine that has all ports except smtp/ssh/http/https blocked. (i.e., ports 22/25/80/443 are the only open ports) I've just started using the CPAN module for the first time and am having some trouble during initialization: The process dies after it attempts to use lynx to connect to ftp://ftp.perl.org/pub/CPAN/MIRRORED.BY.gz. (It tries other methods to connect using ftp first too, but then dies after it tries lynx.) (Yes - Lynx is installed and is in the user's path.) -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Initializing CPAN
On Tue, 25 Jun 2002, Fontenot, Paul wrote: > Let it have 20 and 21 for ftp I poked a hole in the firewall to accept all related/established packets coming *from* ports 20 & 21 but that didn't work. I seem to recall that ftp actually uses two different ports for the same dialogue. Can anyone refresh my memory on how ftp communicates? -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
CPAN: install Bundle::CPAN
Hello, All: This is my first time using the CPAN module. While using CPAN to download/install a module, CPAN reported that I should run 'install Bundle::CPAN' to get the latest stuff. When I entered 'install Bundle::CPAN' it went about it's business getting and make'ing and started asking about where to install _all_kinds_of_stuff_... What the heck is Bundle::CPAN? What is going on? It seems like it's installing a completely new version of Perl or something. (It wanted to know where my C compiler is and where it should install stuff!!!) -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: HTML::Template
On Sun, 23 Jun 2002, Shawn Bower wrote: > <--> > my $template = HTML::Template->new(filename=>'weather.html'); > $template->param('CurrTime', $currTime); > $template->param('CurrTemp', $currTemp); > $template->param('HiTemp', $hiTemp); > $template->param('LoTemp', $loTemp); > $template->param('ImgLoc', $imgLoc); > $template->param('CurrCon', $currCon); > > #Display template page > print "Content-Type: text/html\n\n"; > print $template->output; Shawn: Where are the variables being set? e.g., $imgLoc = 'foo.bar.com/images.gif'; -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Displaying Problems
On Tue, 25 Jun 2002 [EMAIL PROTECTED] wrote: > Well, I still can't get my page to display. kb: Much earlier in this thread, I think, the fundamental point got lost: CGI.pm is an added layer of abstraction that creates an additional opportunity for users to wreak havoc. When scipting Web app's with CGI.pm, I usually develop the HTML separately and then translate that into CGI.pm function calls _a_step_at_a_time_ so that I can catch those MINOR typos that can bring the entire script to a screaching halt much earlier. As to your complaint: I recommend that you... 1. begin riping-out sections of code until the script works (so that you can find the almost-certainly minor typo that is causing you heartburn), or 2. write a smaller script that embodies the jist of what you're trying to accomplish as most people who subscribe to this list (myself *especially*) have neither the time nor the patience to sift through anything longer than a screen-full of intricate code only to find insignificant errors. (e.g., typos) -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]