[25066] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 7316 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 27 00:10:39 2004

Date: Tue, 26 Oct 2004 21:10:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 26 Oct 2004     Volume: 10 Number: 7316

Today's topics:
        Modify program to write just data to a text file. (Mortgageloan2004)
    Re: Modify program to write just data to a text file. <simon@unisolve.com.au>
    Re: Modify program to write just data to a text file. <usa1@llenroc.ude.invalid>
    Re: Modify program to write just data to a text file. <noreply@gunnar.cc>
    Re: Modify program to write just data to a text file. <usa1@llenroc.ude.invalid>
    Re: Modify program to write just data to a text file. <noreply@gunnar.cc>
    Re: open-perl-ide qustion <phaylon@dunkelheit.at>
    Re: open-perl-ide qustion <segraves_f13@mindspring.com>
    Re: open-perl-ide qustion <cwilbur@mithril.chromatico.net>
    Re: regex to extract color guide from html <noreply@gunnar.cc>
    Re: regex to extract color guide from html <jgibson@mail.arc.nasa.gov>
    Re: regex to extract color guide from html <cmail@cherryplankton.com>
    Re: What's the seed? ctcgag@hotmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 27 Oct 2004 02:35:39 GMT
From: mortgageloan2004@aol.com (Mortgageloan2004)
Subject: Modify program to write just data to a text file.
Message-Id: <20041026223539.28660.00001485@mb-m05.aol.com>

This program, below,  will create a database and write the fields and their
values to a database, and email just the data or the data and the fieldnames. 
I want it it to do the following in addition to what it already does without
changing that.   I want it to take just the data from the form just completed,
and save it to a comma delimited text file. ( Just data values separated by a
comma) Then use sendmail  to send an email with the file just created attached
to the email message and sent the email to whoever I specify. The data will be
imported into another program. Could someone please help with this additional
code? 

##########################################################
# Advanced Settings email
my $send_me                  = 1;
my $admin_mail               = 'loanapps@mortgage-pros.com';
my $from                     = 'nobody@mortgage-pros.com'; 
my $from_field_name  	     = 'email';
my $email_input_error        = "Non resolved email input";
my $send_just_data	     = 1;
my $mailprog                 = '/usr/sbin/sendmail';
my $subject                  = 'New loan request in database';
##########################################################
# Advanced Settings Auto Responder, must enable $from_field_name
my $auto_responder 	     = '0';
my $auto_responder_from	     = 'email@hotmail.com';
my $auto_responder_subject   = "Thank you for your form submit";
my $auto_responder_message   = 'reply.txt';
##########################################################
# Advanced Settings SMTP email
# use Net::SMTP;
my $send_via_SMTP            = 0;
my $mailhost                 = 'smtp.com';
##########################################################
# Advanced Settings required fields
my @required_fields          =
(realname,Borrowerfirst,Borrowerlast,BorrowerHomePhone,BorrowerAddress,Bor
rowerCity,BorrowerState,BorrowerZip,
BorOutstandingJudgements,BorBankrupt,BorForeclose,BorLawsuit,BorOblig,BorD
elinquent,BorAlimony,BorBorrowed,BorCoMake,BorCitizen,BorAlien,BorPrimary,
BorOwnership,OtherMonthlyPayments,MonthlyBalances);
my @required_fields_numbers  = (BorBaseInc);
my @required_fields_email    = (email);
my $error_fields_require     = "Field is blank, it is required";
my $error_fields_numbers     = "Only numbers";
my $error_fields_email       = "email address is not valid";
my $error_title              = "<b>Sorry, we require more information</b>";
my $fontColor                = "black";
my $fontSize                 = 3;
my $fontFace                 = "Verdana";
my $return_message           = "Please click 'back' on your browser and try
again";
##########################################################
# Advanced Settings extra database
my $field_name_database      = '';
$DB{'database2'} = 'database2.txt';
$DB{'database3'} = 'database3.txt';
$DB{'database4'} = 'database4.txt';
$DB{'database5'} = 'database5.txt';
##########################################################
# Advanced Settings extra thank you page
my $HTML_thankyou_field_name = '';
$ThankYou{'thankyou2'}    = 'index2.htm';
$ThankYou{'thankyou3'}    = 'index3.htm';
$ThankYou{'thankyou4'}    = 'index4.htm';
$ThankYou{'thankyou5'}    = 'index5.htm';
##########################################################
# EZscripting.co.uk © 1999 - 2004 Copyright Darren Deans
# The scripts are available for private and commercial use.
# You can use the scripts in any website you build.
# It is prohibited to sell the scripts in any format to anybody.
# The scripts may only be distributed by EZscripting.co.uk.
# The redistribution of modified versions of the scripts is prohibited.
# EZscripting.co.uk accepts no responsibility or liability
# whatsoever for any damages however caused when using our services or scripts.
# By downloading and using this script you agree to the terms and conditions.
##########################################################
my $alternativeDateFormat    = 0; # BETA Feature not yet in use
my $display_data_afterSubmit = 0; # BETA Feature not yet in use

