RE: CGI.pm Question
Here's a function I wrote to make this eaiser for myself... Might be usefull, might not. It depends on you having a hash of data you want to dump into a cgi table. sub HashToTable { my $hashRef = shift; my $orderRef = shift; my $table_contents; if($orderRef) { foreach my $key (@$orderRef) { my $value = $hashRef->{$key}; $table_contents .= Tr( td({-valign => 'top'}, b($key)) . td((ref $value eq 'HASH')?(HashToTable($value)):($value)) ); } } else { while (my ($key, $value) = each %$hashRef) { $table_contents .= Tr( td({-valign => 'top'}, b($key)) . td((ref $value eq 'HASH')?(HashToTable($value)):($value)) ); } } return table({-align=>'center', -border=>2, -bgcolor=>'FEFFE'}, $table_contents); } I call this in many cases. Here's one example used in a form: $html .= start_form(); $html .= HashToTable({Name=> textfield(-name=>'NAME'), Type=> textfield(-name=>'TYPE'), Username=>textfield(-name=>'USERNAME'), Password=>textfield(-name=>'PASSWORD'), Server=>textfield(-name=>'SERVER'), Description=>textarea(-name=>'DESCRIPTION'), }, ['Name', 'Type', 'Username', 'Password', 'Server', 'Description']); Nice thing is that it's a recursive function, so if you have a hash where some of the values are other hashes, this will resolve those out into nested tables. The ordering array ref that is the second parameter is optional. Since you can't assume ordering on a hash. I too would like suggestions on this approach if possible! Bruce W. Lowther OpenAuto Lead Micron Technology, Inc. Boise, Idaho [EMAIL PROTECTED] -Original Message- From: Andrea Holstein [mailto:[EMAIL PROTECTED]] Sent: Saturday, November 10, 2001 3:44 PM To: [EMAIL PROTECTED] Subject: Re: CGI.pm Question Jess Balint wrote: > > Hello all, I was wonder if there is a way to do this with less `$query->`'s. > And yes, I know the table's not perfect. Any input would be appreciated. > Thanks. > > ~Jess > > print $query->start_form, > $query->start_table({-border=>undef}), > $query->Tr({-align=>CENTER,-valign=>CENTER}), > $query->td(["Username: "]), > ... If you want to use OO-way still, there's a funny trick to short your source-code: for ($query) { print $_->startform, $_->start_table({-border => undef}), $_->Tr({-align=>CENTER,-valign=>CENTER}), $_->td(["Username: "]), ... } A second way (not so funny :-( ) is to use run time code evaluation: my @queries = qw/ start_form, start_table({-border=>undef}), Tr({-align=>CENTER,-valign=>CENTER}), td(["Username:\ "]), ... /; eval "print " . join(",", map( {'$query->' . $_}, @queries )) . ';'; Best Wishes, Andrea -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Reading an Outlook "PST" file?
.PST files are those written out by Macrosloth Lookout. I'm guessing they are streamed out COM representations. Bruce W. Lowther Demotivational quote for the day: "(Don't worry if the concepts of variables and functions are not familiar; we'll introduce these concepts as we go along.)" - Cross Platform Perl OpenAuto Lead Micron Technology, Inc. Boise, Idaho [EMAIL PROTECTED] -Original Message- From: Jos I. Boumans [mailto:[EMAIL PROTECTED]] Sent: Friday, July 06, 2001 2:45 PM To: Wine, Michael; [EMAIL PROTECTED] Subject: Re: Reading an Outlook "PST" file? forgive the ignorance but what is an PST file? on a general note: as long as it's ascii in some way or the other, there should be no reason why perl couldnt read it (binary would be a tad more complicated) hth Jos - Original Message - From: "Wine, Michael" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, July 06, 2001 9:23 PM Subject: Reading an Outlook "PST" file? > I need to write a script that will read an Outlook "PST" file (WIN32) so > that I can write each mail message out to a flat file. I have to believe > that this is a simple thing! Can anyone help? > > Thanks in Advance! >
RE: Editor
cperl is a major mode in gnu/X emacs. It provides colorization, and is syntax aware (well, as close as you can be to syntax aware with perl.) for Graphical debugging, I use ptkdb. It's available from cpan. Once it's installed, you can launch a debug session with the following command: perl -d:ptkdb MyPerlScript.pl Bruce W. Lowther Demotivational Quote for the day: "(Don't worry if the concepts of variables and functions are not familiar; we'll introduce these concepts as we go along.)" - Cross Platform Perl OpenAuto Lead Micron Technology, Inc. Boise, Idaho [EMAIL PROTECTED] -Original Message- From: Matija Papec [mailto:[EMAIL PROTECTED]] Sent: Friday, July 06, 2001 6:49 AM To: [EMAIL PROTECTED] Subject: Re: Editor "Aigner-Torres, Mario" <[EMAIL PROTECTED]> wrote: >Hi Bill, > >my choice is gnuemacs Does it support script debugging? I'm looking for nice *nix editor /debugger with breakpoints, step execution, etc. Have you tried PerlComposer? >with cperl! What is cperl? -- Matija
RE: populating an array with unique integers.
Just a different spin on this one would be to create an array containing sequential numbers, then shuffling them. This meets your criteria that they be unique. However it adds an unspecified condition that all numbers in a range are represented. A good shuffle algorithm (fisher-yates shuffle) for perl located in the perl cookbook: 4.17 pg 121. -Original Message- From: Scott Taylor [mailto:[EMAIL PROTECTED]] Sent: Tuesday, June 19, 2001 10:51 AM To: [EMAIL PROTECTED] Subject: populating an array with unique integers. I want to create an array, and populate it with random numbers, they should be unique and sorted (I can sort at the output). I'm stuck at the unique part: generate a random number; check if the number exists in the array, if it exists generate a new one, check again until a unique number is found. once unique add too next place in array. I think the perldocs are confusing me. Thanks. Scott.
RE: Output to a file.
As far as I can see, the prints for output are going to the console, not a file. The statement you're referring to: __END__ flat2rdb.pl sitelist.str.fo has very little to do with the perl script. The __END__ tells the perl interpreter to not compile/run anything after the __END__ line. So the "flat2rdb.pl sitelist.str.fo" has no affect on how the program runs. It may be a veiled attempt at a comment? >From my brief review of the code, I see that the commented out portion near the top would have used the command line parameter to open the input file rather than how it is currently running -- using STDIN to capture a user entered filename. (I'm guessing that the part that choked was that `date '+%Y%m%d%H%M%S'` shells out to the operating system to call a date program. This probably didn't work under windows NT since there isn't a date program under a standard system.) I'm assuming that you want the prints that are going to a console to go to a flat file? If so you could just use a redirect STDOUT to a file under windows NT flat2rdb.pl > myresultfile.dat ?? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Thursday, May 31, 2001 5:42 PM To: [EMAIL PROTECTED] Subject: Output to a file. I've never written a line of perl before ... and I've only been lurking on the list for three hours or so. But I've been presented some code which was written for Unix and I'm trying to run on NT using ActiveState Perl. It converts a flat file from the USGS to a format we can get into our SQL database. It's running right now -- and I'm hoping that it will generate an output file -- however I see no indication that an output file is being generated as the program loops (it's been running for three hours or so -- see the connection?) the very end of the program are these lines: __END__ flat2rdb.pl sitelist.str.fo flat2rdb.pl is the name of the perl code. When this is done running will it generate a file called sitelist.str.fo ? Entire code at end of message. TYIA Rob Clayton WRE-Data/Modeling City of Austin ps. I must apologize for the rtf email. wish that I could deactivate it; but there are restrictions on that sort of thing here. #! /usr/bin/perl5 # Program for Chris Herrington # Convert flatout files to RDB files # with the format: # STAID DATES TIMES PARAMETER_CODE VALUE #--- # This command caused program to choke on NT: RC # Get the date #chomp($DTAG = (`date '+%Y%m%d%H%M%S'`)); # Get flatfile filename from command line #chomp($QWFLAT = $ARGV[0]); # Edited out Unix Commands by RC #--- # If flatfile filename not on command line prompt for it if($QWFLAT eq '') { print "Enter QW flatfile file name -> "; chomp($QWFLAT = ); } # Check to make sure file exists if(! -r $QWFLAT) { print "The file \"$QWFLAT\" not found\?\n"; exit; } open(FLAT, "< $QWFLAT") or die "Can\'t open $QWFLAT file.\n"; while() { #print "$parmcount\n"; $line = $_; $parmcount=''; $COL=40; $STAID = substr($_, 0,20); $STAID=~(s/^\s*(.*?)\s*$/$1/); $DATE = substr($_, 20,10); $DATE=~(s/^\s*(.*?)\s*$/$1/); $TIME = substr($_,30,10); $TIME=~(s/^\s*(.*?)\s*$/$1/); $VALUE = substr($_,40,10); $VALUE=~(s/^\s*(.*?)\s*$/$1/); $COL=($COL+10); #$crap=; print "# $STAID Station Number\n" if($OLDSTNUM != $STAID); print "DATE\tTIME\tSTORET\tRESULT\n8D\t4s\t5s\t10n\n" if($OLDSTNUM != $STAID); open(PARMS, "<${QWFLAT}.parnames") or die "Can\'t open ${QWFLAT}.parnames file.\n"; while() { next if(/^STAID|^DATES|^TIMES/); ($PARM, $junk)=split(/\s+/); print "$DATE\t$TIME\t$PARM\t$VALUE\n" if(($VALUE != -99)and($VALUE ne '')); while($VALUE ne '') { while() { ($PARM, $junk)=split(/\s+/); last; } $VALUE = substr($line,$COL,10); $VALUE=~(s/^\s*(.*?)\s*$/$1/); print "$DATE\t$TIME\t$PARM\t$VALUE\n" if(($VALUE != -99)and($VALUE ne '')); $COL=($COL+10); } } $OLDSTNUM = $STAID; } __END__ flat2rdb.pl sitelist.str.fo
RE: Perl, Nice, and CPU Usage
Perhaps the perl benchmarking would help out with this unit testing. perldoc Benchmark -Original Message- From: John Peterson [mailto:[EMAIL PROTECTED]] Sent: Monday, May 14, 2001 10:11 AM To: '[EMAIL PROTECTED]'; [EMAIL PROTECTED] Subject: RE: Perl, Nice, and CPU Usage Thanks for your help! I'll do a lot of testing. > -Original Message- > From: Brett McCoy [SMTP:[EMAIL PROTECTED]] > Sent: Monday, May 14, 2001 10:13 AM > To: 'John Peterson' > Subject: RE: Perl, Nice, and CPU Usage > > >-Original Message- > >From: John Peterson [mailto:[EMAIL PROTECTED]] > >Sent: Monday, May 14, 2001 11:59 AM > >To: '[EMAIL PROTECTED]' > >Subject: RE: Perl, Nice, and CPU Usage > > > > > >Because this is on a test box there is nothing else running at > >the time. The > >intention is to have it be user requested through a web > >browser. But right > >now I'm just running it from the command line. Only one person > >would run it > >at a time and only about once a week or so. I just want to > >make sure that > >when it does go on a production box that it will let other > >processes go in > >front of it and won't crash the server or anything. > > Probably wouldn't crash the server. The only way to know, of course, is > to > do some unit testing in a simulated production environment -- run some > load > testing software against your test server and try to run your report. It > might take longer to run, but it should yield to other processes (like the > web server) in an appropriate manner. This kind of thing probably won't > even make a Sun box blink. Your idle time goes down so much because only > one thing is utilizing the CPU and it will use as much as the system wants > to give it (and connecting to two databases and crunching a bunch of data > can be pretty processor intensive). > > -- Brett
RE: Loading extra modules.
If you got it in a tar'ed package, it will come with a Makefile.PL script. The general procedure is: perl Makefile.PL make test make install {su'ed to root} If you didn't get the tar'ed package, and just have .pm, then I would recommend getting the tar'ed package instead. This would vary somewhat if you're on a Windows NT box. -Original Message- From: Tirthankar C.P [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 09, 2001 11:44 AM To: [EMAIL PROTECTED] Subject: Loading extra modules. Folks, how do I load extra modules? I got Date::Manip today, and I know I should be putting it in the search-path of perl (@INC ?), but how do I do it? Can I get a small code snippet? I do not have su privileges on the machine I work, and would like the search-path to have my modules dir, $HOME/perlmodules in it. TIA, -tir
RE: IDE for perl?
I think it's pretty clear, given that the poster is asking for feedback that they are looking for options. Disclaimer: I don't work for free. -Original Message- From: Peter Scott [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 09, 2001 10:53 AM To: [EMAIL PROTECTED] Subject: RE: IDE for perl? At 10:41 AM 5/9/01 -0600, blowther wrote: >I recommend wscite when I teach perl classes. The code highlighting is >pretty good. No inline debugger tho. We use ptkdb for graphical debugging. >--all of these are free.-- I think it's pretty clear, given the requirement for project directories, and group environment, that the poster should take a look at Activestate Visual Perl (http://aspn.activestate.com/ASPN/Downloads/VisualPerl/), since it allows Visual Studio to provide those features. Since it sounds as though money's available, they may want to check out their ASPN Perl package also (http://www.activestate.com/Products/Productivity/ASPN_Perl/). Disclaimer: I don't work for ActiveState. >-Original Message- >From: Rod Suter [mailto:[EMAIL PROTECTED]] >Sent: Wednesday, May 09, 2001 8:19 AM >To: [EMAIL PROTECTED] >Subject: IDE for perl? > > >I'm using perl through emacs, but I want to bring along some people on >NT4.0. They're accustomed to Visual Studio, and want IDE features, such as >project directories, global search and replace, debugger linking, source >code error hilighting, etc. Can anyone suggest a good group environment for >developing perl? My first urge is to set up Ultra-Edit with some appropriate >customization. -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com
RE: IDE for perl?
I recommend wscite when I teach perl classes. The code highlighting is pretty good. No inline debugger tho. We use ptkdb for graphical debugging. --all of these are free.-- -Original Message- From: Rod Suter [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 09, 2001 8:19 AM To: [EMAIL PROTECTED] Subject: IDE for perl? I'm using perl through emacs, but I want to bring along some people on NT4.0. They're accustomed to Visual Studio, and want IDE features, such as project directories, global search and replace, debugger linking, source code error hilighting, etc. Can anyone suggest a good group environment for developing perl? My first urge is to set up Ultra-Edit with some appropriate customization.
RE: db connect
In other words, you need configure Windoz to add the data source. Start | Settings | Control Panel | Data Sources (ODBC). You'll have to check your manuals, what entries go in this section... (Beyond the scope of Perl Beginners list). Bruce W. Lowther [EMAIL PROTECTED] Micron Technology, Inc. Boise, Idaho -Original Message- From: M.W. Koskamp [mailto:[EMAIL PROTECTED]] Sent: Monday, May 07, 2001 10:50 AM To: justin todd; Beginners (E-mail) Subject: Re: db connect - Original Message - From: justin todd <[EMAIL PROTECTED]> To: Beginners (E-mail) <[EMAIL PROTECTED]> Sent: Monday, May 07, 2001 6:30 PM Subject: db connect > Hi Folks > > I am running a IIS server and MSSQL7, both on the same machine. > > The database server is called JUSTIN. The database is called test and > the table is called test. > > This is my connect string. > $dbh = DBI->connect('DBI:ODBC:test',''); > > This is my error. Data source name not found and no default driver specified I think this line explains it. There is no known ODBC datasource by the name of 'test'
RE: :ODBC (say what?)
Here's one link to the perl DBI POD. It's the best POD documentation I've seen. Kudos to the POD writers. http://theoryx5.uwinnipeg.ca/CPAN/data/DBI/DBI.html -Original Message- From: Smith, Jim R [mailto:[EMAIL PROTECTED]] Sent: Thursday, May 03, 2001 12:32 PM To: [EMAIL PROTECTED] Subject: DBD::ODBC (say what?) I have a little experience with perl. 99.999% of it is on Unix. My boss came up with a project involving an NT server, Microsoft SQL Server, and MS-Access datbases. I'm fairly confident that I can figure out perl and NT. I have read postings that mention DBI,DBD::ODBC etc. I need some guidance as to finding newbie documentation for the database interface, and what modules I would need to install on top of perl v5.6 to make this work. Thanks for your help. jim
RE: Error
$fh = newopen("$datafile"); It looks like this line needs a 'my' -Original Message- From: Phillip Bruce [mailto:[EMAIL PROTECTED]] Sent: Friday, April 27, 2001 7:47 AM To: perl Subject: Error Hi, I'm getting the following errror: Global symbol "$fh" requires explicit package name at livonia.pl line 22. Execution of livonia.pl aborted due to compilation errors. Also can some one suggest a better way to handle the IO I'm wondering about the globtype and that is why I used the \*FH in my subroutine. Below is the code: #!/usr/bin/perl # Modules use strict; use Text::CSV_XS; use FileHandle; # Constants my $datafile = 'everyone.csv'; #my $summary = 'summary.txt'; #open $handle, "$datafile" or die "$datafile: $!"; sub newopen { my $path = shift; local *FH; open (FH, $path) || return undef; return \*FH; } $fh = newopen("$datafile"); my $csv = Text::CSV_XS->new; my $column = ''; if ($csv->parse($fh)) { my @field = $csv->fields; my $count = 0; for $column (@field) { print ++$count, " => ", $column, "\n"; } print "\n"; } else { my $err = $csv->error_input; print "parse() failed on argument: ", $err, "\n"; } my @sample_input_fields = ('You said, "Hello!"', 5.67, 'Surely', '', '3.14159'); if ($csv->combine(@sample_input_fields)) { my $string = $csv->string; print $string, "\n"; } else { my $err = $csv->error_input; print "combine() failed on argument: ", $err, "\n"; } #close(INFILE); #close(OUTFILE); -- *** Phillip B. Bruce *** *** http://pbbruce.home.mindspring.com *** *** [EMAIL PROTECTED] *** *** *** *** "Have you ever noticed? Anybody going slower than*** *** you is an idiot, and anyone going faster than you*** *** is a maniac." - George Carlin***
Perl Advocacy email list
What's the email address for the perl advocacy email distro? Bruce W. Lowther Micron Technology, Inc. Boise, Idaho
RE: how to execute a windows 2000 command with perl
Just to clarify: >From machine A you want to remotly execute a script on machine B? If I understand your question correctly, you well have a hard time doing that using Perl alone. I would recommend looking and CYGNUS http://www.cygnus.com for information about rsh on win32 platform. If I'm not understanding the question, then please clarify. Bruce W. Lowther Micron Technology, Inc. Boise, Idaho -Original Message- From: Peter Lemus [mailto:[EMAIL PROTECTED]] Sent: Wednesday, April 25, 2001 5:12 PM To: [EMAIL PROTECTED] Subject: how to execute a windows 2000 command with perl Hi all, I need to execute a windows 2000 command through a perl script on a different machine. can someone give me an example on how to accomplish this. I mapped a drive for example: system "net use x: myserver\myshare" now I can go to X: How can I execute the command on the remote machine: some thing like: system "xcacls $line /g $line:r /E \n"; # set the permissions I need to run this on the remote machine though. Regards, = Peter Lemus Computer Networks Engineer [EMAIL PROTECTED] My Dad always tought me; when you do good; expect to receive good; when you do bad; expect the bad...sooner or later. __ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/
RE: What is a "case shell"?
Might be a phonetic thing... perhaps they are referring to the ksh (K Shell)? -Original Message- From: Dennis Fox [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 24, 2001 5:38 PM To: [EMAIL PROTECTED] Subject: What is a "case shell"? Here is a line from a job description that has me baffled: "·Perl scripting (must know how to Perl well enough to script inside a case shell)" Leaving aside the use of "Perl" as a verb for another discusssion, is this just a typo (common in job advertisements), or is there a "case shell" that I have not heard of yet? The company with this ad uses Solaris (does not say which version). If it is just about using "case" in a shell script, I already know how to do that. Thanks for any light y'all can shed. -- - Dennis "Bass Dude" Fox | [EMAIL PROTECTED] OR [EMAIL PROTECTED] Bureaucracy is the art of making the possible impossible -Javier Pascual Salcedo -
RE: Global symbol requires explicit pack name
I pretty printed for my own sanity: use strict ; my @vob_list = `cleartool lsvob | grep "*"`; my $entry ; foreach $entry (@vob_list) { chomp $entry; my @fields = split /\s+/, $entry; my $tag_list ; my $vbs_list ; @tag_list = @fields[1] ; @vbs_list = @fields[2] ; foreach my $lock (@tag_list) { print "$lock \n" ; foreach my $tardir (@vbs_list) { print "$tardir \n" ; } } } You need to declare the variables referenced in the foreach statements. I put my in front of both. The other two errors related to the lines: my $tag_list ; my $vbs_list ; @tag_list = @fields[1] ; @vbs_list = @fields[2] ; This is a common mistake for new folks... you're declaring two scalars, but you're actually assigning into two different arrays. In perl, $tag_list is a completely different variable than @tag_list. One is a scalar (single value) and the other is an array. To access an item within the array, you reference it in a scalar context: $tag_list = $fields[1]; Hope this helps Bruce W. Lowther Micron Technology, Inc. Boise, Idaho -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 24, 2001 3:41 PM To: [EMAIL PROTECTED] Subject: Global symbol requires explicit pack name All, When I use strict function, I get an error in the following code. #!/usr/local/bin/perl use strict ; my @vob_list = `cleartool lsvob | grep "*"`; my $entry ; foreach $entry (@vob_list) { chomp $entry; my @fields = split /\s+/, $entry; my $tag_list ; my $vbs_list ; @tag_list = @fields[1] ; @vbs_list = @fields[2] ; foreach $lock (@tag_list) { print "$lock \n" ; foreach $tardir (@vbs_list) { print "$tardir \n" ; } } } Global symbol "tag_list" requires explicit package name at ./back.pl line 10. Global symbol "vbs_list" requires explicit package name at ./back.pl line 11. Global symbol "lock" requires explicit package name at ./back.pl line 12. Variable "@tag_list" is not imported at ./back.pl line 12. Global symbol "tag_list" requires explicit package name at ./back.pl line 12. Variable "$lock" is not imported at ./back.pl line 13. Global symbol "lock" requires explicit package name at ./back.pl line 13. Global symbol "tardir" requires explicit package name at ./back.pl line 14. Variable "@vbs_list" is not imported at ./back.pl line 14. Global symbol "vbs_list" requires explicit package name at ./back.pl line 14. Variable "$tardir" is not imported at ./back.pl line 15. Global symbol "tardir" requires explicit package name at ./back.pl line 15. Execution of ./back.pl aborted due to compilation errors. I get this error only when I use the strict function, so I figured that this is not an efficient code. Can somebody help me on this ? Thx in advance Kailash
RE: Rookie Question
The Term::ReadLine package is one option.. You might also try the native perl function getc. Bruce W. Lowther [EMAIL PROTECTED] Micron Technology, Inc. Boise, Idaho -Original Message- From: Goodman Kristi - kgoodm [mailto:[EMAIL PROTECTED]] Sent: Monday, April 23, 2001 1:05 PM To: '[EMAIL PROTECTED]' Subject: Rookie Question I have this line of code in my program: print "Did everything look ok? (Y/N)"; chomp ($check = ); $check = "\U$check"; if ("\U$check" ne "Y") {die "Well. . . go back and try again until you get it right!!!\n"}; How would I fix it where the user did not have to ENTER after they typed a Y or N. Thanks for your help!
RE: CGI problem, no luck so far
Remember you can always check the syntax of a perl script using the -c option! perl -c myscript.pl One thing that frequently gets over looked is that you can run a script through perl to check the syntax of a script. This quick check will point out all sorts of details that are hard to see when running the script through CGI or when using perl in an embeded situation. Bruce W. Lowther Micron Technology, Inc. Boise, Idaho -Original Message- From: Dan Brown [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 19, 2001 4:23 PM To: Pam Derks Cc: [EMAIL PROTECTED] Subject: Re: CGI problem, no luck so far Is this really the exact script? The reason I ask is that you shouldn't even get as far as to get the error you present ("Premature end of script headers"). There is an extra curley brace at the end that should have caused the Perl compiler to croak with something like Unmatched right curly bracket at pam_derks.pl line 59, at end of line syntax error at pam_derks.pl line 59, near "}" Execution of pam_derks.pl aborted due to compilation errors. Try running it from command line and see what you get. There are a couple of pointers I can give you. 1. I strongly suggest using the pragma use strict; It will force you to write less error-prone code of which you will be glad of later. 2. Please read the documentation on the CGI module. Based on the code provided, you're reinventing the wheel. If the code has print $cgi->header; # print this before printing *anything* else! there's no need to do this print "Content-type: text/html\n\n"; since the 'header' routine does it for you. By the way, for a CGI program printing the "Content-type" alone it will do fine also. If you're not going to use the CGI module for anything other than printing the header, there's no need to include it. But, I *strongly* recommend using it since it'll save you a great deal of effort. For example, using the CGI module the FormInput routine can be completely removed. The CGI module gives you access to all input, regardless of how it came to the script (request_method), via the param routine. Using CGI to its full, the size of the script is cut in half. 1 #!/usr/bin/perl -w 2 3 use strict; 4 use CGI qw( :standard ); 5 6 #--- Start User Configuration 7 my $main = 'xxx.berkeley.edu'; 8 #---End User Configuration --- 9 10 # Declare/Initialize the variable 11 # 12 my $goto = ''; 13 14 # Assign the variable a new value if that new value was passed in 15 # If it was not passed in, $goto will have the value of '' 16 # 17 $goto = param( 'goto' ) if( defined param( 'goto' ) ); 18 19 if( $goto eq '' ) 20 { 21 # CGI::redirect will do everything you need to redirect 22 # 23 print redirect( "http://xxx.berkeley.edu/cat/$main" ); 24 } 25 else 26 { 27 print redirect( "http://xxx.berkeley.edu/cat/$goto" ); 28 } 29 30 exit; I hope this helps. Dan Pam Derks wrote: > > Thanks all for your suggestions regarding earlier post (below): > > Am testing out a new web server running SunOS5.8 " and I can't get any of my cgi scripts to run. I get this error message: > "Premature end of script headers" > the cgi scripts worked perfectly on the old server which was running Digital UNIX. > > -- > > Here's a more info, as I've tried several things and still am having no luck. > > New web server: > perl version is 5.005_03 for sun4-solaris > Running Apache > (not exactly sure which version but I THINK this is a newer version than other machine)) > > Old web server: > perl version is 5.004_04 for alpha-dec-osf > Running Apache > > file permissions are set to 755 on the cgi script > path to perl is correct > error message has remained the same: > "Premature end of script headers" > > The script is very simple and I'm sure can be written better, but it worked on the other web server. it's a simple script that activates the "Go" button from a pull down menu on a web page. > > Here's the CGI script that won't run, on new web server. > > #!usr/bin/local/perl -w > 2 > 3 > 4 > 5 #--- Start User Configuration > 6 $main = 'xxx.berkeley.edu'; > 7 #---End User Configuration --- > 8 > 9 > 10 use CGI; > 11 > 12$cgi = new CGI; > 13 > 14print $cgi->header; # print this before printing *anything* else! > 15 print "Content-type: text/html\n\n"; > 16 > 17 &FormInput(*input); > 18 > 19 if($input{'goto'} eq "") > 20 { > 21 print ("Location: http://x
RE: cat a file
Something like this will work. perl -pe "" foo.txt bar.txt > c:\temp\baz.txt It's disappointing that perl -p foo.txt bar.txt > c:\temp\baz.txt doesn't work. It thinks foo.txt is the perl script to execute. -Original Message- From: Peter Scott [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 19, 2001 2:34 PM To: Drain, Frank; Beginners (E-mail) Subject: Re: cat a file At 04:27 PM 4/19/01 -0400, Drain, Frank wrote: >Hello, > >I am very new to perl. I have two pst (personal folder files) that I want >to combine into one. > >I know how to use cat in Linux. How do do this >same operation in perl under windows? # cat. Usage, e.g. perl cat .pl file1 file2 >file3 while (<>) { print } -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com
RE: OK, Where is CVS?
CVS Can be found at http://www.cvshome.org -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 19, 2001 9:52 AM To: [EMAIL PROTECTED] Subject: OK, Where is CVS? I can't seem to find the CVS Client. I have looked in samba.org and have perused the "CVS Access to pserver" document (which states that I need to install a recent copy of CVS) with no luck. I must be missing the obvious. If the client is available in binary format I am interested in HPUX; otherwise, if someone can point me to the source I would be eternally grateful. Thanks, George Gage [EMAIL PROTECTED]
RE: Removing Leading Zeros
Striping the zeros may not be necessary depending on what you are using the $index and $value for. If you are actually going to use $index and $value as numbers, the leading zeros won't matter. For example: my $index = '0003'; print "Original: "; print $index; print "\n"; print "In a string context: "; print $index . '15'; print "\n"; print "In a numerical context: "; print $index + 15; print "\n"; will print the following: Original: 0003 In a string context: 000315 In a numerical context: 18 That's the good thing about loosly typed languages... (I guess it's also the bad thing.) Bruce W. Lowther -Original Message- From: David M. Lloyd [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 19, 2001 8:48 AM To: Mark Martin Cc: [EMAIL PROTECTED] Subject: Re: Removing Leading Zeros On Thu, 19 Apr 2001, Mark Martin wrote: > Hi all, > I have sucked two substrings into two variables : > > $index = substr $_, 35, 11; > $value = substr $_, 64, 6; > > These variables may or may not have leading zero/s : > > 09/99/000999and so on. > > If they do I need to strip away the leading zeros. > > Any ideas? # Begin perl code $index =~ s/^0+//; $value =~ s/^0+//; # End perl code It reads like this: "Apply a substitution to $index, in which any group of 1 or more zeros (0) at the beginning of the string, are replaced with nothing". The s/// operator is very powerful. I'd recommend reading up on it... you can do all kinds of cool things with it. - D <[EMAIL PROTECTED]>
RE: referencing and subroutines.
You could return the data by reference... The documentation is at perldoc perlref But in summary it would be sub parse { my $hashRef = {}; $hashRef->{ONE} = 45; return $hashRef } my $result = parse(); print $result->{ONE}; -Original Message- From: Martijn van Exel [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 17, 2001 2:38 PM To: [EMAIL PROTECTED] Subject: referencing and subroutines. Hi all, I'm new to this list and quite new to Perl. I'm on digest, so I'd appreciate a cc. I have written a subroutine to parse a text file containing a flat file database. The data ends up in a hash of hashes, say %datafile. This hash is created on the spot, looping through the data in a foreach loop. The data coud then be retrieved using $datafile{$record}{$fieldname}. This seems to work, but the hash won't travel with me out of the subroutine. I'm not using strict, so I'm being messy with my declarations, probably. Do I need to end the subroutine using return? Any help greatly appreciated. -- martijn van exel -- [EMAIL PROTECTED] -- http://huizen.dds.nl/~mvexel
RE: problem with variables
So your saying that Perl can handle calculating cosine while iterating through Pi? for my $inc (-3.14159 .. 3.14159) { push @result, cos($inc); } Come on... C style for loops have their place. -Original Message- From: Brent Michalski [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 17, 2001 1:55 PM To: Pacifico Cc: [EMAIL PROTECTED] Subject: Re: problem with variables To add to the answer(s) already given... for ($i=1 ; $i<4 ;$i++){ print $sup($i); } is actually quite cumbersome, and very 'C'-ish... Let's make it more Perl-ish... for my $i (1..4){ print $i; } There is not need to have to deal with incrementing and checking conditions in loops - Perl does this very nicely for us already... brent "Pacifico" <[EMAIL PROTECTED]> Sent by: To: <[EMAIL PROTECTED]> beginners-return-51-Brent_Michalski=mastercard.co cc: [EMAIL PROTECTED] Subject: problem with variables 04/17/01 09:59 AM i have this program: $sup1='a'; $sup2='b'; $sup3='c'; for ($i=1 ; $i<4 ;$i++){ print $sup($i); } but give error, why???
RE: regular expression match?
Geeze, these answers come in much faster than I can type... I did want to check your use of an array... You're using hash access: $array{0} = 'clk_n'; Shouldn't this be $array[0] = 'clk_n'; -Original Message- From: Prentice, Phillip R [mailto:[EMAIL PROTECTED]] Sent: Monday, April 16, 2001 12:37 PM To: '[EMAIL PROTECTED]' Subject: regular expression match? Hello, I am fairly new to perl and am having problems matching a specific character. I want to be able to match the "_" character at the end of a string. For example, asume I have an array of strings with the following data: $array{0} = "clk_n" $array{1} = "test_in_6_" $array{2} = "clk_out" I want to create a regular expression which will match $array{1} and not the others in the array. This is what I have so far. foreach (@array) { if(m/$\w+\_/) { print "Matched, $_\n"; } } This isn't giving the results I want, instead it will match the "_" character in the middle of the string as well as the end of the string. Any ideas or suggestions on how this can be done? Thanks in advance, -Phillip Prentice