building substrings

2004-09-15 Thread David Gilden
Hello,

I am building a primary key for a database, and I guess the first question would be 
how safe is a key made from the last 4 digits of a social security num and the first 
3 letters of the last name.  Now for the PERL question, I have substr. line working 
correctly.
I wanted to try it with ReGrex,  but the syntax is escaping me. 
Any pointers would appreciated!
Thanks,
Dave
( webmaster @ www.coraconnection.com  / Ft. Worth, TX, USA) 


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

$ss = '1234567890';
$lname = 'Gilden';
# $pkey  = substr($ss,length($ss)-4,length($ss)) .  substr($lname,0,3);
# print  "$pkey\n";

$ss = '09876543';
$lname = 'Smith';
# this line is bad! -- trying to have the same functionality as the substr line.
$pkey = ($ss =~ m/\d{length($ss)-4}($ss{length($ss)})/);
# $pkey = ($pkey  =~ m/$lname{0,3}/;) 
print  "$pkey\n";

# Is there any advantage using  =~ m/(\w){3}/ over  substr method?

__END__


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




Perl regrp 101

2004-12-03 Thread David Gilden
Greetings,

## This Does what _not_ do what I would expect  -- return the first 3  
characters of type '\w'

$tmp ="Joe Smore1qazxswedcvfrtgbnhytujmkilptyot5000";
$tmp =~ s/(^\w{3})(.*)/$1/;
print "$tmp\n";  

# is ^ better outside the '()s'?


$tmp ="Joe Smore1qazxswedcvfrtgbnhytujmkilptyot5000";
($tmp) =  $tmp =~ s/(^\w{3})(.*)/$1/;
print "$tmp\n";   # name  contains "1"  not "Joe"

# $1 captures "Joe" --- but 

## This Does what I want !!
$tmp ="Joe Smore1qazxswedcvfrtgbnhytujmkilptyot5000";
($tmp) = $tmp =~ m/^(\w{3})/;
print "$tmp\n"; ## "Joe"

The above code works fine but I am not sure on reading the syntax 
-- and would this qualify as untainting data? -- and yes I realize we are 
clobbering $tmp


Thanks & Happy Holidays -- from Cow Town

Dave Gilden

(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)

PS: Please reply to me off list (and CC the list so that others can benefit!)

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




RE: Perl regrp 101 -- on OSX.....

2004-12-03 Thread David Gilden
To  David & the group,

Wags <[EMAIL PROTECTED]> wrote:

>  What version of Perl are running and on what OS

BBedit under Panther (OSX) Mac -- Berkeley BSD Unix 
perl v5.8.1  

> > 
> > ## This Does what _not_ do what I would expect  -- return the first 3
> > characters of type '\w' 
> > 
> > $tmp ="Joe Smore1qazxswedcvfrtgbnhytujmkilptyot5000";
> > $tmp =~ s/(^\w{3})(.*)/$1/;
> > print "$tmp\n";

>   I ran it and it displayed Joe. I am running under  Windows XP and Perl is 
> AS 5.8.4 ( 810 ).

So the above code in Windows XP does what I expected?  Not on my Apple G4!

>   Are you running with strict and warnings?   
No

> Exactly what did your code that you ran look like? 

The above code returned  $tmp   containing :
  "Joe Smore1qazxswedcvfrtgbnhytujmkilptyot5000"
No change, that's what has me puzzled


This is all the code...

> You  have given a paste, but what other code is there?
>   I would leave the ^ outside, but as stated, my print put out Joe.
> 
> Wags ;)


Regards, 
DG

(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)

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




RE: Perl regrp 101 -- correction

2004-12-03 Thread David Gilden
Ok,


> ## This Does what _not_ do what I would expect  -- return the first 3
> characters of type '\w' 

Give this a shot!


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

$tmp ="Joe Smore1qazxswedcvfrtgbnhytujmkilptyot5000";
$tmp =~ s/(^\w{3})/$1/;
print "$tmp\n";

This returns the whole string ... sorry about the earlier posts..
Although I still am not clear on the syntax of the following ::

## This Does what I want !!
$tmp ="Joe Smore1qazxswedcvfrtgbnhytujmkilptyot5000";
($tmp) = $tmp =~ m/^(\w{3})/;
print "$tmp\n"; ## "Joe"

Why does $tmp need '(...)'  ??



Thx
DG

(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)

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




Reading the first line of a file

2005-01-17 Thread David Gilden
Greetings,

The second piece of code should look for  "* InTune " somewhere in the 
first line
of the file if it does not, it should unlink the bad file and fire off the 
error, it seems
to happen all the time regardless of the match.

Two quick questions here:

I can't see why I am getting this error
:  Use of uninitialized value in print

#!/usr/bin/perl -w

# code test 
use strict;

my $str =  "* InTune ";

($str) = ($str =~ m/(\*{5} InTune)/);

print $str;
 
__END__

is there a way to add a -e to check to see if we have a file to unlink ?