@date=localtime();
$date[4]++;
$date[5]+=1900;
for(0..4){$date[$_]=sprintf("%02d",$date[$_]);}
$date="$date[2]:$date[1]:$date[0] $date[5]-$date[4]-$date[3]";
if ($alternativeDateFormat){
	$date[5]=sprintf("%02d",$date[5]-2000);
 	$date = "$date[5]:$date[4]:$date[3]-$date[0]:$date[1]:$date[2]";
 }

my @field;
#print "Content-type: text/html\n\n";
error("Error: Bad record separator!") if !$separator or $separator eq $change
or $separator=~m /["'\.\\\/]/;
$my_separator=$separator;
$my_separator="\\".$separator if $separator eq '|'or  $separator eq ',' or 
$separator eq '.';

%FORM = parse_cgi();
$base_file = $DB{$FORM{$field_name_database}} if $FORM{$field_name_database};
error("Please, select correct database on head of script!") unless $base_file;
create_base()  if  !stat($base_file);
push @required_fields_email, $from_field_name if $from_field_name;
test_form();



open(F, $base_file) || error("Can't open file $base_file!");
my @data = <F>;
close F;
	@data_fields=split($my_separator, $data[0]);
	error("You have bad file!") if !@data_fields;
	chomp $data_fields[@data_fields-1];
	if($ID_autoincrement_name && $ID_autoincrement){
		my $positionID =-1; my $p=0;
		foreach(@data_fields){
			$positionID=$p if $_ eq $ID_autoincrement_name;
			$p++;
		}
		if($positionID>=0){
			#seach max ID
			for(1..@data-1){
				@line=split($my_separator, $data[$_]);
				$maxID=$line[$positionID] if $maxID<$line[$positionID];
			}
			$maxID||=1000;
			$maxID++;
		}
		else{error("Can't find ID-field in your db!");}
	}
	
	my $line;
	
my $text;
	
foreach(@data_fields){
	if ($_ eq 'REMOTE_ADDR'){
		$line .="$ENV{REMOTE_ADDR}$separator";
		$field{$_}=1; 
		$message.="$_: " unless $send_just_data;
		$message.="$ENV{REMOTE_ADDR}\n";
	}
	elsif ($_ eq 'HTTP_USER_AGENT'){
		$line .="$ENV{HTTP_USER_AGENT}$separator";
		$field{$_}=1; 
		$message.="$_: " unless $send_just_data;
		$message.="ENV{HTTP_USER_AGENT}\n";
	}
	elsif ($_ eq 'DATE'){
		$line .="$date$separator";
		$field{$_}=1; 
		$message.="$_: " unless $send_just_data;
		$message.="$date\n";
	}
	elsif ($ID_autoincrement && $_ eq $ID_autoincrement_name){
		$line .="$maxID$separator";
		$field{$_}=1; 
		$message.="$_: " unless $send_just_data;
		$message.="$maxID\n";
	}
	else{
		$line .="$FORM{$_}$separator";
		$field{$_}=1; 
		$message.="$_: " unless $send_just_data;
		$message.="$FORM{$_}\n";
	}
	
} 
chop $line;

foreach(@field){error("Field $_ not exist!") if !$field{$_};}	



$from =  $FORM{$from_field_name} if $FORM{$from_field_name};
if($admin_mail && $send_me){male($admin_mail, $from, $subject, $message);}
if($auto_responder && $FORM{$from_field_name}){
	open(F, "$auto_responder_message") or error("Can't open message file");
	my @message=<F>;
	close F;
	male($FORM{$from_field_name},$auto_responder_from,$auto_responder_subject,
join('',@message)); 
	
	}
	
	open(F, ">>$base_file") || error("Can't open file $base_file!");
	print F "$line\n";
	close F;	
	

$HTML_thankyou =  $ThankYou{$FORM{$HTML_thankyou_field_name}} if 
$ThankYou{$FORM{$HTML_thankyou_field_name}};

if ($display_data_afterSubmit && $ID_autoincrement &&
$HTML_thankyou=~m/\.pl|\.cgi/i){ print "Location:
$HTML_thankyou?show=$maxID\n\n";}
else{print "Location: $HTML_thankyou\n\n";}
exit;


##############################################################
sub create_base{
	
	my $field = join($separator, @field);
	$field.=$separator."$ID_autoincrement_name" if $ID_autoincrement &&
$ID_autoincrement_name;
	$field.=$separator."REMOTE_ADDR" if $REMOTE_ADDR;
	$field.=$separator."HTTP_USER_AGENT" if $HTTP_USER_AGENT;
	$field.=$separator."DATE" if $DATE;
	
	open(F, ">$base_file");
	print F "$field\n";
	close F;
}

sub error{
	print "Content-type: text/html\n\n";
	print "<html><head><title>Error</title></head><body><br>";
	print "<font color=$fontColor size=$fontSize
face=$fontFace>$error_title</font><br>" if $_[1];
	print "<br><font color=$fontColor size=$fontSize
face=$fontFace>$_[0]</font><br>";
	print "<font color=$fontColor size=$fontSize
face=$fontFace>$return_message</font>" if $_[1];
	print "</body></html>";
	exit;

}

sub parse_cgi{
	my(%FORM,$name,$value,$content);
	my $a=0;
	read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
	@pairs = split(/&/, $buffer);
	foreach $pair (@pairs) {
	   ($name, $value) = split(/=/, $pair);
	   $value =~ tr/+/ /;
	   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
	   $value =~ s/"/&#34;/g;
	   $value =~ s/'/&#39;/g;
	   $value =~ s/<!--(.|\n)*-->//g if $kill_html_tags;
	   $value =~ s/<([^>]|\n)*>//g if $kill_html_tags;
           $value =~ s/\n/$line_break/g;	 # added to strip line breaks
           $value =~ s/\r//g;  
	   $value =~ s/\Q$separator/$change/g;
	   if($FORM{$name}){$FORM{$name} = ", ".$value;}
           else{
           	$FORM{$name} = $value;
           	$field[$a++]=$name if $name ne $HTML_thankyou_field_name and $name
ne $field_name_database and !($kill_image_buttons_value &&
$name=~/(\.|\A)(x|y)\Z/);
           }
	}
	$a=0;
	$temp=$ENV{'QUERY_STRING'};
	@pairs=split(/&/,$temp);
	foreach $item(@pairs) {
		($key,$content)= split (/=/,$item,2);
		$content =~ tr/+/ /;
		$content =~ s/%(..)/pack("c",hex($1))/ge;
		$content =~ s/\Q$separator/$change/g;
		$content =~ s/"/&#34;/g;
		$content =~ s/'/&#39;/g;
		$content =~ s/<!--(.|\n)*-->//g if $kill_html_tags;
		$content =~ s/<([^>]|\n)*>//g if $kill_html_tags;
		$content =~ s/\n/$line_break/g;	 # added to strip line breaks
		$content =~ s/\r//g;
		if($FORM{$key}){$FORM{$key} .= ", ".$content;}
		else{
			$FORM{$key} = $content;
			$field[$a++]=$key if $key ne $HTML_thankyou_field_name and $key ne
$field_name_database and !($kill_image_buttons_value &&
$key=~/(\.|\A)(x|y)\Z/);
		}
	}
	return %FORM;
}



sub male{
	error($email_input_error)  if length($_[1])>120 or length($_[0])>120;
	error($email_input_error)  if $_[1]=~m/:/is or $_[0]=~m/:/is;
	error($email_input_error)  if $_[1]=~m/Content-type/is or
$_[0]=~m/Content-type/is;
	error($email_input_error)  if $_[1]=~m/\n/is or $_[0]=~m/\n/is ;
	$_[1] =~ s/<([^>]|\n)*>//g;
	$_[0] =~ s/<([^>]|\n)*>//g;
	$_[1]=~s/\n|\r//g;
	$_[0]=~s/\n|\r//g;

	if($send_via_SMTP){
	    $smtp = Net::SMTP->new($mailhost);

	    $smtp->mail($_[1]);
	    $smtp->to($_[0]);

	    $smtp->data();
	    $smtp->datasend("To: $_[0]\n");
            $smtp->datasend("From: $_[1]\n");
	    $smtp->datasend("Subject: $_[2]\n\n");
	    $smtp->datasend("\n");
	    $smtp->datasend("$_[3]\n");
	    $smtp->dataend();

	    $smtp->quit;

	}
	else{
		open(MAIL,"|$mailprog -t");
		print MAIL "To: $_[0]\n";
		print MAIL "From: $_[1]\n";
		print MAIL "Subject: $_[2]\n\n";
		print MAIL "$_[3]\n";
		close(MAIL);
		#print "To: $_[0]<br>";
	}
}


sub test_form{
	my $errors='';
	foreach(@required_fields){
		$errors.="ERROR FIELD &lt; $_ &gt;: $error_fields_require!<br>" if $FORM{$_}
eq "";
	}
	foreach(@required_fields_numbers){
		$errors.="ERROR FIELD &lt; $_ &gt;: $error_fields_numbers!<br>" if
$FORM{$_}=~m/\D/ or $FORM{$_} eq '';
	}
	foreach(@required_fields_email){
		$errors.="ERROR FIELD &lt; $_ &gt;: $error_fields_email!<br>" if $FORM{$_}
!~m/\S+?\@\S+?\.\S+?/;
	}
	error("$errors",1) if $errors;
	
	
return;
}


------------------------------

Date: Wed, 27 Oct 2004 12:45:15 +1000
From: Simon Taylor <simon@unisolve.com.au>
Subject: Re: Modify program to write just data to a text file.
Message-Id: <cln2f6$21s5$1@otis.netspace.net.au>

Mortgageloan2004 wrote:
> This program, below,  will create a database and write the fields and their
> values to a database, and email just the data or the data and the fieldnames. 
> I want it it to do the following in addition to what it already does without
> changing that. I want it to take just the data from the form just completed,
> and save it to a comma delimited text file. ( Just data values separated by a
> comma) 


See TEXT::CSV

     http://search.cpan.org/~alancitt/Text-CSV-0.01/CSV.pm

or TEXT::CSV_XS

     http://search.cpan.org/~jwied/Text-CSV_XS-0.23/CSV_XS.pm

for modules that will help with this.

> Then use sendmail  to send an email with the file just created attached
> to the email message and sent the email to whoever I specify. 

See MIME::Lite (or many other modules that wil help with this)

     http://search.cpan.org/~yves/MIME-Lite-3.01/lib/MIME/Lite.pm

 > The data will be
> imported into another program. Could someone please help with this additional
> code? 

You'll increase your chances of getting help in this forum
by posting example code showing what you've tried and describing
how it failed.

Good luck!

Regards,

Simon Taylor


------------------------------

Date: 27 Oct 2004 03:04:05 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: Modify program to write just data to a text file.
Message-Id: <Xns958EEAA8E16Aasu1cornelledu@132.236.56.8>

mortgageloan2004@aol.com (Mortgageloan2004) wrote in
news:20041026223539.28660.00001485@mb-m05.aol.com: 

> This program, below,  will create a database and write the fields and
> their values to a database, and email just the data or the data and
> the fieldnames. I want it it to do the following 

Ahem ... so, you want us to violate the license for this code and do so in 
public?

> ##########################################################
> # EZscripting.co.uk © 1999 - 2004 Copyright Darren Deans
 ...
> # The redistribution of modified versions of the scripts is
> # prohibited. 
 ...

Oh, by the way, this is not a supermarket but a programmers' forum. We 
are not in the business of writing canned scripts or fixing other people's 
messes.

You might want to head on over to http://jobs.perl.org/ and look for 
someone you can hire to do this work.

No

use strict;
use warnings;

Cargo cult CGI parsing ... Things like:

sub male {
	error($email_input_error)  if length($_[1])>120 or 
length($_[0])>120;

Oh, don't forget:

Global symbol "%DB" requires explicit package name at t.pl line 46.
Global symbol "%DB" requires explicit package name at t.pl line 47.
Global symbol "%DB" requires explicit package name at t.pl line 48.
Global symbol "%DB" requires explicit package name at t.pl line 49.
Global symbol "%ThankYou" requires explicit package name at t.pl line 53.
Global symbol "%ThankYou" requires explicit package name at t.pl line 54.
Global symbol "%ThankYou" requires explicit package name at t.pl line 55.
Global symbol "%ThankYou" requires explicit package name at t.pl line 56.
Global symbol "@date" requires explicit package name at t.pl line 71.
Global symbol "@date" requires explicit package name at t.pl line 72.
Global symbol "@date" requires explicit package name at t.pl line 73.
Global symbol "@date" requires explicit package name at t.pl line 74.
Global symbol "@date" requires explicit package name at t.pl line 74.
Global symbol "$date" requires explicit package name at t.pl line 75.
Global symbol "@date" requires explicit package name at t.pl line 75.
Global symbol "@date" requires explicit package name at t.pl line 75.

 ... many more snipped ...

Bareword "BorLawsuit" not allowed while "strict subs" in use at t.pl line 
26.
Bareword "BorOblig" not allowed while "strict subs" in use at t.pl line 26.
Bareword "BorAlimony" not allowed while "strict subs" in use at t.pl line 
26.
Bareword "BorBorrowed" not allowed while "strict subs" in use at t.pl line 
26.
Bareword "BorCoMake" not allowed while "strict subs" in use at t.pl line 
26.
Bareword "BorCitizen" not allowed while "strict subs" in use at t.pl line 
26.
Bareword "BorAlien" not allowed while "strict subs" in use at t.pl line 26.
Bareword "BorPrimary" not allowed while "strict subs" in use at t.pl line 
26.
Bareword "BorOwnership" not allowed while "strict subs" in use at t.pl line 
26.
Bareword "OtherMonthlyPayments" not allowed while "strict subs" in use at 
t.pl line 26.
Bareword "MonthlyBalances" not allowed while "strict subs" in use at t.pl 
line 26.
Bareword "BorBaseInc" not allowed while "strict subs" in use at t.pl line 
32.
Bareword "email" not allowed while "strict subs" in use at t.pl line 33.
t.pl had compilation errors.




------------------------------

Date: Wed, 27 Oct 2004 05:06:04 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Modify program to write just data to a text file.
Message-Id: <2u8hu9F27vmlbU1@uni-berlin.de>

A. Sinan Unur wrote:
> Ahem ... so, you want us to violate the license for this code and do
> so in public?
> 
>>##########################################################
>># EZscripting.co.uk © 1999 - 2004 Copyright Darren Deans
> 
> ...
> 
>># The redistribution of modified versions of the scripts is
>># prohibited. 
> 
> ...

Does that really mean that you are not allowed to modify the script for
your own use, i.e. as long as you don't distribute the modified version
to somebody else?

> Oh, by the way, this is not a supermarket but a programmers' forum.
> We are not in the business of writing canned scripts or fixing other
> people's messes.

Indeed.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: 27 Oct 2004 03:19:02 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: Modify program to write just data to a text file.
Message-Id: <Xns958EED32067Basu1cornelledu@132.236.56.8>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in news:2u8hu9F27vmlbU1@uni-
berlin.de:

> A. Sinan Unur wrote:
>> Ahem ... so, you want us to violate the license for this code and do
>> so in public?
 ...
>>># The redistribution of modified versions of the scripts is
>>># prohibited. 

>> ...

> Does that really mean that you are not allowed to modify the script for
> your own use, i.e. as long as you don't distribute the modified version
> to somebody else?

Good question. My answer is I do not know because the full statement:

# EZscripting.co.uk © 1999 - 2004 Copyright Darren Deans
# The scripts are available for private and commercial use.
# You can use the scripts in any website you build.
# It is prohibited to sell the scripts in any format to anybody.
# The scripts may only be distributed by EZscripting.co.uk.
# The redistribution of modified versions of the scripts is prohibited.
# EZscripting.co.uk accepts no responsibility or liability
# whatsoever for any damages however caused when using our services 
# or scripts.
# By downloading and using this script you agree to the terms and 
# conditions.

does not explicitly allow modifying scripts for own use. On the other hand, 
since the script uses a bazillion variables instead of a proper 
configuration mechanism, it is impossible to use it without 'modifying' it.

Sinan.


------------------------------

Date: Wed, 27 Oct 2004 05:22:20 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Modify program to write just data to a text file.
Message-Id: <2u8it3F27r8coU1@uni-berlin.de>

A. Sinan Unur wrote:
> On the other hand, since the script uses a bazillion variables
> instead of a proper configuration mechanism, it is impossible to use
> it without 'modifying' it.

Yeah. :)  If it hadn't said © 1999 - 2004, I'd rather have guessed
© 1989 - 1994 ...

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: Wed, 27 Oct 2004 00:24:36 +0200
From: "Robert Sedlacek" <phaylon@dunkelheit.at>
Subject: Re: open-perl-ide qustion
Message-Id: <opsgh0jacd2n465k@localhost>

Am Tue, 26 Oct 2004 08:58:28 -0400 schrieb daniel kaplan  
<nospam@nospam.com>:

> even stranger, is it possible that there is someone out there who doesn't
> realize that googling something only gives you listings for it, and not
> other programmers opinions?

Do you wanna say by that you haven't used groups.google.com so far?

g,
Robert

-- 
http://www.dunkelheit.at/


------------------------------

Date: Wed, 27 Oct 2004 00:22:29 GMT
From: "Bill Segraves" <segraves_f13@mindspring.com>
Subject: Re: open-perl-ide qustion
Message-Id: <9TBfd.8710$5i5.3198@newsread2.news.atl.earthlink.net>

"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrncntfpn.o7t.tadmc@magna.augustmail.com...
> Uri Guttman <uri@stemsystems.com> wrote:
> >>>>>> "BS" == Bill Segraves <segraves_f13@mindspring.com> writes:
> >

Note 1: The line below should be attributed to the OP, not to Bill Segraves:
> >  >> vi?  is this another one i can try?
Note 2: I think I may have mistakenly interpreted in the above "this" =
"there".

> >
> >  BS> cat
> >
> > that is a dog of an editor!
>
>
> and it doesn't use a mouse!

Unfortunately, a serious attempt to show the OP a minimalistic alternative
for an editor, i.e., cat, especially for embedded systems that may have an
abbreviated implementation of busybox, was sidetracked by the inherent humor
in the thread.

Uri and Tad, thanks for the humorous contributions to the thread.

BTW, to the OP, my personal preferences for editors depend on the system I'm
using, e.g.,

On this Windows system, shortcuts for Emacs and a primitive, but useful,
Perl/Tk File Editor reside on the Taskbar, while Edit, Notepad, and Wordpad
are available, as well. On various Linux/Knoppix systems, I use ed, vi,
emacs, or one of the many other text editors that are available.

In another life, I used Cadre and IDE. In that same life, I had a colleague
who used (1) vi and (2) cat, together with the Bash "history" command, very
effectively to write programs, shell scripts, etc. This colleague could
write programs/scripts on the fly as fast as he could type, which appeared
to be about 100 wpm.

To the OP: My recommendation is to use whatever allows you to get your job
done most efficiently.

All the best.
--
Bill Segraves




------------------------------

Date: Wed, 27 Oct 2004 02:32:33 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: open-perl-ide qustion
Message-Id: <87lldshpbx.fsf@mithril.chromatico.net>

>>>>> "SP" == Sherm Pendley <spamtrap@dot-app.org> writes:

    SP> The same applies to Perl docs in general, actually. Trying to
    SP> memorize them all would be a Herculean task. But it *is* a
    SP> pretty good idea to familiarize yourself with "perldoc perl",
    SP> so you'll know what docs are available.

Hell, I've been using Perl for 10 years, and I *still* consult the FAQ
when I'm trying something I haven't done before.  

For a while I got the FAQ-a-day mailings, and that was a pretty
convenient way to digest it.

Charlton


-- 
cwilbur at chromatico dot net
cwilbur at mac dot com


------------------------------

Date: Wed, 27 Oct 2004 00:22:43 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: regex to extract color guide from html
Message-Id: <2u816fF26qkp3U1@uni-berlin.de>

cp wrote:
> I then observed that the first color to be picked up on a line was
> picked up but the remaining colors on the same line were skipped. I
> thought that adding the g modifier at the end of the regex would fix
> it but it produced the same exact output.

<snip>

> foreach(@data)
> {
>         next if not /td\>(\S+\s?\S*)\s*(\#[[:xdigit:]]+)\<td/g;
>         my $s1 = "$1\n";
>         my $s2 = "$2\n";
>         push @output,($s1,$s2);
> }

You are assigning $s1 and $s2 only once per line, so only the last pair
on respective line is added to @output.

One possible solution is to process each line in a while loop:

     foreach(@data) {
         while (/td>(\S+\s?\S*)\s*(#[[:xdigit:]]+)<td/g) {
             my $s1 = "$1\n";
             my $s2 = "$2\n";
             push @output,($s1,$s2);
         }
     }

But what happens if the color name and color code are on different 
lines? A better solution is to slurp the whole file as one string into a 
scalar variable, and drop the foreach loop:

     my $data = do { local $/; <FILE> };
     while ($data =~ /td>(\S+\s?\S*)\s*(#[[:xdigit:]]+)<td/g) {
         ...

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: Tue, 26 Oct 2004 16:16:58 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
To: cmail@cherryplankton.com
Subject: Re: regex to extract color guide from html
Message-Id: <261020041616589024%jgibson@mail.arc.nasa.gov>

[[ This message was both posted and mailed: see
   the "To," "Cc," and "Newsgroups" headers for details. ]]

In article <10nti0uq7ik3h6e@news.supernews.com>, cp
<cmail@cherryplankton.com> wrote:

> I copied a webpage that had a color guide that I liked.  I wanted to extract
> the color names and codes and make a list of name alternating with code,
> which, of course, could be made into a hash or saved in a file or whatever. 
> Below is some random clippings from the html so you can see what I am
> working with.  Below that is the foreach loop that goes through and looks
> for the color name and color code.  The html file is already loaded into
> @data.  I thought that it worked fine until I realized that some colors
> were missed.  I then observed that the first color to be picked up on a
> line was picked up but the remaining colors on the same line were skipped. 
> I thought that adding the g modifier at the end of the regex would fix it
> but it produced the same exact output.  Any suggestions would be greatly
> appreciated.
> 
> 
>  class=s><br>&nbsp;<td>mediumseagreen (<a href="colorsvg.html">SVG</a>)
> #3CB371<td bgcolor="#3CB371" class=s><td>gray24 #3D3D3D<td
> bgcolor="#3D3D3D" class=s>^M
> <tr align=right><td>cobalt #3D59AB<td bgcolor="#3D59AB"
> class=s><br>&nbsp;<td>cobaltgreen #3D9140<td bgcolor="#3D9140"
> class=s><td>gray25 #404040<td bgcolor="#404040" class=s>^M
> 
> <tr align=right><td>dodgerblue4 #104E8B<td bgcolor="#104E8B"
> class=s><br>&nbsp;<td>ultramarine #120A8F<td bgcolor="#120A8F"
> class=s><td>gray7 #121212<td bgcolor="#121212" class=s>^M
> 
> 
> foreach(@data)
> {
>         next if not /td\>(\S+\s?\S*)\s*(\#[[:xdigit:]]+)\<td/g;

Change the above line to:

         while( /td>(\S+\s?\S*)\s*(#[[:xdigit:]]+)<td/g ) {

>         my $s1 = "$1\n";
>         my $s2 = "$2\n";
>         push @output,($s1,$s2);

and add

      }
> }

The /g modifier means you can check for more matches in the same
string, but you do have to use the same regular expression on the same
search string, not the next element of @data. The characters '<', '>',
and '#' are not special in the double-quote environment of m// and need
not be escaped.


------------------------------

Date: Tue, 26 Oct 2004 21:44:30 -0400
From: cp <cmail@cherryplankton.com>
Subject: Re: regex to extract color guide from html
Message-Id: <10ntvi36278dbc6@news.supernews.com>

Gunnar Hjalmarsson wrote:

> cp wrote:
>> I then observed that the first color to be picked up on a line was
>> picked up but the remaining colors on the same line were skipped. I
>> thought that adding the g modifier at the end of the regex would fix
>> it but it produced the same exact output.
> 
> <snip>
> 
>> foreach(@data)
>> {
>>         next if not /td\>(\S+\s?\S*)\s*(\#[[:xdigit:]]+)\<td/g;
>>         my $s1 = "$1\n";
>>         my $s2 = "$2\n";
>>         push @output,($s1,$s2);
>> }
> 
> You are assigning $s1 and $s2 only once per line, so only the last pair
> on respective line is added to @output.
> 
> One possible solution is to process each line in a while loop:
> 
>      foreach(@data) {
>          while (/td>(\S+\s?\S*)\s*(#[[:xdigit:]]+)<td/g) {
>              my $s1 = "$1\n";
>              my $s2 = "$2\n";
>              push @output,($s1,$s2);
>          }
>      }
> 
> But what happens if the color name and color code are on different
> lines? A better solution is to slurp the whole file as one string into a
> scalar variable, and drop the foreach loop:
> 
>      my $data = do { local $/; <FILE> };
>      while ($data =~ /td>(\S+\s?\S*)\s*(#[[:xdigit:]]+)<td/g) {
>          ...
> 

Thanks to all for helpful advice.  I followed and now have 570 named colors
instead of the 243 I had before!  I did finally go with the all in one
string solution.  I am going to send them up to my website now...Thanks
again!

-- 
www.cherryplankton.com


------------------------------

Date: 27 Oct 2004 01:36:29 GMT
From: ctcgag@hotmail.com
Subject: Re: What's the seed?
Message-Id: <20041026213629.161$fH@newsreader.com>

Ben Morrow <usenet@morrow.me.uk> wrote:
> Quoth ctcgag@hotmail.com:
> > Derek Fountain <nospam@example.com> wrote:
> > > In any recent version of Perl, the seed for the random number
> > > generator is set at the first time rand() is called. Can I find out
> > > what that seed is so I can subsequently reproduce the random
> > > sequence?
> > >
> > > At present I'm setting my own seed using "time ^ ($$ + ($$ << 15))",
> > > but my program is being run repeatedly over and over, and only takes
> > > a fraction of a second to do its job. That means time is often the
> > > same for several runs, and $$ tends to go up in small, sometimes
> > > single, steps. I have my suspicions about the quality of my seed!
> >
> > I think this would be generally adequate, but you don't say what you
> > are using this for.  If you are concerned, and you think that perl's
> > default srand is better than what you are doing, I would do something
> > like this:
> >
> > my $x=int rand(~0);      #Cause srand to be invoked "naturally"
> > srand($x);
> > warn "using $x as seed"; #record seed
>
> I think this is incorrect: the seed contains *more* entropy than any
> given return value from rand(), so this will give you less random
> numbers than not setting the seed at all.

But the primary purpose wasn't to create a seed with more entropy
than perl's default seed, but rather to know what the seed was so it could
be re-used in the future.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 7316
***************************************


home help back first fref pref prev next nref lref last post