KevinADC 192 Practically a Posting Shark

Some input data would also be nice.

KevinADC 192 Practically a Posting Shark

open(IN, "/path/to/file");
open(OUT,">",'path/to/outfile');
print OUT reverse <IN>;
close(IN);
close(OUT);

The only problem is that if there is not a newline at the end of the last line of the IN file, the reversed OUT file will have the first and second lines appended together.

KevinADC 192 Practically a Posting Shark

Maybe it will work if you remove "strict"

KevinADC 192 Practically a Posting Shark

When you use print, you should quote strings.

print reverse <>, "history.txt > history_rev.txt\n";

On the other hand, if you are expecting perl to know those are input and output files you must not have been awake in perl class. ;)

KevinADC 192 Practically a Posting Shark

You need to install DBI and DBD::mysql.

Open the activestate/activeperl folder that was created on the hard drive when you install activeperl and open the documentation. Read the PPM directions which is what you use to install and manage modules with activeperl.

Then see this thread on another forum:

http://bytes.com/forum/thread840298-install+dbd%3A%3Amysql.html

KevinADC 192 Practically a Posting Shark

And the same person on tek-tips, and perlguru, and daniweb, and ??

KevinADC 192 Practically a Posting Shark

You have this posted on too many forums for me to want to help you. You should also try and do your own school work.

KevinADC 192 Practically a Posting Shark

You could try using a reference to a function.

sub some_function {
   print "foo";
}

my $some_function = \&some_function;

You can pass $some_function like any other scalar, but you need to use the arrow operator to run the function.

$some_function->()

Assuming you pass references to functions to your sub rotuine:

sub function_runner {
   my @exit_functions = @_;
   my $counter = 1;
   foreach my $function (@exit_functions) {
      print "Performing exit function $counter:\n";
      $counter++;
      $function->();
   }
   print "\nAll exit functions completed.\n";
}
klactose commented: His post was very helpful +1
KevinADC 192 Practically a Posting Shark

to quote myself:

post some sample input data and desired output data.

KevinADC 192 Practically a Posting Shark

post some sample input data and desired output data.

If you want to continue with awk you should take this discussion to an awk forum.

Perl has very similar command line syntax to awk and could be done as a command line/one-liner if you really wanted to do that. one-liners are good for very targeted tasks, but not so good when you have more complex programming problems.

Your problem is right about in the middle of being a simple task and a more complicated one better suited to a script.

KevinADC 192 Practically a Posting Shark

I'm pretty sure its matlab, of which I know nothing. So I suggest you find a matlab forum or mailing list.

KevinADC 192 Practically a Posting Shark

the code you posted is not perl, I am not sure after reading your post if you know that or not.

PoovenM commented: Thank you for the assistance :) +2
KevinADC 192 Practically a Posting Shark

The character class you have will match all of the characters in the list of characters you posted. Is there a problem?

KevinADC 192 Practically a Posting Shark

basic script with no formatting of output:

use warnings;
use strict;
use File::Find;

use File::Find;
    find( {wanted=> \&wanted, no_chdir => 1}, 'C:/Program Files/Player' );
    sub wanted { print $_,"\n"; }

See File::Find (a core module) for details.

raul15791 commented: good! +1
KevinADC 192 Practically a Posting Shark

I think he wants to use File::Find to browse all files in all sub folders.

KevinADC 192 Practically a Posting Shark

What you want is an IDE, a good free one is Perl Express

http://www.perl-express.com/

I think its only for Windows operating systems. Install activeperl from www.activestate.com then use the IDE to run write and run your perl scripts.

I believe you can also use it as just an editor if you don't want to install perl.

Some free ebooks:

http://www.perl.org/books/library.html

Most still relevant if a little out of date in reagards to the newest version of perl: 5.10.

raul15791 commented: useful +1
KevinADC 192 Practically a Posting Shark

Post your code.

Ditto. Post your code.

KevinADC 192 Practically a Posting Shark