#  Check to make sure it is an inTune File
open (FH, UPLOAD_DIR . "/$file")  || error( $q, "Error reading $file for test : 
 $!" );

while(){
if ($_ !~ /\*{5} InTune/){
unlink( UPLOAD_DIR . "/$file") or error( $q, "Problem deleting file $!");
error( $q, "The file you uploaded is not an inTune file. Only an inTune 
export file will be accepted." ); 
}
last;
} 
close FH;



Thanks,

Dave
(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)

Visit my schedule page for up to the minute performance info:



==
 Cora Connection: Your West African Music Source
  Resources, Recordings, Instruments & More!
    
==

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




Testing the first line of a file

2005-01-21 Thread David Gilden
Greetings,

I was looking for a way to improve the following: 

#  Check to make sure it is an inTune File
open (FH, UPLOAD_DIR . "/$file")  || error( $q, "Error reading $file for test : 
 $!" );

while(){
if ($_ !~ /\*{5} InTune/){
unlink( UPLOAD_DIR . "/$file") or error( $q, "Problem deleting file $!");
error( $q, "The file you uploaded is not an inTune file. Only an inTune 
export file will be accepted." ); 
}
last;
} 
close FH;

It never seemed to work consistently.  So after reading through my Perl archive 
here is what I am now using, which works great! ( special thanks to, Randal L. 
Schwartz )


#  Check to make sure it is an inTune File
open (FH, UPLOAD_DIR . "/$file")  || error( $q, "Error reading $file for test : 
 $!" );


while (($_ = ) !~ /[*]{5} InTune/) {
unlink( UPLOAD_DIR . "/$file") or error( $q, "Problem deleting file $!");
error( $q, "The file you uploaded is not an inTune file. Only an inTune 
export file will be accepted." );
last;
} 
close FH;

Have a great weekend!

Dave
(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)


Web Hosting  / Apache / PERL / PHP / mySql  --> for cheap!


==
 Cora Connection: Your West African Music Source
  Resources, Recordings, Instruments & More!
    
==

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




Digest version please

2001-04-19 Thread David Gilden

Can we get a digest version of list?
Thanks
Dave

**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**



matching with a loop

2001-04-19 Thread David Gilden

Hello,

What I want to is to load a file "$bw" 
and then have my regrex find if any of the bad words are in any of the form fields. 
The code I have here does not work.

# $in{$i} are the form fields, that need to be checked for 
# any of the bad words, contained in the bad_words.txt

$bw ='../class/bad_words.txt';

## read a list of bad words

open(BW,$bw) || die &dead("Can't find Bad word list", $!);
@indata = ; 
close(BW); 

$tmp = join ("|", @indata);
## need to cycle through them
### Does not work 

foreach $i (keys %in) {

if  ( $in{$i} =~ /$tmp/ig) {

print <  
Request denied-improper language.
@indata

$tmp
  
badwords
exit(0);

 
}

}

Thanks,
Dave

**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**



Populating Hashs and checking multi form fields

2001-04-20 Thread David Gilden

Hello,
Here is code fragment that I can't seem to solve.
All help, suggestions are appreciated.
Thanks!
Dave

What I want to do is to check for either if the username or password is good:

The $pwfile contains (exactly like it is here):
username1|password1
username2|password2
ect.


# stuff $pwd in to @indata
open(FILE,$pwfile) || die &dead("Can't find $pwfile. $!");
@indata = ;
close(FILE);


# populate a hash , I am guessing here!
foreach (@indata){
($x,$y) = split(/\|/,$_);
$users{$x} = $y;
}


# loop and process each record from $pwd
foreach $i (@indata) {
#remove hard return character from each record
chomp($i);

#split fields on pipe character
#assign a variable name to each of the fields
($username,$password) = split(/\|/,$i);


## want to check here and if something is not matching call our sub &dead
while (($test_username,$test_password) = each %users) {
# print "$test_username,$test_password\n";
# print "$in{'name'} $in{'pwd'} \n";
#&dead("Bad username , Sorry") if ($in{'name'} ne $test_username);
#&dead("Password, Sorry") if ($in{'pwd'} ne $test_password);
} 


---more deleted

**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**



Validating price (US Currency)

2001-04-23 Thread David Gilden

Is there a better way of doing this?
Thanks!
Dave



if ($in{'price'} eq "") {print '• Missing '; }  
 elsif (&checkPrice($in{'price'})) {
  print '• Wrong Format';
}




sub checkPrice{

if ($_[0] =~ /\$?(\d*)(\.\d{0,2})?/) {
return 1; 
} else {
return 0;
}

}


Allowable input: 
$1
$1.50
2
.50
$.50
-
Not allowable input: 
a
$5a
$e.40
--



print with => ??

2001-04-23 Thread David Gilden

Hello,
Sorry to ask this, as I am quite new at this.
And the online class that I am just now finishing has
lots of bad code for examples!

>From this list: 

 print "'$file' => '$newfile'\n";
 ^
 
What does this line mean, this a renaming convention?

Thanks
Dave 
--


while (defined(my $file = readdir(MSDS)))
{
next if $file =~ /^\.\.?$/;   # skip ".", ".."
next if $file =~ /\.pl$/; # don't want to rename Perl script
my $newfile = $file . ".txt"; # or whatever
print "'$file' => '$newfile'\n";
#   rename($file, $newname)
#   or warn "Couldn't rename '$file' => '$newfile': $!\n";
}



quick PERL question

2001-04-23 Thread David Gilden

Dear Casey and the list,
Thanks for your all of your valuable help,

What is $|++ for?

#!/usr/local/bin/perl -w
use strict;
$|++;

while (  ) {
  chomp; 
  print( &validate( $_ ) ? 'valid entry' : 'try again punk' );
  print "\n";
}

sub validate {
  my $currency = shift;

  # return false if we have an empty string or the string is just '$'.
  return 0 unless length( $currency ) > 0 && $currency ne '$';

  $currency =~ m<
 ^  # The beginning of the string
 \$?# We may have a $ sign, we may not
 \s*# We may encounter some space here
 \d*# We may nave a numerator but could just have '.50'
 (?:\.?\d{1,2})? # and we might have a denominator
 $  # The end of the string
>x ? 1: 0; # true if match succeeded, false otherwise
}

---

sub checkPrice{
return ($_[0] !~ /^\$?(\d+|\d*\.\d\d)$/) ? 1 : 0;
}

Is there a shorthand? Or do I need $_[0], 

-

I could not seem to include the sub chekPrice in my if statement 

$x = &checkPrice($in{'price'});
if ( ($in{'name'} eq "") or
 ($in{'type'} eq "") or
 ($in{'price'} eq "") or 
 $x)

{  .


  ###  won't pass syntax validation!  
   if ( ($in{'name'} eq "") or
 ($in{'type'} eq "") or
 ($in{'price'} eq "") or 
 &checkPrice($in{'price'})
 )

{ ..



---

Are there any issues with using 
 if (!length $in{price}) 
as opposed to:
if ($in{price} eq "") ...

I am not sure about !length, 
I mean it is not a $length, so it is not scalar is it some special variable?  
Thanks to [EMAIL PROTECTED] (Paul Johnson) for his input on this.


Dave







print statment

2001-04-23 Thread David Gilden

Original from the class:

print "\n";


Is this bad style?

print '',"\n";


better?

print ''. "\n";

I do believe that these 3 statements are all equivalent. 

Thanks

Dave



Multiple submit buttons CGI question

2001-05-22 Thread David Gilden

Hello,
Can any one tell where I went wrong here?
(I remember reading that a html form can have 
multiple submit forms as long as you parse them 
via their value)

Thanks!
Dave
-

In the html:


--

#!/usr/bin/perl 


$forminfo = ; 

@key_value_pairs = split(/&/,$forminfo); 

foreach $pair (@key_value_pairs){
   ($key,$value) = split(/=/,$pair);
   $value =~ s/\+/ /g; 
   $value =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("C", hex($1))/eg;
   $FORM_DATA{$key} = $value;
}

$num1 = $FORM_DATA{'num1'};
$num2 = $FORM_DATA{'num2'};
$result = 0;

### Determine what button was clicked
if ($FORM_DATA{'add'} eq "add") {

$result = $num1 + $num2;

} 
elsif ($FORM_DATA{'sub'} eq "sub") {
 $result = $num1 - $num2 ;  
}

#



foreach confusion

2001-05-22 Thread David Gilden

As an exercise here I want to play with this for a few minutes,
and have a few basic questions

#!/usr/bin/perl

# First question  do I use 
# (  )  OR { ... }
@lines = qq{dave john mike drew};
# First error, should be qw( ... )
# qq is garbage, right?


# is the  ','  correct in my($a,$b) can you use a space my($a $b @c)

my (%sortKeys,$i);


foreach ( @lines ) {
print"$_$i\n";

my $sortKey = $i++; # do something to create the sort key,
  # using %idToName to map the ID to the name
$sortKeys{$_} = $sortKey;
 
   }

# Then create a sub to pass to sort:

print "@lines $i\n";

# Could you elaborate on this
# $a $b are not passed any values -- don't understand 

sub bySortKey {
$sortKey{$a} cmp $sortKey{$b}
}

 print &bySortKey; 

exit(0);  # If script executes successfully do you  exit(1)  OR  exit(0);

Thanks 
Dave G.



Regrex question

2001-05-23 Thread David Gilden

Hello,
Thanks for all the help this list is providing,

Here is today's problem:


#!/usr/bin/perl

$test = "dave David Davy";

$i=0;


### Does not work want to count the number of matches...
$regex=  ($test=~ s/(dav)/$i++ $1/eig);

print "$regex $i\n";

### This does work..
$regex=  ($test=~ s/(dav)/$1 Smith/ig);

print "$regex\n"; 

__END__


It looks like  $regex contains the number of matches,
what I wanted to was capture the modified string

Also can some provide an example of how to use the 'e' switch in
a regrex,

Thanks

Dave






Perl library question

2001-05-24 Thread David Gilden

Hello,

I have moved my subroutines to a second file
and have named it "subs_lib.pl"

In the main file I have:

require "subs_lib.pl";

Is the following equivalent:

use "subs_lib.pl";
-

Secondly do I need:

#!/usr/bin/perl

as the first line in my "subs_lib.pl"

and are Libraries really modules with .pl instead of .pm?

Thank for everyone's help here :)

Thanks

Dave



RE: use strict / explicit packages

2001-05-29 Thread David Gilden

Hello,

I am using MacPerl here. 

After adding:
' use strict; '
and am now getting several warnings..
 
In my library I have %FORM_DATA declared,

File "hd:Perl:Cgi class:useractive:guest book:guestin.pl"; 
Line 9:  Global symbol "FORM_DATA" requires explicit package name.

How can I avoid the above warning?


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

require "libcgi2.pl";

&parse_input; # sub in our library 

#strip leading or trailing white space from all our form elements 
foreach  my $key (keys %FORM_DATA){ 
$FORM_DATA{$key} =~ s/^\s+|\s+$//g;
}

ect.

Maybe some one could chime in about explicit packages.


Thanks
Dave

**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**



RE: use strict / explicit packages

2001-05-29 Thread David Gilden

Did I touch a nerve here or what?

Ge, all of this totally   is confusing me,

So you know where I am coming from, I'm taking 
a second on-line CGI/PERL class that leaves a lot to be desired (if anyone knows
a good up-todate on-line class, please let me know!)

I will move up to learning CGI.pm, but for this month, I need to learn 
how share variables between PERL files.

So by way of example what do I need to add to my code so I can use the Strict Pragma?

I take it that this is considered bad programing style or is just out date, 
like the  tag in  :)

require "libcgi2.pl";

Also I don't understand this '::' syntax.

Thanks
Dave
(I would think that there are a few out there that might benefit from some 
clarification) 

 the  library file "libcgi2.pl" 

# used in guestout.pl and guestin.pl
$filename = 'guest_data/guest_data.txt';
#

sub parse_input { 

 $whichmethod = $ENV{'REQUEST_METHOD'};
 if($whichmethod eq "GET"){ 
   $forminfo = $ENV{"QUERY_STRING"};
 }else{
   $forminfo = ; } 
 @key_value_pairs = split(/&/,$forminfo); 
 foreach $pair (@key_value_pairs){
   ($key,$value) = split(/=/,$pair);
   $value =~ s/\+/ /g; 
   $value =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("C", hex($1))/eg;
   $FORM_DATA{$key} = $value;
 }
 } 

--- more stuff ---

return 1;
__END__
  
 


-- main perl executable,  what is this package's $Name? -

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

require "libcgi2.pl";

&parse_input; # sub in our library 

#strip leading or trailing white space from all our form elements 
foreach  my $key (keys %FORM_DATA){ 
$FORM_DATA{$key} =~ s/^\s+|\s+$//g;
}

ect.
--

**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**



iinfinite loop

2001-05-30 Thread David Gilden

The following seems to never break out of the loop,
any comments?
Thanks

Dave

#!/usr/bin/perl -w


$data = 'some
multi line
string';


while($data){
  
   push(@everyline, $_);  

}



basic questions!

2001-05-31 Thread David Gilden

Hi folks,

In my effort to fully understand online documentation [ perldoc ] 

I see all kinds of examples like the following :

This approach of treating C and C like object methods
calls doesn't work for the diamond operator.  That's because it's a
real operator, not just a function with a comma-less argument.  Assuming
you've been storing typeglobs in your structure as we did above, you
can use the built-in function named C.


I am not sure what they mean, is the C as in command line or as in construct?
-

I am not following what /m modifier does (I am looking thru the camel books not no 
luck so far)

# turn the line into the first word, a colon, and the
# number of characters on the rest of the line
s/^(\w+)(.*)/ lc($1) . ":" . length($2) /meg;

[ Last comment on perldoc, why am I seeing the leading "=" here: ]

=item Comments Inside the Regexp

The C modifier causes whitespace to be ignored in a regexp pattern
(except in a character class), and also allows you to use normal
comments there, too.  As you can imagine, whitespace and comments help
a lot.


Might be nice if in FAQ or on this list some might post a short tutorial 
on using  Perldoc. I just starting using it this week and I have on this list
for a month or so! Never was quite sure what the people meant when at the end of 
their post with stuff like:

references:

  perldoc perlmod
  perldoc -f require
  perldoc -f use



Unrelated question:

In a library file can the last line can be "1;" or should be "return 1;"



Thanks :)

Dave

-- Writing CGI Applications with Perl --  just arrived, it should help out!



**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**



printf and other stuff

2001-06-01 Thread David Gilden

Good afternoon,

Is there a way to combine the last two statements?

#!/usr/bin/perl -w

$sort_order =0;

$sort_type = ($sort_order) ? 'Newest First' : 'Oldest First';
# are the () optional?

print $sort_type;


##this does not work

print ($sort_order) ? 'Newest First' : 'Oldest First';

printf question--

### get time
my($sec, $min, $hour, $mday, $month, $year) = (localtime)[0..5];
$year += 1900;
$mday = "0" . $mday if $mday < 10;
$month++; # perl counts from -1 on occasion
$month = "0" . $month if $month < 10;


-- later in the same file --

print TOFILE "On $month/$mday/$year At $hour:$min you wrote:\n\n";

how do I use print to provide a leading '0' to $min, such that
I get 5:01 and not 5:1


Thanks!

Dave G.




push(@everyline, $_); vers $longstring .= $_;

2001-06-01 Thread David Gilden



Is one of these preferred over the other?



open(FROMFILE,$filename);

while(){
push(@everyline, $_);
 }


$longstring = join("",@everyline);
@oldentries = split(//,$longstring);


---OR---


open(FROMFILE,$filename);

while (){
   $longstring .=  $_;
}

@entries = split ('', $longstring);




Can you write split with // as in:


@entries = split (//, $longstring);
 
anything between /.../  is like, quoted "" 

Is this correct?


Thanks to all you kind folks, (What a Great List!) 

Dave


**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**



one last thought on printf

2001-06-02 Thread David Gilden


In the following chunk,

($sec, $min, $hour, $wday, $month, $year) = (localtime)[0..5];

1:  $year += 1900;
2:  $wday = "0" . $wday if $wday < 10;  # adds a leading zero , not needed
3:  $month++; # perl counts from -1 on occasion
4:  $month = "0" . $month if $month < 10; # same as above
 
# this line makes line 2 and 4 unnecessary, better style to handle it with printf (?)  
 
"On %02d/%02d/%04d At %d:%02d you wrote:\n\n", $month, $wday, $year, $hour, $min;


Also I am creating unique files and was thinking of the following:

$unique_file_name 'fourm'. (localtime) . '.html';

is there a better way of doing this, I am saving each entry froma web based guest book 
as
a separate .html file.  So if the same person submits another entry, I don't want that
to overwrite any older files, so I can't use their name for the file name with out 
some sort of
'key'...  any comments.


Regards,

Dave G.

--Yep PERL what else can you do on a rainy day :)
 



multi word strings (with spaces) in a hash key?

2001-06-03 Thread David Gilden



>  Quick question: can I use multi word strings (with spaces) in a hash key?
>  
>  $hash{time to upgrade}  # note the spaces, 

Well, yes, you can. But it's not a very good idea. If you absolutely must,
enclose the string in quotes.

$hash{'time to upgrade'}



 any comments on why this a bad Idea?

Thanks

Dave

**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**



command line switches?

2001-06-04 Thread David Gilden

Which perldoc will list the command line switches?
Thanks

Dave

**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**



Which Regrex

2001-06-04 Thread David Gilden

Is version 2 a better choice here?
Thx
Dave


#!/usr/bin/perl

# desired result ""bill gates the third"

$name= "bill_gates_the_third_132506042001.html";


# vers 1:
$name =~ s/^(\w+?)_(\d+).html$/$1/;
$name =~ tr/_/ /;

print "$name\n"; 

# 
# vers 2:

$name= "bill_gates_the_third_132506042001.html";
 $name =~ s/\d+.html$//;
 $name =~ tr/_/ /;
 $name =~ s/\s$//;

print "$name\n"; 


__END__



regrex delimiters

2001-06-06 Thread David Gilden

Hi, 
What is going on with the [] at the end of the regrex?
Thnx,
Dave G.


I so understand s///  however... I am little confused with following: 

#!/usr/bin/perl -w

$s = "long string of stuff";


($r = $s) =~ s/l\w+/[]gsx;

print $r;


__END__


File "untitled 15"; Line 6:  Substitution replacement not terminated.
-

# Delete (most) C comments.
   $program =~ s {
   /\* # Match the opening delimiter.
   .*? # Match a minimal number of characters.
   \*/ # Match the closing delimiter.
} []gsx;

# This is a variation on the s///; operator, which replaces
# the thing between the first two slashes with the thing between
# the last two slashes. Perl lets you choose something other than
# a slash, if you want. This regex matches C comments, by looking
# for "/*" (the '*' is a wildcard, so you have to 'escape' it by
# putting a backslash in front of it) -- followed by as few characters
# as possible (.* means "anything, zero or more times, '?' means
# "do this only until the "next thing" comes up). The "next thing" in
# this regex is "*/" - the closing delimiter of C comments. Again, you
# have to escape the splat, so that Perl doesn't treat it specially.
#
# after the "[]", the 'g' means "match globally", that is, look
# for as many matches as you can.
# the 's' means treat the input as a single line. That is, don't
# stop looking for a match when you hit a newline.
# the 'x' means "let me have comments in my regex."

**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**



m#^/\*# .. m#^\*/#;

2001-06-06 Thread David Gilden

Could someone please break this down, 
I am not sure how to read this:


 m#^/\*# .. m#^\*/#;  # using the range operator
  
match (# is the delimiter) 
at the start of a line /\* (and this where I lose it!)


  Frm Jason King
  
  #!perl -w
  use strict;

  open FILE, 'Cfile' or die "Bad open: $!";

  while()
  {
next if m#^/\*# .. m#^\*/#;  # using the range operator

print; # we're just printing for testing
  }

  __END__


Thanks-
Dave



avoiding duplicate values

2001-06-07 Thread David Gilden


Is this the correct way to avoid getting the same value twice?

# Text colors
@colors = qw[ #F0F8FF #00 #7FFFD4 #F0 #F5F5DC #FFE4C4  #4169E1 #8B4513 #FA8072 
#F4A460 #2E8B57 #A0522D ];


# choose a color!
$color_choice1 = rand $#colors;

# make sure we don't get same color twice

$color_choice2 = rand $#colors;

while ($color_choice1 eq $color_choice2){

$color_choice = $color_choice2 = rand $#colors;
last if ($color_choice1 ne $color_choice2);
}



Thx!

Dave

**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**



Re: avoiding duplicate values

2001-06-07 Thread David Gilden


> On Jun 7, David Gilden said:
> 
> >@colors = qw[ #F0F8FF #00 #7FFFD4 #F0 #F5F5DC #FFE4C4 #4169E1
> >#8B4513 #FA8072 #F4A460 #2E8B57 #A0522D ];
> >
> >
> ># choose a color!
> >$color_choice1 = rand $#colors;

On Thursday, June 7, 2001 at 3:40 PM, [EMAIL PROTECTED] (Jeff 'japhy' Pinyan) wrote:

> 
> You're never going to select "#A0522D" this way -- you need to use
> rand(@colors), not rand($#colors).  Read the rand() docs -- it returns x
> such that 0 <= x < ARG.
> 
> I would splice() the array after I get the first color from it.
> 
>   $first = splice @colors, rand(@colors), 1;
>   $second = splice @colors, rand(@colors), 1;
> 
> That way, I always get two different colors.  

Thanks Jeff, 
I will have to read up on Splice, 

The way I am using this to generate html where each line is in a different color,

@colors = qw[ #F0F8FF #00 #7FFFD4 #F0 #F5F5DC #FFE4C4 #4169E1 #8B4513 #FA8072 
#F4A460 #2E8B57 #A0522D ];


$color_choice1 = rand ($#colors + 1);  #thanks for pointing this out!

This code is in a cgi that when called appends some text to a file and then exits. 

So now that I think about it, I will need the last $color_choice to be stored between 
cgi calls!

Dave 

**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**



avoiding duplicates

2001-06-14 Thread David Gilden

Greetings, 

a couple of questions here,
---


# Text colors
@colors = qw[
#F0F8FF #00 #7FFFD4 #F0 #F5F5DC #FFE4C4
#00 #FF #8A2BE2 #A52A2A #5F9EA0 #7FFF00
#FF7F50 #DC143C #00 #8B #008B8B #B8860B  
#FA8072 #F4A460 #2E8B57 #A0522D #6A5ACD #00FF7F 
#4682B4 #D2B48C #008080 #FF6347 #EE82EE #00 
#D2691E
];


# choose a color!
# avoid the same color twice in a row!

sub choseColor{
return int (rand ($#colors + 1));
}

# $#colors + 1 --> better written as  int (rand @colors);
# is this ok, using an @array as in a loop to 
# like:  while ($i < @array) {... do something...; $i++} 


# print out some values

while ($i < 1000 ){

$color_choice = &choseColor;

# never happens ?!?

 print "###dup###\n" if ($color_dup == $color_choice);


print "$color_dup  $color_choice\n";

$color_dup = $color_choice;

$i++;
}

# print some html
print qq|some text\n|;

Looking for Web Talent, You found it!
portfolio: www.coraconnection.com/web/
email: [EMAIL PROTECTED]
tel/fax: (860) 231-9988




Slicing and dicing

2001-06-14 Thread David Gilden

Is one style better then the other here?
Thanks,
Dave
-

sub print_table_rows {
my $name = shift;
my $key = shift;
my $date = shift;
print <

$thread{$key}
$name$date

data


--- alt



sub print_table_rows {
my ($name,$key,$date) = @_[0..2]
print <

$thread{$key}
$name$date

data





Sort hash by values

2001-06-14 Thread David Gilden

Hello, 

Stuck here, 

The first sort block works like a charm!

if ($sort_order == 1) {

# sort by name
# $key is really the filename with out the path and '.html'
foreach my $key (sort {lc($a) cmp lc($b)} keys %subjects){
my $name;
  ($name = $key ) =~ s/_(\d+)$//;
  $name =~ tr/_/ /;
 &print_table_rows($key,$name,$subjects{$key}," ");
}
}


However, this one has be stuck, I want to sort  (case insensitive) the values
in the hash  %subjects,  and I need to get keys of the hash as well -- 
the key of the hash has data I need to pass along to my sub,

 elsif  ($sort_order == 2) {

# sort by subject 

foreach my $subject (sort {lc($a) cmp lc($b)} values %subjects){




##
need the key here...
my $name;
($name = $key ) =~ s/_\d+$//;
 $name =~ tr/_/ /;
##

   &print_table_rows($key,$name,$subject," ");

}

Looking for Web Talent, You found it!
portfolio: www.coraconnection.com/web/
email: [EMAIL PROTECTED]
tel/fax: (860) 231-9988




sort by number...

2001-06-15 Thread David Gilden

Good day,

keys look like: Dowda_23241506142001

This is wrong, but not sure how the syntax is,

Where are $a,$b coming from, I thought of a sub, but how do assign $a, $b

foreach my $key  (sort { /_(\d+)$/; $a <=> $b  } (keys %subjects)) {
#  /_(\d+)$/  grabs the number at the end of the string,

what about:

foreach my $key  (sort { s/_(\d+)$/$1/; $a <=> $b  } (keys %subjects)) {

Thanks for your help on this.

Dave



More sorting

2001-06-15 Thread David Gilden

Good afternoon, TGIF!

Sorry to say that lot of this still above my head,
but I am trying, and I am getting better

<http://dowda.rockin.net:31822/cgi/forum_idx.pl?3>
My code has problems, 
first one is  line:   
($hours,$minutes,$seconds,$month,$day,$year) = $key =~ 
/_(\d{2})(\d{2})(\d{2})(\d{1,2})(\d{2})(\d{4})/;
is repeated all over the place, which I believe is not a good thing,

But more to the point is making the sorting correct and the code more concise;

Ignoring the second branch of the code below, the final branch (the else)
does kind sort, it puts the 'dates' in the correct order, but seems to neglect time

each key (which is really a file name, just add .html) is: dave_1132376152001

Is this possible:

$date_time = "$month{$month} $day, $year $hours:$minutes:$seconds";


if ($sort_order == 1) {

# sort by name
# $key is really the filename with out the path and '.html'
foreach my $key (sort {lc($a) cmp lc($b)} keys %subjects){

my ($name,$hours,$minutes,$seconds,$day,$month,$year);

   ($hours,$minutes,$seconds,$month,$day,$year) = $key =~ 
/_(\d{2})(\d{2})(\d{2})(\d{1,2})(\d{2})(\d{4})/;
 $month =~ s/^0//;
 #$date_time will get interpolated twice,  "$month{$month} $day, $year 
$hours:$minutes:$seconds";

   &print_table_rows($key,$subjects{$key},$date_time);

  # &print_table_rows($key,$subjects{$key},"$month{$month} $day, $year 
$hours:$minutes:$seconds");
}
}

 elsif  ($sort_order == 2) {
# does not work at this time
# sort by subject 

# foreach my $subject (sort {lc($a->[1] cmp lc($b->[1]} map {[ $_, $subjects{$_}]}) { 

# $subjects{$subject->[0]}, $subject->[0];

# foreach my $key (sort {lc($a) cmp lc($b)} keys %subjects){
#  my ($name,$hours,$minutes,$seconds,$day,$month,$year);

#   ($hours,$minutes,$seconds,$month,$day,$year) = 
/_(\d{2})(\d{2})(\d{2})(\d{1,2})(\d{2})(\d{4})/;

#   &print_table_rows($_,$subject,"$month{$month} $day, $year 
$hours:$minutes:$seconds");

}


} else {
# sort by date and time

#$sortValue = "$name$hours$minutes$seconds$day$month$year";

foreach my $key  (sort { my($A) = $a =~ /_(\d+)$/; my($B) = $b =~ /_(\d+)$/; $A <=> 
$B; }  
(keys %subjects)) {

my ($hours,$minutes,$seconds,$day,$month,$year);

($hours,$minutes,$seconds,$month,$day,$year) = $key =~ 
/_(\d{2})(\d{2})(\d{2})(\d{1,2})(\d{2})(\d{4})/;
# ($name) = $key =~ /(\w+_?)+_/;
  $month =~ s/^0//; # remove after debug
 &print_table_rows($key,$subjects{$key},"$month{$month} $day, $year 
$hours:$minutes:$seconds");

}
}

print "\n";
print &html_end;

sub print_table_rows {
my ($fileName, $subject, $date) = @_;

($name = $fileName) =~ s/_\d+$//;
$name =~ tr/_/ /;

print <

$subject
$name$date

data
}





--


From: Wagner-David 

Sorry, but as soon as I saw the input coming back I knew it was really
untested.

 Should be sort {lc($a->[1]) cmp lc($b->[1])} and NOT sort {lc($a) cmp
lc($b)}

Wags ;)

-Original Message-

Sent: Thursday, June 14, 2001 13:21
To: 'David Gilden'; [EMAIL PROTECTED]
Subject: RE: Sort hash by values


  Use of keys, map and sort (untested)
foreach my $subject (sort {lc($a) cmp lc($b)} map {[ $_, $subjects{$_}]}
keys %subjects){
   printf "%-40s: %-s\n", $subjects{$subject->[0]}, $subject->[0];
 }



From: Timothy Kimball

my (%idToName);
foreach ( @lines ) {
my ($id,$name) = /^(...)..(.{8})/g;
next if $name eq "xx  ";
$idToName{$id} = $name;
}

Also, instead of prepending the sort key to each line, try making it
the value of a hash, which has the line itself as the key.  Something
like this:

my (%sortKeys);
foreach ( @lines ) {
my $sortKey = ... # do something to create the sort key,
  # using %idToName to map the ID to the name
$sortKeys{$_} = $sortKey;
}

Then create a sub to pass to sort:

sub bySortKey {
$sortKey{$a} cmp $sortKey{$b}
}


Looking for Web Talent, You found it!
portfolio: www.coraconnection.com/web/
email: [EMAIL PROTECTED]
tel/fax: (860) 231-9988




$hash{$_}++

2001-06-18 Thread David Gilden

I am having trouble understanding just what the following does,
and how to you use it:

 $hash{$_}++
 
 i.e. are we increment the value or the key?
 
 I would appreciate any guidance here! 
 
 Thanks,
 
 Dave G.
 
   



RE: Sort hash by values

2001-06-18 Thread David Gilden

Thanks for all who helped with my Perl coding,
I thought some folks here might benefit from me posting the final 
code I used on a current project:

---snip---

if ($sort_order == 1) {

# sort by name (front part of the key)

foreach my $key (sort {lc($a) cmp lc($b)} keys %index){

  &print_table_rows($key);
}
}

 elsif  ($sort_order == 2) {

# sort by subject (values)

foreach my $key (sort { lc($index{$a}) cmp lc($index{$b}) }  keys %index ) {

   &print_table_rows($key);
 }
} 
else {

# sort by date and time (end part of the key)

foreach my $key (sort { my($A) = $a =~ /_(\d+)$/; my($B) = $b =~ /_(\d+)$/; $B <=> $A; 
} (keys %index)) {

 &print_table_rows($key);

}
}


sub print_table_rows {
my ($key) = @_;

# get the date and time
my ($year,$month,$day,$hours,$minutes,$seconds) = $key =~ 
/_(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/;
   
# remove the leading '0' for the hash %month
$month =~ s/^0//;

# get the name
($name = $key) =~ s/_\d+$//;
$name =~ tr/_/ /;

print <

$index{$key}
$name$month{$month} $day, $year $hours:$minutes:$seconds

data
}



**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**



Re: $hash{$_}++

2001-06-18 Thread David Gilden

How about a an example or 2 where you would use this,


$hash{$_}++


Thnx,
Dave,

Looking for Web Talent, You found it!
portfolio: www.coraconnection.com/web/
email: [EMAIL PROTECTED]
tel/fax: (860) 231-9988




Variable scope

2001-06-26 Thread David Gilden

Quick question,

I could not get the following sub to work until 
I had to move  $emailLog inside the sub to get this 
to work on the server. 

What did I miss or not understand?
Thanks
Dave


##  not seen by the sub, 
$emailLog = 'logs/email_log';

# Send E-Mail
  &send_mail;
  
# Append email log
  &addEmail;
 

sub addEmail{
$emailLog = 'logs/email_log';   ##after moving it inside,  now it works

open(EL,"$emailLog") ||  &errorLog( "Read in, Could not find $emailLog, $!");
my @lines = ;
close(EL);

 open(EL,">$emailLog.tmp") ||  &errorLog( "Write file, could not find $emailLog, $!");

 my %seen;

@lines = sort @lines;
 foreach(@lines){
next if /test/; 
$_ =~ s/^\s+(.*)\s+$/\1,/; 
   print EL unless $seen{$_}++;
 }

# print EL "$Config{'email'} $Config{'name'},\n";
 close(EL);

rename("$emailLog", "$emailLog.old");
rename("$emailLog.tmp", "$emailLog");
}

sub errorLog{
open(ER,'>>logs/error_log') || die "could not find error_log, $!";
$errorMssg = shift;
 
print ER "$errorMssg\n";
close(ER);
}

Looking for Web Talent, You found it!
portfolio: www.coraconnection.com/web/
email: [EMAIL PROTECTED]
tel/fax: (860) 231-9988




RE: Variable scoop

2001-06-26 Thread David Gilden

Here's the latest revision, 
I don't know why it was not working earlier 
when emailLog = 'logs/email_log';
was out of the sub block. 
This script is contained in one file, with on 'use' or 'require'
statements.

The next revision I see is to move the regrex up to top of the sub
where the append takes place. Which leads to the following question,
am I to doing to many disk reades/writes, is there more efficient way 
of accomplishing what I have below:   


# Append email log and filter out duplicates  
  &addEmail;
 

sub addEmail{
my $emailLog = 'logs/email_log';

# append new email
open(EL,">>$emailLog") ||  &errorLog( "Read in, Could not find $emailLog, $!");
print EL "$Config{'email'} ($Config{'name'}),\n";
close(EL);

open(EL,"$emailLog") ||  &errorLog( "Read in, Could not find $emailLog, $!");
my @lines = ;
close(EL);

rename("$emailLog","$emailLog.old");

open(EL,">$emailLog.tmp") ||  &errorLog( "Write file, could not find $emailLog, $!");

my %seen;

@lines = sort @lines;
 foreach(@lines){
next if /test/; 
$_ =~ s/^\s+(.*)\s+$/\1,/; 
   print EL unless $seen{$_}++;
 }

close(EL);

rename("$emailLog.tmp", "$emailLog");

}

sub errorLog{
open(ER,'>>logs/error_log') || die "could not find error_log, $!";
$errorMssg = shift;
 
print ER "$errorMssg\n";
close(ER);
}

Looking for Web Talent, You found it!
portfolio: www.coraconnection.com/web/
email: [EMAIL PROTECTED]
tel/fax: (860) 231-9988




removing white space

2001-06-26 Thread David Gilden

Is the following regrex the correct way to remove leading or trailing white space
from a string?

$data = "[EMAIL PROTECTED] (mike smith)"

$data =~ s/(^\s+)|(\s+$)//g;

or would it be more efficient to it thus:

# two passes
$data =~ s/^\s+)//;
$data =~ s/\s+$)//;

Final comment when I am reading from a loop:


open(EL,"$emailLog") ||  &errorLog( "Read in, Could not find $emailLog, $!");
my @lines = ;

 foreach(@lines){
next if /test/; 
$_ =~ s/^\s+(.*)\s+$/\1,/; 

 other code

Do I need to escape the '@' as my data will be of format:
[EMAIL PROTECTED] (name) 


Thanks
Dave



Format & Sprintf

2001-07-02 Thread David Gilden

Hello, 
The following is based on the first example in Programming Perl,
and have a question about some of the syntax 
(and or why it was doen this way)

$grades{$student} .= $grade . " ";

Why not $grades{$student} = $grade;
Why the concatenation  and the extra space?

$average =  sprintf ("%3d", ($total / $scores));

I want to allow for values like 2.5, 11.5, 2, 22 ...

Finally am I using the Format correctly (assigning $~ )

Thanks
Dave


---Begin--
#!/usr/bin/perl 

open (GRADES, "grades.txt") || die "Can't open grades $!\n";

while  ($line=){
($student,$grade)= split(" ",$line);
$grades{$student} .= $grade . " ";
}


local $~ =  grades_header;
write;


local $~ =  grades_format;

foreach $student (sort keys %grades){
$total = 0;

@grades = split (" ",$grades{$student});
foreach $grade (@grades){
$total+= $grade;  
$scores++;
}

$average =  sprintf ("%4d", ($total / $scores));

write;
# print "$student: $grades{$student}\tAverage: $average\n";
}



format grades_header =
Student Score Average
-
.


format grades_format =
@<<  @<<@
$student,$grades{$student},$average
.


Looking for Web Talent, You found it!
portfolio: www.coraconnection.com/web/
email: [EMAIL PROTECTED]
tel/fax: (860) 231-9988




modules & path to perl

2001-07-05 Thread David Gilden

How do I list what my ISP has on there server in terms of Modules?
And what is the command (at the command line) to tell me what version 
The server has on it / and or the path to perl.
Thanks

Dave G.


Looking for Web Talent, You found it!
portfolio: www.coraconnection.com/web/
email: [EMAIL PROTECTED]
tel/fax: (860) 231-9988




upper-casing the first char & hashs of hashs

2001-07-16 Thread David Gilden

Hello,


The following uppercase'S the whole string, when all I want is the first letter.


&uppercase($bears->{"rec$n"}{name}), uc($bears->{"rec$n"}{type})  # works but caps the 
whole string
} 

u\$bears->{"rec$n"}{type} # does not work...


sub uppercase{
($s) = @_;
\u$s = scalar $s;  ## does not work
return $s;
}


another version:

sub uppercase{
($s) = @_;

return uc($s);  # works but caps the whole string
}


lastly, in this hash of hashs..

$bears = {

rec1 => {
type =>  'sweater',
name =>  'sweaterie',
color => 'golden brown',
food =>  'mixed beries',
},


one of many... more recs heres


}


is $ (scalar) $bears, correct? should not be %bears 


How would I get the lenght of $bears if I wanted to a:

for (0 ..  # true lenght of $bears )

and as it is, I can not do the following, that you would use will normal hashs

foreach my $key (sort keys %bears ) {


Thanks & good day,

Dave G.
---

**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**

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




Cmd Line args

2001-07-16 Thread David Gilden

if I invoke this script as follows:

perl bears.pl

ARGV[0] never seems to be false even though there are no args..

What did I do wrong here?
Thanks
Dave


#!/usr/bin/perl -w

$sort_order = $ARGV[0] || $usage; # grab command line args

$usage ="
# Type a number after the script name to choose the type of sorting:
# 1 = sort by type
# 2 = sort by name
# 3 = sort by color
# 4 = sort by food
#
# Example:
# perl bears.pl 1
# sorts bears by type";





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




Dynamic Data structures

2001-07-18 Thread David Gilden


Take this Data structure  (which is an anonymous hash)

#
# $bears = {
#
#
#   rec0 => {
#   name =>  'sweaterie',
#   type =>  'sweater',
#   color => 'golden brown',
#   food =>  'mixed berries',   
#   },   # ect
#   };


I am trying to build  from a flat file dynamically:

# the text file looks like:
# name1|type|color|food
# name2|type|color|food

open (DATA, "bear_data.txt") || die "Could not access file $!";

local $/;# undefine the builtin var $/
$tmp = ;
@tmp =  split (/\n/,$tmp); 


my $n = 0;
my $bears = {};

foreach $line (@tmp){
my ($name,$type,$color,$food); # is this correct?
($name,$type,$color,$food) = split (/|/, $line);

$bears->{"rec$n"} = {};
# problem here #
$bears->{"rec$n"}{
name  =>  $name;  
type  =>  $type; 
color =>  $color;
food  =>  $food;

};
$n++;
}

Please point out what I missed or if there is a better way of accomplishing this,
Thanks,
Dave


Looking for Web Talent, You found it!
portfolio: www.coraconnection.com/web/
email: [EMAIL PROTECTED]
tel/fax: (860) 231-9988


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




PERL / UNIX File manipulation

2001-08-17 Thread David Gilden

Hi,

How would you approach the following:

in a directory (on a UNIX box)

file-a
file-b
file-c
file-d

This what I like have after I run a script or a mysterious UNIX command:


1-file-a
2-file-b
3-file-c
4-file-d


*** OR ***

new-file-a
new-file-b
new-file-c
new-file-d


Possible script untested,  mycomputer% = cmd line prompt 

mycomputer% perl -ews  foreach $files (<./*>) {rename($file,"new-$file");}


Am I on the right track?

Thanks

Dave

PS: Is there a mailing list or any good web resources for learning UNIX?


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




incrementing inside a s///

2003-02-11 Thread David Gilden
How do get  $i do increment inside the substitution below?
Thanks
Dave

#!/usr/bin/perl -w

my $i = 0;

while(<>)
{
chomp;
s/name=\"order/name=\"order$i++/;
print "$_\n";

}



==
 Cora Connection: Your West African Music Source
  Resources, Recordings, Instruments & More!
    
==

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




removing elements from an array

2003-03-05 Thread David Gilden
Hi,
I would like to remove elements from an array that are eq to string '0'
The following does not work, can someone shed some light on the proper 
way to do this.
Thanks!
Dave G.

#!/usr/bin/perl -w

@bag_quantity = ( '0', 1, '0', '0', '0', '0', '0', '0', '0' ); 


for (@bag_quantity){
shift if $_ eq '0';
}


print "@bag_quantity\n";


==
 Cora Connection: Your West African Music Source
  Resources, Recordings, Instruments & More!
    
==

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



getting the number of characters

2003-03-12 Thread David Gilden
Hello,

I am looking for the $num to treated as a string and get the number of characters,
in this case I am look for 3 to be returned.

Later I want to use this number to pad a string with zeros
Thanks!
Dave 

#!/usr/bin/perl -w

$num =123;

($match) = ($num =~ m/(\d)/);


print "$match \n";  # should print 3 

__END__

==
 Cora Connection: Your West African Music Source
  Resources, Recordings, Instruments & More!
    
==

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



PERL OSX --- reading a local text file

2003-03-18 Thread David Gilden
Hi List,

Any reason why this dies?   error: " could not open data.txt No such file or directory"
-->The file and script reside in the same directory!!! 

#!/usr/bin/perl -w

use strict;

my $data = "data.txt";

open (FH,$data)  || die  "could not open $data $!";

local $/; 
my $tmp = ;
my @tmp =  split (/\n/,$tmp); 

print @tmp;


__END__

Thanks

Dave

( kora musician / audiophile / web master @ cora connection /  Ft. Worth, TX, USA)

==
 Cora Connection: Your West African Music Source
  Resources, Recordings, Instruments & More!
    
==

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



Re: PERL OSX --- reading a local text file

2003-03-18 Thread David Gilden
OK, one problem is solved, which was the path to the data file.

I know there is a simple way to read in a file like the following:

apple,2
banana,4
kiwi,1


and produce a HASH. The code below works I get the feeling there is a more
compact way to accomplish this.

---

#!/usr/bin/perl -w

use strict;
my %prices;

my $data = "/Users/dowda/Desktop/tmp test/test.txt";

open (FH,$data)  || die  "could not open $data $!";

local $/; 

my $tmp = ;
my @tmp =  split (/\n/,$tmp); 

close FH;

for (@tmp) {
my ($k,$v)  = split /,/;
$prices{$k} =$v; 
}

for my $key (keys %prices){

print "$key = $prices{$key}\n";

}


Thanks for any pointers here,

Dave


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



RE: PERL OSX - reading a local text file with white space

2003-03-18 Thread David Gilden
Thanks Dave for the while  loop,  

I need to protect against blank lines and spurious white space that could show
up in the data. No doubt the file will edited in Note pad (on widows 98), and I
want to put the data in to the hash in a clean format.  and since the this is
basically a price list names of the product (the keys for the hash) might have
spaces: new model , 20 I do want them quoted: "new model"

also of note  Data::Dumper;  is built in to OSX! Joy!

Thanks for any refinement on the code below.

Dave 
( kora musician / audiophile / web master @ cora connection /  Ft. Worth, TX, USA)
 --


#!/usr/bin/perl -w
use Data::Dumper; 
use strict;

my %prices;

my $data = "/Users/dowda/Desktop/tmp test/test.txt";

open (FH,$data)  || die  "could not open $data $!";

while(  ) {
s/^\s*(.+)\s*$/$1/; # clean the line
next if m/^\W+/;  # blank lines

my( $k, $v ) = split /,/;

$k =~ s/^\s*(.+)\s*$/$1/; # clean the hash key
$v =~ s/^\s*(.+)\s*$/$1/; # clean the value

$prices{qq($k)}  = $v; 
}

close FH;

for my $key (keys %prices) {
print "$key = $prices{$key}\n";
}


print "\n\n" , Dumper \%prices;

__DATA__

 model-old  ,22
model new,  34  

model new with crome, 48
last years model,10  


model 2a , 100

==
 Cora Connection: Your West African Music Source
  Resources, Recordings, Instruments & More!
    
==

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



Re: PERL OSX --- reading a local text file

2003-03-18 Thread David Gilden
Thanks for all of the help, 

Here is what I am currently going with:


my $prices = '../paul_s/data/prices.txt';

open (FH,$prices) || die  "could not open $prices $!";

while(  ) {
s/^\s*(.+)\s*$/$1/;  # clean the front of each line
next if /^\s*$/;  #  skip blank lines
my ( $k, $v ) = split /\s*,\s*/;  #  cool use of split
$v =~ s/^\s*(.+?)\s*$/$1/; # clean the value
$prices{qq($k)}  = $v;
}

close FH;  



  "John W. Krahn" <[EMAIL PROTECTED]>  suggests,
 

 my %prices = do { local $/;  =~ /[^\n,]+/g };
 
Nice and compact, but how does one remove spurious white space?
Just a thought :)

Good night  Local time (1:12 AM CST) 

Dave 
( kora musician / audiophile / web master @ cora connection /  Ft. Worth, TX, USA)


 

 
==
 Cora Connection: Your West African Music Source
  Resources, Recordings, Instruments & More!
    
==

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



Re: PERL OSX --- reading a local text file

2003-03-18 Thread David Gilden

> But what directory were you in when you ran the program?  That's a lot
> more important than where the program is.


/Users/dowda/Desktop/tmp test/read-prices.pl

OSX Jaguar, G4 


Randal L. Schwartz <[EMAIL PROTECTED]>,

> The following message is a courtesy copy of an article
> that has been posted to perl.beginners as well.
> 
> >>>>> "David" == David Gilden <[EMAIL PROTECTED]> writes:
> 
> David> Hi List,
> David> Any reason why this dies?   error: " could not open data.txt No such file or 
> directory"
> 
> --> The file and script reside in the same directory!!! 
==
 Cora Connection: Your West African Music Source
  Resources, Recordings, Instruments & More!
   <http://www.coraconnection.com/> 
==

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



POSIX 'strftime'

2003-04-06 Thread David Gilden
Hello,

How can get the date formatted to include the day of the week (plus one)
'04-07-2003-1013'

Thanks,
Dave
( kora musician / audiophile / web master @ cora connection /  Ft. Worth, TX, USA)

The following misses the day of week!!

#!/usr/bin/perl -w

use POSIX 'strftime';

print strftime('%m-%W-%Y-%I%M',localtime),"\n";


==
 Cora Connection: Your West African Music Source
  Resources, Recordings, Instruments & More!
    
==

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



check against two different passwords.

2002-12-23 Thread David Gilden
Hello,

in the following 

# Goal:  check against two different passwords.

#!/usr/bin/perl 
my $qs = 'c';
my $secret_word  = 'a';
my $secret_word_guest  = 'b';

if ($qs !~ /$secret_word_guest|$secret_word/) {
print "fail\n"; 
} else { 
print "go, ok\n";
}



another version:

#!/usr/bin/perl 

my $qs = "a";
my $secret_word  = 'a';
my $secret_word_guest  = 'b';

if ($qs ne ($secret_word_guest || $secret_word)) {
print "fail\n"; 
} else { print "go, ok\n";}


the original works fine! 
if ($qs ne  $secret_word) {
print "fail\n"; 
exit;
} 


What should happen is that if $secret_word OR $secret_word_guest does not Match $qs 
Then it should print 'Fail'.

The above behaves correctly, but when I try to bring a second test,
it fails

I can not seem to get this to do what i want!
Can any one show me by example what is wrong.

Dave
-
OSX, Jaguar PERL 5.6

Cora Connection: Your West African Music Source
Resources, Recordings, Instruments & More!
 


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




OSX Perl

2002-12-25 Thread David Gilden
Here's a quick question:

#!/usr/bin/perl -w

use strict;

print "Hello, Perl!\n";
# return "Hello, Perl!\n";  
# tried this as well


bash2.05a  % perl Hello\ World.pl > test-hello.txt
bash2.05a  %  bbedit test-hello.txt  

 test-hello.txt  is empty, what did I miss?
 
 Thanks!
 
 Dave


Cora Connection: Your West African Music Source
Resources, Recordings, Instruments & More!
 


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




basic syntax s/..../..../

2004-03-18 Thread David Gilden
Greetings,


I want to do the result of a substitution to $newname,
but do not have it correct.

#!/usr/bin/perl

# rename from the Terminal OSX

$orig = "tina-o1.jpg";

($orig = $newname)  =~ s/tina/quest/ig;

print $newname;
 
 __END__
 
 Then I would like to run from the command line the following:
 (OSX flie re-namer)
 
 my @files = <>;

@files = sort @files;
 foreach(@files){
my $newname;
 ( $newname = $_)  =~ s/PIC1000/NEWNAME/; 
rename($_, "$newname");

}


Any suggestions would be appreciated,

Thanks,

Dave 

==
 Cora Connection: Your West African Music Source
  Resources, Recordings, Instruments & More!
    
==

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




running PERL from CMD line OSX

2004-03-18 Thread David Gilden
Trying to run a perl script in OSX shell, and It is not working, what am I missing?

here is what I am typing:
> perl -e  test.pl

#!/usr/bin/perl
#test.pl
# rename from the Terminal OSX
print "hello";

__END__




Dave,

(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, TX, USA)

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




Random Image script has a problem

2004-04-20 Thread David Gilden
Greetings,

In the following script (see below) it should be pulling images from the directory:
rand_fp_imgs

The debug info looks good, but when I run the script from the URL below it pulls images
that I have sitting at the root level. 
Does anyone have any idea why this might be?
Thanks,

Dave
(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, TX, USA)

http://www.coraconnection.com/index3.html



(the script is on a UNIX server with PERL 5.04)
---


#!/usr/bin/perl
# script: random_pict2.pl  Thank you Lincoln Stein! 

use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);

$PICTURE_PATH = path_translated();
$PICTURE_URL = path_info();
$PICTURE_URL =~ m#(.+/?)+(/\w+)#;

chdir "/www/coraconnection/$2" or die "Couldn't chdir to pictures directory: $!";

@pictures = <*.{jpg,gif}>;
$lucky_one = $pictures[rand(@pictures)];

die "Failed to pick a picture" unless $lucky_one;
print redirect("$2/$lucky_one");


__END__

print header('text/plain');
print $PICTURE_PATH, "\n"; 
print "Rand Imgs: , ", $lucky_one;

print "\$2: ", $2, "\n"; 



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




Search --> Replace on Unix

2001-09-06 Thread David Gilden

Hello,

What is the best way do to search and replace operation on a whole directory on a UNIX 
box?

Sed?
Awk?
Perl?

I know this is wrong, what I want to do is a search and replace,
find '../forum_idx.pl' and replace with '../forum_idx.pl'

I have to hit a whole directory with this change, (and it would be a valuable skill to 
know how to this)

Here is my starting point:

perl -e 'foreach $file (glob("*")) {grep '../forum_idx.pl' 
'../cgi-bin/forum_idx.pl');}'

Thanks for your help,
Dave

**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**

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




Perl one-liner problem

2001-09-07 Thread David Gilden


Any idea why this aint working?

perl -wpi.org -e s@/cgi-bin/forum_idx.pl@/fakecgi/fakeforum_idx.pl@


Thanks

Dave

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




Data Structures

2001-10-03 Thread David Gilden

Hi,
 
 I am having bit of a struggle getting the following code to work:
 
Here are my two questions, first is there a cleaner way of dealing the 'radio button 
group' 
next is the building of a hash of hashs, and  I can not seem to sort desired criteria.
As a PERL neophyte all help is appreciated,
Thx,
Dave 
-- 
 
#!/usr/bin/perl -w

my ($sort_by,$new_row ,$row_count, $first_name, $last_name, $birthday, $gender, 
$height, $weight);

$new_row ="\n";

require "dbi-lib.pl";
require "libcgi.pl";

&initialize_dbi;
&run_statement("select * from friends;");

## Get sort order via post method
&parse_input;

$sort_by = $FORM_DATA{sort_order} || 0;


%sort_order =(
0 => 'Nothing',
1 => 'Hash',
2 => 'First Name',
3 => 'Last Name',
4 => 'Birthday',
5 => 'Sex',
6 => 'Height',
7 => 'Weight',
);


&print_header;  # html header

print <
Sort Database by $sort_order{$sort_by}:

FORM

# Radio Button Group
print qq/ Nothing\n";

print qq/ Hash\n";

print qq/ First Name\n";

print qq/ Last Name\n";

print qq/ Birthday\n";

print qq/ Sex\n";

print qq/ Height\n";

print qq/ Weight\n";
# End Radio Button Group


print <
Here is the list of your friends and their stats.
HEADER

$row_count = 0;
%database = ();


print <

First NameLast 
NameBirthdaySexHeightWeight

TABLE


while (($first_name, $last_name, $birthday, $gender, $height, $weight) = 
$sth->fetchrow) {

# Build Hash of Hashs
$database{$row_count++} = {
first_name => $first_name,
last_name => $last_name,
birthday => $birthday,
gender => $gender,
height => $height,
weight => $weight,
};   

if ($sort_by == 0){
print "$new_row\n";
print "$first_name$last_name$birthday
$gender$height$weight\n";
print "\n";
}
} 


if ($sort_by == 1){
# Sort by Hash
foreach my $key (keys %database ) {
 &print_tableData($key);
}
}  

elsif ($sort_by == 2){
# sort by first name,  does not work at this point
foreach my $key (sort 

{ $a = $database{$key}{first_name};  $b = $database{$key}{first_name};
lc($a) cmp lc($b)}
 keys %database){

print "$database{$key}{first_name}"; 

#&print_tableData($key);
# &print_table_rows($key);
}
} 


**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**

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




problem with 'use strict'

2001-10-26 Thread David Gilden

Hi,

As an exercise I have two files, a library file and a main
file. If I try to 'use strict' my script won't run.

What do I have to change so that things will work correctly with 
out clobbering any of my $vars?
Thanks and have a good weekend,

Dave G.

-
# library file dbi-lib.pl

my $user_name = "**"; 
my $user_password = "";
my $sql_server = "sql.**.com";


sub initialize_dbi{
   use DBI;
   $drh = DBI->install_driver( 'mysql' );
   $dbh = DBI->connect("DBI:mysql:$user_name:$sql_server", $user_name, $user_password);
   die "Cannot connect: $DBI::errstr\n" unless $dbh;
}

sub run_statement{
$stmt = "$_[0]";
$sth = $dbh->prepare($stmt);
$sth->execute;
}


1;
# end dbi-lib.pl

--


#!/usr/bin/perl -w

# Main PERL file

use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);

require "dbi-lib.pl";
# use strict;

my ($d,$s,$time,$week_day, @data);


# mySQL Stuff follows

&initialize_dbi;

$s= "select date_format(current_date, '%W'), date_format(current_date, '%M %e, %Y');";
&run_statement($s);
my ($day,$date_string) = $sth->fetchrow;


# This $sth is in the library (or is it package?) dbi-lib.pl,  correct?


$s = "select dayofweek(date_sub(current_date, interval 15 day)), current_time, 
date_format(current_date, '%b %e, %Y %a');"; 


&run_statement($s);
($week_day,$time,$current_date) = $sth->fetchrow_array;

more stuff.

**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**

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




Re: problem with 'use strict'

2001-10-26 Thread David Gilden



On Friday, October 26, 2001 at 5:38 PM, [EMAIL PROTECTED] (Brett W. McCoy) 
wrote:
> 
> Sorry, I meant that to say "And it runs without 'use strict'?

Yes the code works fine, untill I try to use strict

Dave

**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**

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




Perl Filter problem

2001-10-27 Thread David Gilden

Can anyone please tell me what is wrong here,
Thnx

Dave


cold:~/cgi$ perl -pie  's/;"\);/"\);/ ' *
Can't open perl script "s/;"\);/"\);/ ": No such file or directory


What I want to do is change all files in the current directory.

Find lines that contain: 

;");

And change them to:

");




**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**

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




syntax @{ $records{$_} }

2001-11-09 Thread David Gilden

Could some explain what this is?  
  
 @{ $records{$_} }
 
 is it a Array?
 
 thanks!
 
 DAve

**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**

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




rename((1,2) and file permissions

2001-11-12 Thread David Gilden

Hello,

what is causing the renamed file to take permissions of 755
instead of 644? -- am I doing this correctly -- there will be only one user
of the script .. do I need 'file lock' here?

Thanks to Bob Showalter for the formatting info on 'strftime'

"man 3c strftime" --> http://www.cs.princeton.edu/cgi-bin/man2html?strftime:3C


cold:~/cgi$ ls -l gi*
-rw-r--r--   1 dowdawebusers  351 Nov  9 11:11 gigs.dat
-rwxr-xr-x   1 dowdawebusers  394 Nov  8 15:46 gigs.dat.old*


One final thought what can I do prevent one from going to straight to the following,
user normally would not go to this script, or am I being paranoid?
thx,
Dave

--

#!/usr/bin/perl 

use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
use POSIX 'strftime';
use strict;
my (@gigs,$line,$gig_num);
my $data_file = 'gigs.dat';



# Create a 'last updated time stamp'
push (@gigs,strftime('%A, %B %1d, %Y %I:%M %p',localtime));

# how many records...
my $rows = param('rows');
$gig_num =0;

#get all records from the web page

while  ($gig_num < $rows ){
my $gig = param("date$gig_num") . '|' . param("time$gig_num") . '|' . 
param("event$gig_num") . '|' . param("place$gig_num") . '|' . param("city$gig_num") . 
"\n";
push (@gigs,$gig)  unless param("$gig_num");
$gig_num++;
}


rename($data_file, "$data_file.old");

# open for writing 
open(OUT,">$data_file") or die "Can't write to $data_file $!\n";

foreach my $line (@gigs){
#chomp $line;
print OUT $line;

}  


if (param('action') eq 'Add to Schedule' ){

$line = "\n" . param('date') . '|' . param('time') . '|' . param('event') . '|' . 
param('place') . '|' . param('city');
print OUT $line;
}


close (OUT);
print  redirect("edit_schedule.pl");
exit;

__END__


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




Grep question

2008-06-05 Thread David Gilden

Could someone please help me the syntax here


my $Comments = param('(Comments');
&BADemail if ($Comments =~ /[virtualthirst.com|napavalleycf.org]/ig);

This should go to  &BADemail if $Comments contains either string, regardless 
else is contained in the $Comments.


Thanks,

Dave

(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)

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




Extra Commas in output!

2007-12-06 Thread David Gilden

This is adding to many ',' in my output and do not see why!

Could some one could point where I have gone wrong.
Thanks,

Dave Gilden 
(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)



data in: (one row of many)
35, 'Mike Hoffman', '', '2565 Davis Blvd. #177', '', 'Ft. Worth', '75252', 
'Texas', 'United States', '972267-2820', '[EMAIL PROTECTED]', 2, 'Mike 
Hoffman', '', '2565 Davis Blvd. #177', '', 'Ft.', '75252', 'Texas', 'United 
States', 2, 'Richard Hoffman', '', '6565 Davis Blvd. #177', '', 'Dallas', 
'75252', 'Texas', 'United States', 2, 'Authorize.net AIM', 'Visa', 'Richard 
Hoffman', '5446731215700551', '0807', '2007-07-03 15:12:30', '2007-07-02 
19:35:44', 3, NULL, 'USD', 1.00, NULL

output #not correct  # note the end of this string
(35, 'Mike Hoffman', '', '2565 Davis Blvd. #177', '', 'Ft. worth', '75252', 
'Texas', 'United States', '972267-2820', '[EMAIL PROTECTED]', 2, 'Mike 
Hoffman', '', '2565 Davis Blvd. #177', '', 'Ft. worth', '75252', 'Texas', 
'United States', 2, 'Mike Hoffman', '', '2565 Davis Blvd. #177', '', 'Ft. 
worth', '75252', 'Texas', 'United States', 2, 'Authorize.net AIM', 'Visa', 
'Mike Hoffman', '5446731215700551', '0809', '2007-07-08 21:30:10', '2007-07-05 
16:01:48', 3, NULL, 'USD', 1.00, 
NULL,'','','','','','','','','','','','','','','','','','','','','','','','','','','','','','',,,'',,'','','','',,'','','','','','')

# note the end of this string
# why am I getting the extra [,] s

-

#!/usr/bin/perl -w

$fileIn = "orders-raw.txt" ;
$CleanCSV = "clean_orders_insert.txt";



open (FH, $fileIn) or &errorMsg("Problem reading $fileIn $!\n");

while(){
push(@record, $_); 
} 
close FH;



sub errorMsg{
$_ = shift;
print "Error: $_\n";
}


open(CSV_OUT,">$CleanCSV") or &errorMsg( "Write out,  Could not write file: 
$CleanCSV, $!");
 
foreach (@record){
chomp;  
#Split each line
my @tmpArray  = split(/","/,$_); 
my @tmpArray  = split(/","/,$_); 

$customers_id = $tmpArray[0] || "''";
$customers_name = $tmpArray[1] || "''";
$customers_company = $tmpArray[2] || "''";
$customers_street_address = $tmpArray[3] || "''";
$customers_suburb = $tmpArray[4] || "''";
$customers_city = $tmpArray[5] || "''";
$customers_postcode = $tmpArray[6] || "''";
$customers_state = $tmpArray[7] || "''";
$customers_country = $tmpArray[8] || "''";
$customers_telephone = $tmpArray[9] || "''";
$customers_email_address = $tmpArray[10] || "''";
$customers_address_format_id = $tmpArray[11] || "''";
$delivery_name = $tmpArray[12] || "''";
$delivery_company = $tmpArray[13] || "''";
$delivery_street_address = $tmpArray[14] || "''";
$delivery_suburb = $tmpArray[15] || "''";
$delivery_city = $tmpArray[16] || "''";
$delivery_postcode = $tmpArray[17] || "''";
$delivery_state = $tmpArray[18] || "''";
$delivery_country = $tmpArray[19] || "''";
$delivery_address_format_id = $tmpArray[20] || "''";
$billing_name = $tmpArray[21] || "''";
$billing_company = $tmpArray[22] || "''";
$billing_street_address = $tmpArray[23] || "''";
$billing_suburb = $tmpArray[24] || "''";
$billing_city = $tmpArray[25] || "''";
$billing_postcode = $tmpArray[26] || "''";
$billing_state = $tmpArray[27] || "''";
$billing_country = $tmpArray[28] || "''";
$billing_address_format_id = $tmpArray[29] || "''";
$payment_method = $tmpArray[30] || "''";
$cc_type = $tmpArray[31] || "''";
$cc_owner = $tmpArray[32] || "''";
$cc_number = $tmpArray[33] || "''";
$cc_expires = $tmpArray[34] || "''";
$last_modified = $tmpArray[35] || "''";
$date_purchased = $tmpArray[36] || "''";
$orders_status = $tmpArray[37] || "''";
$orders_date_finished = $tmpArray[38] || "''";
$currency = $tmpArray[39] || "''";
$currency_value = $tmpArray[40] || "''";
$shipping_method = $tmpArray[41] || "''"; #shipping_module
# Write TMP file 
print CSV_OUT 
"($customers_id,$customers_name,$customers_company,$customers_street_address,$customers_suburb,$customers_city,$customers_postcode,$customers_state,$customers_country,$customers_telephone,$customers_email_address,$customers_address_format_id,$delivery_name,$delivery_company,$delivery_street_address,$delivery_suburb,$delivery_city,$delivery_postcode,$delivery_state,$delivery_country,$delivery_address_format_id,$billing_name,$billing_company,$billing_street_address,$billing_suburb,$billing_city,$billing_postcode,$billing_state,$billing_country,$billing_address_format_id,$payment_method,$payment_module_code,$shipping_module,$shipping_method,$coupon_code,$cc_type,$cc_owner,$cc_number,$cc_expires,$cc_cvv,$last_modified,$date_purchased,$orders_status,$orders_date_finished,$currency,$currency_value,$order_total,$order_tax,$paypal_ipn_id,$ip_address)\n";

}

close(CSV_OUT);


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




DB Conversion script issues

2007-12-09 Thread David Gilden
Greetings,

Could some please tell me why this writing the data like think it should.


Input data:
4,'Daniel Niederer','','Wberweg 3A','','Hersiwil','

Sample of the output:  (first 4 'columns' )
4,'Daniel Niederer','','Wberweg 3A','','Hersiwil','4558',

I would think it should print to disk the following ::

 0 : 4,'name: Daniel Niederer','','Wberweg 3A','','Hersiwil','4558',
 
 $customers_id= $count++ . " : ". $tmpArray[0] || "''";
$customers_name=  "name : " . $tmpArray[1] || ;


But it does not!!  <[EMAIL PROTECTED]@#>

If anyone can set me straight on how to make my script behave
that would be most helpful.

Thx!

Dave Gilden
(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)  

---

#!/usr/bin/perl -w

$fileIn = "orders-raw.txt" ;
$CleanCSV = "clean_orders_insert.txt";



open (FH, $fileIn) or &errorMsg("Problem reading $fileIn $!\n");

while(){
push(@record, $_); 
} 
close FH;



sub errorMsg{
$_ = shift;
print "Error: $_\n";
}

$count =0;

open(CSV_OUT,">$CleanCSV") or &errorMsg( "Write out,  Could not write file: 
$CleanCSV, $!");
 
foreach (@record){
chomp;  
#Split each line
my @tmpArray  = split(/","/,$_); 

$customers_id= $count++ . " : ". $tmpArray[0] || "''";
$customers_name=  "name : " . $tmpArray[1] || "''";
$customers_company= $count++ . " : ". $tmpArray[2] || "''";
$customers_street_address= $count++ . " : ". $tmpArray[3] || "''";
$customers_suburb= $count++ . " : ". $tmpArray[4] || "''";
$customers_city= $count++ . " : ". $tmpArray[5] || "''";
$customers_postcode= $count++ . " : ". $tmpArray[6] || "''";
$customers_state= $count++ . " : ". $tmpArray[7] || "''";
$customers_country= $count++ . " : ". $tmpArray[8] || "''";
$customers_telephone= $count++ . " : ". $tmpArray[9] || "''";
$customers_email_address= $count++ . " : ". $tmpArray[10] || "''";
$customers_address_format_id= $count++ . " : ". $tmpArray[11] || "''";
$delivery_name= $count++ . " : ". $tmpArray[12] || "''";
$delivery_company= $count++ . " : ". $tmpArray[13] || "''";
$delivery_street_address= $count++ . " : ". $tmpArray[14] || "''";
$delivery_suburb= $count++ . " : ". $tmpArray[15] || "''";
$delivery_city= $count++ . " : ". $tmpArray[16] || "''";
$delivery_postcode= $count++ . " : ". $tmpArray[17] || "''";
$delivery_state= $count++ . " : ". $tmpArray[18] || "''";
$delivery_country= $count++ . " : ". $tmpArray[19] || "''";
$delivery_address_format_id= $count++ . " : ". $tmpArray[20] || "''";
$billing_name= $count++ . " : ". $tmpArray[21] || "''";
$billing_company= $count++ . " : ". $tmpArray[22] || "''";
$billing_street_address= $count++ . " : ". $tmpArray[23] || "''";
$billing_suburb= $count++ . " : ". $tmpArray[24] || "''";
$billing_city= $count++ . " : ". $tmpArray[25] || "''";
$billing_postcode= $count++ . " : ". $tmpArray[26] || "''";
$billing_state= $count++ . " : ". $tmpArray[27] || "''";
$billing_country= $count++ . " : ". $tmpArray[28] || "''";
$billing_address_format_id= $count++ . " : ". $tmpArray[29] || "''";
$payment_method= $count++ . " : ". $tmpArray[30] || "''";
$cc_type= $count++ . " : ". $tmpArray[32] || "''";
$cc_owner= $count++ . " : ". $tmpArray[33] || "''";
$cc_number= $count++ . " : ". $tmpArray[35] || "''";
$cc_expires= $count++ . " : ". $tmpArray[34] || "''";
$orders_status= $count++ . " : ". $tmpArray[37] || "''";
$orders_date_finished= $count++ . " : ". $tmpArray[38] || "''";
$currency= $count++ . " : ". $tmpArray[39] || "''";
$currency_value= $count++ . " : ". $tmpArray[40] || "''";
$shipping_module= $count++ . " : ". $tmpArray[41] || "''";
$last_modified= $count++ . " : ". $tmpArray[35] || "''";
$date_purchased= $count++ . " : ". $tmpArray[36] || "''";
$orders_status = $count++ . " : ". "'*'";
$orders_date_finished = $count++ . " : ". "''";
$currency = $count++ . " : ". "''";
$currency_value = $count++ . " : ". "''";
$order_total = $count++ . " : ". "''";
$order_tax = $count++ . " : ". "''";
$paypal_ipn_id = $count++ . " : ". "''";
$ip_address = $count++ . " : "."'*'";

# Write TMP file 
print CSV_OUT 
"($customers_id,$customers_name,$customers_company,$customers_street_address,$customers_suburb,$customers_city,$customers_postcode,$customers_state,$customers_country,$customers_telephone,$customers_email_address,$customers_address_format_id,$delivery_name,$delivery_company,$delivery_street_address,$delivery_suburb,$delivery_city,$delivery_postcode,$delivery_state,$delivery_country,$delivery_address_format_id,$billing_name,$billing_company,$billing_street_address,$billing_suburb,$billing_city,$billing_postcode,$billing_state,$billing_country,$billing_address_format_id,$payment_method,$payment_module_code,$shipping_method,$shipping_module_code,$coupon_code,$cc_type,$cc_owner,$cc_number,$cc_expires,$cc_cvv,$last_modified,$date_purchased,$orders_status,$orders_date_finished,$currency,$currency_value,$order_total,$order_tax,$paypal_ipn_id,$ip_address)\n";

}

close(CSV_OUT);


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

substr question

2006-06-25 Thread David Gilden
Hello,

I am not sure I have the syntax quite right here, any suggestions would be 
welcome.


$line = "Friday, June 23, 2006 12:30 PM" ;

$last_updated = substr($line, 0, (length($line) -9)); # remove the time part of 
time stamp
# the above line is throwing an error   
  
Thx,
Dave Gilden

(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)

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




Matching a sub pattern and processing results

2006-09-25 Thread David Gilden
Greetings,

I am having a little trouble understanding matching and getting the sub pattern 
saved to a Var. so that I can do a munge. I want to take the line returns and 
change them into 
pipe characters '|'   
All data records start with a date i.e. 01/01/2006  
But there are fields in between that are one multiple lines. Sample data is 
below the script.

Here's what I have so far 

#!/usr/bin/perl -w


open(FI,"test.txt") || die "Read in, Could not find File, $!";
my @files = ;
close(FI);

for (@files){

chomp($_);

$_ =~m|(\d+/\d+/\d+)(?s)(.+?)\d+/\d+/\d+|;

$2 =~tr/\n/|/;

print "$1$2\n";

# save out modified result...
}

Given this data:

09/01/2006|03:29AM Password for qsocordovam reset by Self Reset utility 
Username: qsocordovam 
ClientNumber: 77927 
IP address: 24.248.1.241  
09/01/2006|07:53AM Failed reset attempt 
Username: tmpcollic03 
ClientNumber: 110330 
IP address: 152.121.16.7 
Failed challenge question(s)  
09/01/2006|07:55AM Failed reset attempt 
Username: tmpcollic03 
ClientNumber: 110330 
IP address: 152.121.16.7 
Failed challenge question(s)  
09/01/2006|08:03AM Failed reset attempt 

Desired result: 
09/01/2006|03:29AM Password for qsocordovam reset by Self Reset 
utility|Username: qsocordovam|ClientNumber: 77927|IP address: 24.248.1.241  
#Next record starts with a date of format : 09/01/2006


Thanks for any input on my output :)

Dave Gilden  
(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)




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




RE: Matching a sub pattern and processing results

2006-09-25 Thread David Gilden
Dear Perl Gurus,

Still struggling here...
The problem is the data in the middle of the match is on multiple lines.
Please reply directly and CC the list.
Thanks,
D.G.
(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)
>>
I am having a little trouble understanding matching and getting the sub pattern 
saved to a Var. so that I can do a munge. I want to take the line returns and 
change them into 
pipe characters '|'   
All data records start with a date i.e. 01/01/2006  
But there are fields in between that are one multiple lines. Sample data is 
below the script.

Here's what I have so far  Revised sill not working!

#!/usr/bin/perl -w


open(FI,"test.txt") || die "Read in, Could not find File, $!";
my @files = ;
close(FI);

for (@files){

chomp($_);

#!/usr/bin/perl -w

open(FI,"test.txt") || die "Read in, Could not find File, $!";
my @files = ;
close(FI);

for (@files){

chomp($_);

@match = ($_ =~ m!(\d+\/\d+\/\d+)(.+?)(?=\d+/\d+/\d+)!);

$match[1]=~tr/\n/|/;

print "$match[0]$match[1]\n";
print "#"x10, "#"; 
#rename($old,$_);
}


# save out modified result...
}

Given this data:

09/01/2006|03:29AM Password for qsocordovam reset by Self Reset utility 
Username: qsocordovam 
ClientNumber: 77927 
IP address: 24.248.1.241  
09/01/2006|07:53AM Failed reset attempt 
Username: tmpcollic03 
ClientNumber: 110330 
IP address: 152.121.16.7 
Failed challenge question(s)  
09/01/2006|07:55AM Failed reset attempt 
Username: tmpcollic03 
ClientNumber: 110330 
IP address: 152.121.16.7 
Failed challenge question(s)  
09/01/2006|08:03AM Failed reset attempt 

Desired result: 
09/01/2006|03:29AM Password for qsocordovam reset by Self Reset 
utility|Username: qsocordovam|ClientNumber: 77927|IP address: 24.248.1.241  
#Next record starts with a date of format : 09/01/2006


__END__



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




Case statements

2005-04-12 Thread David Gilden
Hello,

I am trying to create case statement, and I am not sure I am on the right track,
any comments?
Thanks,
Dave Gilden

SWITCH: {

## yacht form 
if ($whichForm eq "123") { 
$subject = "123 Form";
$recipient = "[EMAIL PROTECTED]";
$cc = "[EMAIL PROTECTED]";

LAST SWITCH;
}

## regatta form
if ($whichForm eq "456"){ 
$subject = "456 Form" ;
$recipient = "[EMAIL PROTECTED]";
$cc = "[EMAIL PROTECTED]";
LAST SWITCH;
}

# many more etc
}

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




RE: Switch -- confused

2005-04-13 Thread David Gilden
Greetings,

Thanks for the help so far,

I am added switch...   but not sure that I have syntax correct
Maybe this is best written as if else logic

and or:
my $action = $q->param( "action" );

SWITCH ($action) {

if  (/Upload/) {
last SWITCH;
};

etc...



--- what I have now
use CGI qw/:standard/;
use CGI;
use Fcntl qw( :DEFAULT :flock );
use CGI::Carp qw(fatalsToBrowser);
use strict;
use switch; 


my $action = $q->param( "action" );

SWITCH: {

if  ($action =~ /Upload/) {
last SWITCH;
};

if  ($action =~ /Update/) {
print redirect("./import_clean_csv.php");
exit;
last SWITCH;
};

if  ($action =~ /Clean/) {
my @filesToRemove;  
 
chdir UPLOAD_DIR or die "Couldn't chdir to afm_data directory: $!";

#my @filesToRemove  =  map  {$_ =~ /^(\w[\w.-]*)/} <*>;

opendir(DR,"./");
@filesToRemove  =  grep  {$_ =~ /^(\w[\w.-]*)/} readdir DR;
closedir DR;


print $HTML_HEADER;
print '';


foreach my $fr (@filesToRemove) {

print  "Deleted $fr\n";
unlink($fr)  or die "Couldn't Delete $fr $!";
}



print  




RE: Preventing CPU spikes / was switch confusion

2005-04-13 Thread David Gilden
Dear Perl Gurus,

I have some  problems that I think are a result of how my Switch statement is 
written. 
This script is invoked via a web browser to upload a file, and do a few other 
things. 
However it appears that the user system / network, or my script is stalling. So
the user clicks the button  a second and a third time before the script has
finished. The system admin has made me aware that this script is maxing out the
CPU usage of server. He is not happy


I thought have surrounding a portion of the code and putting in an if 
block ...

if (!$state) {

do lots of stuff related to file upload...
}

$state could be read and written to and store a 0 for ready to do something, 
or a 1 for, 'busy now, don't brother me'..


Another issue to improve the performance of the script
was to move stuff inside a switch block, but I am not sure how this would 
impact scope : 

SWITCH: {

if  ($action =~ /Upload/) {
  

use Fcntl qw( :DEFAULT :flock );
use constant MAX_FILE_SIZE  => 2 * 1_048_576;   # Limit each upload to 2 MB
use constant MAX_DIR_SIZE   => 10 * 1_048_576; # Limit total uploads to 10 MB
use constant MAX_OPEN_TRIES => 100;
  last SWITCH;
};

--

if  ($action =~ /AnotherCmd/) {
### is order backwards on these next two lines?
exit;
last SWITCH; 
}


Could some comment on using Switch or Case statements vers If {} else blocks

Thanks...
Dave Gilden
PS: I am not sure of syntax that I should be using for Switch I have seen 
several variants 
as I have read documentation today


--- what I have now

use CGI qw/:standard/;
use CGI;
use Fcntl qw( :DEFAULT :flock );
use CGI::Carp qw(fatalsToBrowser);
use strict;
use switch; 


my $action = $q->param( "action" );

SWITCH: {

if  ($action =~ /Upload/) {
last SWITCH;
};

if  ($action =~ /Update/) {
print redirect("./import_clean_csv.php");
exit;
last SWITCH;

};


if  ($action =~ /Clean/) {
my @filesToRemove;  
 
chdir UPLOAD_DIR or die "Couldn't chdir to _data directory: $!";

opendir(DR,"./");
@filesToRemove  =  grep  {$_ =~ /^(\w[\w.-]*)/} readdir DR;
closedir DR;


print $HTML_HEADER;
print '';


foreach my $fr (@filesToRemove) {

print  "Deleted $fr\n";
unlink($fr)  or die "Couldn't Delete $fr $!";
}



print  




last question on the switch statement ....

2005-04-17 Thread David Gilden
Dear fellow PERL coders...,

What is the "&& do" part of the code doing, i.e. I am looking to understand the 
syntax,
the example was found in perl beginners archive, from some else's post...
Thanks,

Dave

(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)


foreach (@qString)
{
  if ($_ =~ m/open/)
  {
SWITCH:
{
   $_ eq 'Unkopen' && do { next; last SWITCH; };
   $_ eq 'QCSSopen' && do { $rep = "Quest Central for SQL Server"; last 
SWITCH; };
   $_ eq 'QCSSDGopen' && do { $rep = "QCSS Data Generator"; last SWITCH; };
   $_ eq 'IWopen' && do { $rep = "I/Watch"; last SWITCH; };

##etc##




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




inline GREP filter...

2005-05-17 Thread David Gilden
Hello,

In the following I was thinking it would just print out: "Hello"

#!/usr/bin/perl -w

$S = "Hello, Perl!";

($R) = grep {/\w+/} $S;

print "$R\n";


I am trying for some sort of inline filtering so I can do the following:

#!/usr/bin/perl -w 
use CGI qw/:standard/;
 use strict;

my $page =  grep {/\w{1,50}/i} param('page');
# only allow $page to contain 1-50 of [a-z0-9_]
snip

Is this even possible?


Dave Gilden
(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)

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




grep help request

2005-10-28 Thread David Gilden
Hello,

I am stuck with this issue.
How do get each substring (the names in this case) and then upper case them.
This does not work just yet

Possible data:
mike smith
john h. hamilton 
g. bush
hendric

etc..


#!/usr/bin/perl 

$SendersName = " dave middlename gilden ";
$SendersName =~ s/\s*(.+)\s*/$1/g;
($SendersName) = $SendersName =~ m/([\w\.-]{1,24}( [\w\.-]{1,24}){0,4})/;
$SendersName =~ s/.+ (.+)? (.+){1,3}/\u$1 \u$2 \u$3/g;
print "$SendersName\n";


Thanks!

Dave Gilden -- Ft. Worth

Island Journey music video now online!



Cora Connection: Your West African Music Source
  Resources, Recordings, Instruments & More!
   




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




Re: grep help request -- data fields max size

2005-10-28 Thread David Gilden
Thanks Jay,

For your recommendation,  is there a way I can limit the size, 
something like:   [\w\.-]{1,50} 
or should I do that I bring in the data for first time?
Have a great weekend!
Dave Ft. Worth, Tx
[ www.coraconnection.com ]

> It's going to be a whole lot easier, and probably just as fast, to use
> split() and join() to break the strings apart and operate on each part
> of the name separately. Also, once you've split the names, Perl has a
> built-in ucfirst() function--see perldoc -f ucfirst--so you don't even
> really need to write your own regex.
> 
> $SendersName = join(' ', map {ucfirst($_)} split / /, $SendersName);
> 
> Names are more complicated tha you think, though. What will you do
> with strings like 'old mcdonald', 'old macdonald', and 'c.j. price'?

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




grep mystery / What happened to my @ sign ?

2005-11-22 Thread David Gilden
Greetings,

#!/usr/bin/perl 

$SendersEmail ="[EMAIL PROTECTED]";

($SendersEmail) = $SendersEmail  =~ m/([EMAIL PROTECTED],60})/;

print "$SendersEmail\n";


prints: someone.lastname.net
I was expecting this: [EMAIL PROTECTED]
What happened to my @ sign ?


Thanks!

Dave Gilden


Visit my schedule page for up to the minute performance info:



==
 Cora Connection: Your West African Music Source
  Resources, Recordings, Instruments & More!
    
==

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




use constant

2005-12-19 Thread David Gilden
Greetings,

I looked for documentation on 'use constant'  but it has eluded it me.

my $path =  `pwd`;
use constant UPLOAD_DIR => "/home/sites/site123/web/private/_data/";


I want to get the Document Root at runtime and concatenate like such...


my $path =  `pwd`;
use constant UPLOAD_DIR => "$path/_data/";

But this fails.

is this construct from the PERL 4 days?
constant UPLOAD_DIR

Any guidance would be greatly appreciated.

Thx,

Dave Gilden 
(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)

Cool music.From Guineé comes this CD of kora fusion, electronica  
[ Audition Mp3s at the URL below ]







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




getting a number out of a string....

2005-12-28 Thread David Gilden
Greetings,

How does one just get the number part out of a string?

The script below just prints 1.

#!/usr/bin/perl 

@str = ('Gambia001.tiff','Gambia0021.tiff','Gambia031.tiff','Gambia035.tiff') ;

foreach $str (@str) {
$num = ($str =~ /\d+/);
print  "$str : $num\n";
}


Thanks!
Dave Gilden
(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)

Endorsing Artist for the Moog Music:


==
 Cora Connection: Your West African Music Source
  Resources, Recordings, Instruments & More!
    
==

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




Re: getting a number out of a string....

2005-12-29 Thread David Gilden
Chris,

Thanks and Happy New Year.
Dave
(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)

> > How does one just get the number part out of a string?
> > 
> > The script below just prints 1.
> 
> Right. All it's doing is reporting a successful, true, match.
> 
> You need to fix where the parentheses are being used:
>  
> > foreach $str (@str) {
> > $num = ($str =~ /\d+/);
> > print  "$str : $num\n";
> > }
> 
> foreach (@str) {
> ( $num = $_ ) =~ /\d+/;
> print "$_ : $num\n";
> }
> 
> That should work better, and also avoids the confusing and unnecessary 
> $str temporary scalar that looks too much like the $str[] array. Also, 
> it's usefully indented, because Readability Matters.
> 
> 

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




Use of uninitialized value Error

2005-12-30 Thread David Gilden
Hello,

In the Script below the line:  last if ($num >= 35)
is giving me this error: Use of uninitialized value in int 

How do I avoid this error?


my @files contains: Gambia001.tiff through Gambia100.tiff 

#!/usr/bin/perl -w

my @files =<*>;
$tmp= 1;


for (@files){
my $old = $_;
$_ =~ /(\d+)/;
$num = int($1);
#$_ =~s/Gambia_Pa_Bobo_kuliyo_\d+/Gambia_Pa_Bobo_kuliyo_$tmp/i;
print "$num\n";
#$tmp++;
last if ($num >= 35); 
# rename($old,$_);
}

Thx,
Dave GIlden
(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)

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




Checking a list for a value

2006-02-11 Thread David Gilden
I would like to loop through 'all' acceptable values in an array (my white list)
then assign a pass or fail value.

In the following code does not accomplish this, it needs to go through the 
entire list 
before assigning a value.


#!/usr/bin/perl 

$valToTest = "ac";

@myGoodList = ("10_rater","36_600","ac","cr914","ec12","fairwind");
$testOk = -1;

foreach my $cat  (@myGoodList){
if ($cat =~ /$valToTest/) {
$testOk = 1; 
next;
} else {
$testOk = -1;
# value not in list
last;
}
}

print "$testOk\n";


I am going to guess that the foreach is not the right way to address this 
problem.

Thanks for any insight into this problem,

Dave Gilden

(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)

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




populating a Hash

2006-02-18 Thread David Gilden
Good morning,

I would like to populate a hash from a csv text file, then test for the 
existence  of a value in the hash.
If not found return an error message and exit.


ithe text file will have the format of:
# whitelist created 2/18/06 or some other comment on the first line
name1,nick1
---
name25,nick25
---

my $approvedUser = pram('approvedUser'); # cgi.pm

my $whitelist = './'whitelist.txt;

my %hash

open(EL,"$whitelist") ||  &errorMessage( "Read in, Could not find $whitelist, 
$!");
my @lines = ;
close(EL);

foreach(@lines){
next if /#/;
my($key,$val)= split (@lines,",");
   $hash{$key} = $val;
 }
close(EL);

if (!defined $approvedUser =~ %hash){
&errorMessage( "your not an authorized user")
}


errorMessage(message){
shift;
print "$_\n";
exit;
}


How close am I to having a working script, I have guessed at some of syntax 
here, and am not familiar 
with using 'defined'.

Thanks for any guidance.

Regards from Cow Town,
David Gilden
(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA) 

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




if(!defined construct

2006-03-01 Thread David Gilden
I can not seem to get the following script to return the correct response.
Could someone point where I am off.
Thx,
Dave Gilden
(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)


#!/usr/bin/perl 

use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
use POSIX 'strftime';
use strict;

my $approvedUser ='10_xyz';


my $whitelist = "amya_whitelist.txt";

## White List .:
## nick, mailRouting
# "10xxx","10_xyz"
# "dave","dave_office"
#  etc.
#

my %hash;

open EL, $whitelist or &errorMessage( "$!: Read in Error: Could not find 
$whitelist" );

my @lines = ;
close(EL);

foreach(@lines){
chomp;
next if /^#/;
my ($key,$val) = split ',';
$hash{$key} = $val;
}

# debug
# foreach my $k  (keys %hash){
# print "$hash{$k}\n";
# }


if(!defined $hash{$approvedUser} ) {
 &errorMessage( "your not an authorized user")
 } else {
  print  "$approvedUser is cool\n";
}


sub errorMessage {
 my $msg = shift || '';
 print "$msg\n";
 exit;
}


__END__

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




trimming white space in data

2006-03-04 Thread David Gilden
I am trying to trim white space, at the front and end of a string.
The following is not working

#!/usr/bin/perl 

$name = " Dave Gilden";
$name =~ s/^\s*([\w .-]{1,120})\s*$/$1/;
print "|$name|";


# This gets the front but not the back!
$name = " Dave Gilden";
($name) = ($name =~ m/^\s*([\w .-]{1,120})/);
print "|$name|";


I know there should be a simple way to this via grep

Thanks in advance for any direction on this problem,

Dave Gilden

(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)

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