Use a hash of arrays:

my %HoA = ();
for (1..4) {
   push @{$HoA{$_}},$value;
}
KevinADC 192 Practically a Posting Shark

There are a lot of array handling modules that do this kind of work already. But you could use a hash of arrays and give the keys any value you wanted that would associate it with the respective array.

You could also use the grep() function because arrays can be processed super fast, and you can compare many arrays for various conditions very rapidly with grep.

KevinADC 192 Practically a Posting Shark

the warnings pragma:

use warnings;

is better than the -w switch. It allows you to do this:

no warnings;

within a block of code that might cause warnings but you want the perl script to ignore them. Once you turn on the -w switch there is no way to turn it off. And it affects all modules that your program might use as well. The warnings pragma does not, it is only scoped to the program that loads it.

KevinADC 192 Practically a Posting Shark

You have this question also on DEVSHED where it has a number of replies.

KevinADC 192 Practically a Posting Shark

this creates an array, not a hash:

($temp1, $temp2) = split (/,/, $_);
$words[$temp1]= $temp2

actually unless $temp1 is a number it should not create anything.

This would create a hash:

($temp1, $temp2) = split (/,/, $_);
$words{$temp1}= $temp2

Your code used [] (array indices) instead of {} (hash keys).

KevinADC 192 Practically a Posting Shark

If you want to define the IO files in the script look into the open() function or using @ARGV to pass in parameters to use as files.

Please note, there is no urgent help here. Your question is no more important or less important then anyone elses. It will be answered by anyone that reads it when they read it and if they want to answer it.

KevinADC 192 Practically a Posting Shark

Good point Bob but it's interesting to note it does work for me as-is. ActiveState Perl 5.8.8 which does include perls 'B' module.

KevinADC 192 Practically a Posting Shark

hmmm...not sure what the problem is, your code works fine for me. Are you sure the B.pm file you posted is the file your main script is accessing?

KevinADC 192 Practically a Posting Shark
KevinADC 192 Practically a Posting Shark

I really don't know, sorry. Find a forum or newsgroup that specializes in bioperl and you may find someone that has experienced this problem and can help.

Good luck.

KevinADC 192 Practically a Posting Shark

You are using math, there are several places in the script that use math operators:

==
<=

maybe more. I do not know if that is where you problems are occuring. Erros/Warnings generally have a line number associated with them that can help pin point where a error/warning is occuring. Run your program and see if a line number and a program/module name gets displayed along with the message.

KevinADC 192 Practically a Posting Shark

ahh, that will be a good thing to remember for future reference.

KevinADC 192 Practically a Posting Shark

just for sanity sake I would add in some error handling for any sytem functions, like these:

if (!(-d "$path/"))
	{
		mkdir("$path/", 0777) or some error handling here;
	}
	if(-f "$path/$filename")
	{
		unlink("$path/$filename") or some error handling here;
	}

make sure everything else is working so you can for sure track it down to the read() function being the real source of the problem, or at least the point where the problem occurs. Why the filehandle is closed is a mystery at this point. It worked, nothing got changed, now it does not work.... thats possible but leads to more fundamental questions, like is the server/computer going bad? Was new software installed or ugraded? It does not sound like a perl problem though.

KevinADC 192 Practically a Posting Shark

Another piece of important information is that while both the program that failed and then worked and this current program are programs to upload files, they are completely different versions of code that work differently. They don't even share any custom libraries in common.

Almost sounds like someone is hitting the "stop" button on the browser while uploading a file. Maybe someone else will have an idea to help you, but I am baffled by the problem you have described.

KevinADC 192 Practically a Posting Shark

Not exactly like that but that is the general idea.

Pseudo code:

here print all html haedrs and any stuff that gets printed before opening the file.

open file

while (<>){
here print only the stuff that gets generated from reading the file
}

close file

print the ending html stuff here

KevinADC 192 Practically a Posting Shark

You have to generate your output while the file is opened and you are processing the data line by line. You generate the output after the file is closed, so naturally you will only ever get the last line of the file. A generic example of one way to do it:

print "<table>";
while (<INPUT_FROM_FILE>) {
  # do some stuff here with your data like split() and calculating averages, etc.
  print "<tr><td>$yourdata</td></tr>\n";
}
print "</table>";
KevinADC 192 Practically a Posting Shark

Okay, I've changed that. But I really need to figure out how to do the things I initially asked about...

OK, a generic example:

my $new_var = param('foo');
open (FH, "file.txt");
while(<FH>) {
    my ($foo,$bar) = split(':::');
    my $average = ($foo+$new_var)/2;
    print $average;
}
KevinADC 192 Practically a Posting Shark

Don't bother with heredocs, they are just too perl 4, use an appropriate quote operator like qq:

#generate page
print qq{
<html>
<head><title>Current Cowboys Statistics</title></head>
<body bgcolor="#CCCCCC">
<font size="3">Week $weekNum :<br />Played at: $whereAt<br /></font>
</body></html>
};
KevinADC 192 Practically a Posting Shark

Not only is the code not complete, it has a number of errors. Fix the errors before continuing.

KevinADC 192 Practically a Posting Shark

You need to clarify your question and post any code you have written so far.

KevinADC 192 Practically a Posting Shark

In this case they are for all practical purposes equal:

use Benchmark qw/timethese cmpthese/;
my $string = "    Mary had a little lamb.   ";

my  $results = timethese(200000, 
        {
            'First' => sub {$string =~ s/^\s*//;$string =~ s/\s*$//;},
            'Second' => sub {$string =~ s/^\s*(.+)\s*$/$1/;}
        },
    );
cmpthese( $results ) ;

output:

Benchmark: timing 200000 iterations of First, Second...
     First:  3 wallclock secs ( 2.36 usr +  0.00 sys =  2.36 CPU) @ 84745.76/s (n=200000)
    Second:  2 wallclock secs ( 2.58 usr +  0.00 sys =  2.58 CPU) @ 77519.38/s (n=200000)
          Rate Second  First
Second 77519/s     --    -9%
First  84746/s     9%     --

I would still recommend the two regexp solution as a force of good habit though.

KevinADC 192 Practically a Posting Shark

Maybe try a Benchmark test

KevinADC 192 Practically a Posting Shark

more efficient suggestion:

my $string = '  Mary had a little lamb.  ';
$string =~ s/^\s+//; #remove leading spaces
$string =~ s/\s+$//; #remove trailing spaces
print $string;

use the Email::Valid module to check email addresses

http://search.cpan.org/~rjbs/Email-Valid-0.176/lib/Email/Valid.pm

KevinADC 192 Practically a Posting Shark

it's probably those smilies in the code..... I don't think perl handles smilies too well...... ;)

KevinADC 192 Practically a Posting Shark

untested but should work

use CGI;
my $query = CGI->new;
my %form_results = $query->Vars;
my $file_string = join ('|',map {$form_results{$_}} sort keys %form_results);
print $file_string;

read the CI module documentation. I know it is long and some parts are a bit hard to follow, but the part about importing all the params as a list or hash or array is easy to understand.

KevinADC 192 Practically a Posting Shark

This is the terrible code I refer to:

if ( $ENV{'CONTENT_LENGTH'} > 0 )
{
# ~~~~~~~~~~~~~~~~~~~~~~ GETTING FORM INFO FOR $file_string ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# get form info from POST method
read(STDIN, $text, $ENV{'CONTENT_LENGTH'});
my @value_pairs = split (/&/,$text);
my %form_results = ();
foreach $pair (@value_pairs) {
($key, $value) = split (/=/,$pair);
$value =~ tr/+/ /;
$value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;
$form_results{$key} = $value; # store the key in the results hash
}

You have loaded the CGI module and created a CGI object ($query)

use CGI;

$query = new CGI;

That is what you shoud use to get all the form data, like you do in some parts of the code:

$query->param('bill_to')
KevinADC 192 Practically a Posting Shark

why are you mixing that terrible form parsing code in with CGI anyway? Use the CGI module to get all the form data, don't mix it with that insecure code you are using. Also, when the script reads the data from STDIN:

read(STDIN, $text, $ENV{'CONTENT_LENGTH'});

it empties the buffer, so any subsequent attemptsto read the same data will fail. That may explain your situation, but i did not take a close look at your code.

KevinADC 192 Practically a Posting Shark

Something along these lines should work.

#!/usr/bin/perl

use CGI;
use CGI::Carp qw/fatalsToBrowser/;

my $query = CGI->new;

# Output the HTTP header
print $query->header( );

my $firstname = $query->param("firstname");
my $surname   = $query->param("surname");
my $attend    = $query->param("attend");
my $guests    = $query->param("guests");
my $barbie    = $query->param("barbie");
my $comments  = $query->param("comments");
my $email     = $query->param("email");

my $message = "This is the message if the box is not checked.";
my $thanks  = "Sorry you could not attend."; 
if ($attend) {
   $message = "This is the message if the box is checked.";
   $thanks  = "Thanks for taking the time to fill in the form $firstname.";
}
	
open ( MAIL, "| /usr/lib/sendmail -t" );
print MAIL "From: $email\n";
print MAIL "To: whoever\@mydomain.com\n";
print MAIL "Subject: \n\n";
print MAIL "This data was submitted through mydomain.com\n\n";
print MAIL "$input$ENV{HTTP_USER_AGENT}\n";
print MAIL "$input$ENV{SERVER_NAME}\n";
print MAIL "Received from IPinput$ENV{REMOTE_ADDR}\n\n\n";

print MAIL "firstname\ = $firstname\n";
print MAIL "surname\ = $surname\n";
print MAIL "attend\ = $attend\n";
print MAIL "guests\ = $guests\n";
print MAIL "barbie\ = $barbie\n";
print MAIL "comments\ = $comments\n";
print MAIL "email\ = $email\n\n";

print MAIL "\n.\n";
close ( MAIL );

open ( MAIL, "| /usr/lib/sendmail -t" );
print MAIL "From: someone\@mydomain.com\n";
print MAIL "To: $email\n";
print MAIL "Bcc: someoneelse\@theirdomain.com\n";
print MAIL "Subject: hello\n\n\n";

print MAIL "$message\n\n\n";

print MAIL "\n.\n";
close ( MAIL );

print qq~
<html>
<head>
<style type="text/css">
body {
margin: 0;
padding: 10;
background-color: #000;
background-image: url(../images/cp.gif);
background-repeat: repeat-x y;
}
hr {
width: 100%;
height: 2px;
color: #FFCC00;
}
</style>
</head>
<p align="left">
<img border="0" …
KevinADC 192 Practically a Posting Shark

You are using a module:

use CGI;

all you have to do is check for $attend

if ($attend) {
   the box was checked
   do what you want here
}
else {
   the box was not checked
   do what you want here
}
KevinADC 192 Practically a Posting Shark

It will depend on how your current perl script is coded. Does it use the CGI module?

KevinADC 192 Practically a Posting Shark

I don't understand what you are asking. Post your perl code.

Are you trying to use the open() function to read a file on another server? That will not work.

KevinADC 192 Practically a Posting Shark

You can certainly use the open() command to read a file, any file, as long as your script has permission to open the file. We will assume it does.

There are perl modules for reading CSV files too:

http://search.cpan.org/~hmbrand/Text-CSV_XS-0.31/CSV_XS.pm

This gets into the "you need to install the module" discussion though. But if you can tackle the installation problem the above module works well.

You may very well be able to use MySQL but you need to ask on the MySQL forum.

KevinADC 192 Practically a Posting Shark

http://search.cpan.org/~miyagawa/Email-Find-0.10/lib/Email/Find.pm

You should remove that personal information from your post.